diff --git a/inGameAppState.cpp b/inGameAppState.cpp index a755260..e653e9d 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -220,16 +220,16 @@ namespace battleship{ guiState = ((GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE)); activeState = new ActiveGameState(guiState, players, playerId); stateManager->attachAppState(activeState); + AssetManager *assetManager = AssetManager::getSingleton(); + assetManager->load(DEFAULT_TEXTURE); UnitDataManager *unitDataManager = UnitDataManager::getSingleton(); int numUnits = unitDataManager->getNumUnits(); string *basePaths = unitDataManager->getBasePath(); string *meshPaths = unitDataManager->getMeshPath(); - /* for(int i = 0; i < numUnits; ++i) - AssetManager::getSingleton()->load(basePaths[i] + meshPaths[i]); - */ + assetManager->load(basePaths[i] + meshPaths[i]); } void InGameAppState::onDettached() { diff --git a/map.cpp b/map.cpp index f6b5b6b..2d9094b 100755 --- a/map.cpp +++ b/map.cpp @@ -74,7 +74,6 @@ namespace battleship{ int numWaterBodies = 1; string table = "waterBodies"; Root *root = Root::getSingleton(); - waterBodies = new WaterBody[numWaterBodies]; for(int i = 0; i < numWaterBodies; i++){ float sizeX = luaManager->getFloatFromTable(table, vector{Index("sizeX", true)}); @@ -102,9 +101,11 @@ namespace battleship{ waterNode->setOrientation(Quaternion(-1.57, Vector3::VEC_I)); nodeParent->attachChild(waterNode); - waterBodies[i].pos = Vector3(posX, posY, posZ); - waterBodies[i].size = Vector2(sizeX, sizeY); - waterBodies[i].rect = rect; + WaterBody waterBody; + waterBody.pos = Vector3(posX, posY, posZ); + waterBody.size = Vector2(sizeX, sizeY); + waterBody.rect = rect; + waterBodies.push_back(waterBody); } } @@ -128,9 +129,29 @@ namespace battleship{ void Map::unload() {} - Vector3 Map::getCellPos(int id){ + Vector3 Map::getCellPos(int id, Vector3 cellSize){ + int numCellsX = size.x / cellSize.x; + int numCellsY = size.y / cellSize.y; + int numCellsZ = size.z / cellSize.z; + + Vector3 initPos = Vector3(size.x, 0, size.z) * -0.5; + int x = id % numCellsX; + int y = (id / numCellsX) % numCellsZ; + int z = id / (numCellsX * numCellsZ); + + return Vector3(x * cellSize.x, y * cellSize.y, z * cellSize.z); } - int Map::getCellId(Vector3 pos){ + int Map::getCellId(Vector3 pos, Vector3 cellSize){ + int numCellsX = size.x / cellSize.x; + int numCellsY = size.y / cellSize.y; + int numCellsZ = size.z / cellSize.z; + + Vector3 initPos = Vector3(size.x, 0, size.z) * -0.5; + int x = fabs(pos.x - initPos.x) / cellSize.x; + int y = fabs(pos.y - initPos.y) / cellSize.y; + int z = fabs(pos.z - initPos.z) / cellSize.z; + + return (numCellsX * numCellsZ * y + (numCellsX * z + x)); } } diff --git a/map.h b/map.h index 4f51913..79bbda3 100755 --- a/map.h +++ b/map.h @@ -3,6 +3,7 @@ #define MAP_H #include +#include #include @@ -10,6 +11,11 @@ namespace gameBase{ class LuaManager; } +namespace vb01{ + class Model; + class Node; +} + namespace battleship{ struct WaterBody{ vb01::Vector3 pos; @@ -24,9 +30,10 @@ namespace battleship{ void update(){} void load(std::string); void unload(); - vb01::Vector3 getCellPos(int); - int getCellId(vb01::Vector3); + vb01::Vector3 getCellPos(int, vb01::Vector3); + int getCellId(vb01::Vector3, vb01::Vector3); inline WaterBody getWaterBody(int i){return waterBodies[i];} + inline int getNumWaterBodies(){return waterBodies.size();} inline vb01::Model* getTerrainModel(){return terrainModel;} inline vb01::Node* getNodeParent(){return nodeParent;} inline vb01::Vector3 getSize(){return size;} @@ -34,8 +41,9 @@ namespace battleship{ vb01::Node *nodeParent = nullptr; vb01::Model *terrainModel = nullptr; std::string mapName; - WaterBody *waterBodies = nullptr; - vb01::Vector3 size = vb01::Vector3(20, 20, 6); + std::vector waterBodies; + //TODO replace hardcoded values + vb01::Vector3 size = vb01::Vector3(20, 6, 20); Map(){} void loadSkybox(gameBase::LuaManager*); diff --git a/pathfinder.cpp b/pathfinder.cpp index fbb02c4..176843f 100644 --- a/pathfinder.cpp +++ b/pathfinder.cpp @@ -1,6 +1,7 @@ #include #include "pathfinder.h" +#include "map.h" namespace battleship{ using namespace std; @@ -61,7 +62,4 @@ namespace battleship{ return paths[dest]; } - - void Pathfinder::generateWeights(u32 **weights, int &size, Vector3* verts[], Vector3 mapSize){ - } } diff --git a/pathfinder.h b/pathfinder.h index ace6686..84de681 100644 --- a/pathfinder.h +++ b/pathfinder.h @@ -10,7 +10,6 @@ namespace battleship{ public: static Pathfinder* getSingleton(); std::vector findPath(vb01::u32**, int, int, int); - void generateWeights(vb01::u32**, int&, vb01::Vector3*[], vb01::Vector3); private: Pathfinder(); }; diff --git a/pathfinderTest.cpp b/pathfinderTest.cpp index 37dcd7d..24a7d4e 100644 --- a/pathfinderTest.cpp +++ b/pathfinderTest.cpp @@ -41,9 +41,6 @@ namespace battleship{ CPPUNIT_ASSERT(sumPathWeights == 9); } - void PathfinderTest::testGenerateWeights(){ - } - void PathfinderTest::setUp(){ pathfinder = Pathfinder::getSingleton(); } diff --git a/pathfinderTest.h b/pathfinderTest.h index b8aa2a2..2cc4f09 100644 --- a/pathfinderTest.h +++ b/pathfinderTest.h @@ -15,7 +15,6 @@ namespace battleship{ public: PathfinderTest(){} void testFindPath(); - void testGenerateWeights(); void setUp(); void tearDown(); private: diff --git a/unit.cpp b/unit.cpp index 97b1474..8b405c0 100755 --- a/unit.cpp +++ b/unit.cpp @@ -276,22 +276,29 @@ namespace battleship{ return projectiles; } + void Unit::generateWeights(u32 **weights, int size){ + } + void Unit::addOrder(Order order){ - u32 **weights = new u32*; float eps = getCircleRadius(); Map *map = Map::getSingleton(); Vector3 mapSize = map->getSize(); - int numCells = int(mapSize.x / eps) * int(mapSize.y / eps); + Vector3 cellSize = Vector3(int(mapSize.x / eps), 0, int(mapSize.z / eps)); + int numCells = cellSize.x * (cellSize.y > 0 ? cellSize.y : 1) * cellSize.z; + u32 **weights = new u32*[numCells]; + + for(int i = 0; i < numCells; i++) + weights[i] = new u32[numCells]; Pathfinder *pathfinder = Pathfinder::getSingleton(); - Vector3 **verts = nullptr; - pathfinder->generateWeights(weights, numCells, verts, mapSize); - - vector path = pathfinder->findPath(weights, numCells, map->getCellId(pos), map->getCellId(order.targets[0].pos)); + vector path = pathfinder->findPath(weights, + numCells, + map->getCellId(pos, cellSize), + map->getCellId(order.targets[0].pos, cellSize)); pathPoints.clear(); for(int p : path) - pathPoints.push_back(map->getCellPos(p)); + pathPoints.push_back(map->getCellPos(p, cellSize)); orders.push_back(order); } diff --git a/unit.h b/unit.h index 72699c1..f4aaf45 100755 --- a/unit.h +++ b/unit.h @@ -85,6 +85,7 @@ namespace battleship{ inline vb01::Vector3 getLeftVec() {return leftVec;} inline vb01::Vector3 getUpVec() {return upVec;} private: + void generateWeights(vb01::u32**, int); void updateScreenCoordinates(); void displayUnitStats(); inline int getNextPatrolPointId(int numPoints) {return patrolPointId == numPoints - 1 ? 0 : patrolPointId + 1;} diff --git a/unitDataManager.cpp b/unitDataManager.cpp index 07425e5..aa55c78 100644 --- a/unitDataManager.cpp +++ b/unitDataManager.cpp @@ -30,6 +30,7 @@ namespace battleship{ health = new int[numUnits]; speed = new float[numUnits]; destinationOffset = new float[numUnits]; + unitType = new UnitType[numUnits]; anglePrecision = new float[numUnits]; cost = new int[numUnits]; maxTurnAngle = new float[numUnits]; @@ -45,6 +46,7 @@ namespace battleship{ for(int i = 0; i < numUnits; i++){ health[i] = luaManager->getIntFromTable("health", vector{Index(to_string(i + 1), false)}); speed[i] = luaManager->getFloatFromTable("speed", vector{Index(to_string(i + 1), false)}); + unitType[i] = (UnitType)luaManager->getIntFromTable("unitType", vector{Index(to_string(i + 1), false)}); destinationOffset[i] = luaManager->getFloatFromTable("destinationOffset", vector{Index(to_string(i + 1), false)}); anglePrecision[i] = luaManager->getFloatFromTable("anglePrecision", vector{Index(to_string(i + 1), false)}); cost[i] = luaManager->getIntFromTable("cost", vector{Index(to_string(i + 1), false)});