From e154da636e6ac948658b08231a0ca01e9ec15144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bergstr=C3=B6m?= <davbe125@student.liu.se> Date: Wed, 18 Jul 2018 15:56:42 +0200 Subject: [PATCH] Make it possible to compile on Linux --- CMakeLists.txt | 11 ++++++++++- python-api-src/library.cpp | 4 ++-- python-api-src/library.h | 2 +- src/IDABot.cpp | 4 ++-- src/IDABot.h | 6 +++--- src/MyAgent.cpp | 6 +++--- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 210c3205e..f92edcefc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,15 @@ if (MSVC) set_target_properties(sc2renderer PROPERTIES COMPILE_FLAGS "/W4") set_target_properties(sc2utils PROPERTIES COMPILE_FLAGS "/W3") set_target_properties(sc2protocol PROPERTIES COMPILE_FLAGS "/W0") + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT CommandCenter) endif (MSVC) -set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT CommandCenter) +if(UNIX AND NOT APPLE) + set_target_properties(libprotobuf PROPERTIES POSITION_INDEPENDENT_CODE ON) + set_target_properties(sc2api PROPERTIES POSITION_INDEPENDENT_CODE ON) + set_target_properties(sc2lib PROPERTIES POSITION_INDEPENDENT_CODE ON) + set_target_properties(sc2renderer PROPERTIES POSITION_INDEPENDENT_CODE ON) + set_target_properties(sc2utils PROPERTIES POSITION_INDEPENDENT_CODE ON) + set_target_properties(sc2protocol PROPERTIES POSITION_INDEPENDENT_CODE ON) + set_target_properties(civetweb-c-library PROPERTIES POSITION_INDEPENDENT_CODE ON) +endif() diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 16fa386f6..2f3a8e37d 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -60,9 +60,9 @@ PYBIND11_MODULE(library, m) .def("get_my_units", &IDABot::GetMyUnits) .def("get_player_race", &IDABot::GetPlayerRace) .def_property_readonly("base_location_manager", &IDABot::Bases) - .def_property_readonly("tech_tree", &IDABot::TechTree) + .def_property_readonly("tech_tree", &IDABot::GetTechTree) .def_property_readonly("map_tools", &IDABot::Map) - .def_property_readonly("building_placer", &IDABot::BuildingPlacer) + .def_property_readonly("building_placer", &IDABot::GetBuildingPlacer) .def_property_readonly("start_location", &IDABot::GetStartLocation) .def_property_readonly("minerals", &IDABot::GetMinerals) .def_property_readonly("current_supply", &IDABot::GetCurrentSupply) diff --git a/python-api-src/library.h b/python-api-src/library.h index d6f451fff..7d11d4d80 100644 --- a/python-api-src/library.h +++ b/python-api-src/library.h @@ -57,4 +57,4 @@ void define_point(pybind11::module &m); void define_base_location(pybind11::module & m); void define_tech_tree(pybind11::module & m); void define_map_tools(pybind11::module & m); -void define_building_placer(pybind11::module & m); \ No newline at end of file +void define_building_placer(pybind11::module & m); diff --git a/src/IDABot.cpp b/src/IDABot.cpp index afd09029f..f61dc8329 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -124,7 +124,7 @@ int IDABot::GetCurrentFrame() const return (int)Observation()->GetGameLoop(); } -const TechTree & IDABot::TechTree() const +const TechTree & IDABot::GetTechTree() const { return m_techTree; } @@ -194,7 +194,7 @@ void IDABot::OnError(const std::vector<sc2::ClientError> & client_errors, const // This is called when the sc2api (Google's API) has an error. } -BuildingPlacer & IDABot::BuildingPlacer() +BuildingPlacer & IDABot::GetBuildingPlacer() { return m_buildingPlacer; } diff --git a/src/IDABot.h b/src/IDABot.h index 94c7621dc..eca954f01 100644 --- a/src/IDABot.h +++ b/src/IDABot.h @@ -38,13 +38,13 @@ public: /* API for students */ - const TechTree & TechTree() const; + const TechTree & GetTechTree() const; const BaseLocationManager & Bases() const; const MapTools & Map() const; const UnitInfoManager & UnitInfo() const; CCRace GetPlayerRace(int player) const; CCPosition GetStartLocation() const; - BuildingPlacer & BuildingPlacer(); + BuildingPlacer & GetBuildingPlacer(); int GetCurrentFrame() const; int GetMinerals() const; @@ -62,4 +62,4 @@ public: const TypeData & Data(const CCUpgrade & type) const; const TypeData & Data(const MetaType & type) const; const TypeData & Data(const Unit & unit) const; -}; \ No newline at end of file +}; diff --git a/src/MyAgent.cpp b/src/MyAgent.cpp index 4fd66e698..5a6ac87e4 100644 --- a/src/MyAgent.cpp +++ b/src/MyAgent.cpp @@ -85,7 +85,7 @@ void MyAgent::manageBuilding(std::vector<UnitType> & build_plan) BuildStatus status{ type, position }; currently_building[worker] = status; // Reserve the location - BuildingPlacer().reserveTiles(position.x, position.y, type.tileWidth(), type.tileHeight()); + GetBuildingPlacer().reserveTiles(position.x, position.y, type.tileWidth(), type.tileHeight()); // Update economy book-keeping if (type.isRefinery() || type.isResourceDepot()) @@ -303,7 +303,7 @@ void MyAgent::manageWorkers(std::vector<UnitType> & build_plan) if (worker.isIdle()) { BuildStatus status = currently_building[worker]; - BuildingPlacer().freeTiles(status.position.x, status.position.y, status.type.tileWidth(), status.type.tileHeight()); + GetBuildingPlacer().freeTiles(status.position.x, status.position.y, status.type.tileWidth(), status.type.tileHeight()); currently_building.erase(worker); assignWork(worker, Assignment::Mineral); } @@ -415,7 +415,7 @@ CCTilePosition MyAgent::getBuildPosition(UnitType & building) else { CCPosition position = Bases().getPlayerStartingBaseLocation(Players::Self)->getPosition(); - tile_position = BuildingPlacer().getBuildLocationNear(Util::GetTilePosition(position), building, 1); + tile_position = GetBuildingPlacer().getBuildLocationNear(Util::GetTilePosition(position), building, 1); } return tile_position; } -- GitLab