From 882ca02b664ce23fd8d01895a58c820006ec31ea Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 28 Jul 2024 14:24:18 +0300 Subject: [PATCH] export partial fix attempts --- mapEditorAppState.cpp | 47 ++++++++++++++++++++++++------------------- mapEditorAppState.h | 4 ---- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index 670d3c6..09bb1e2 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -6,8 +6,8 @@ #include "gameObjectFactory.h" #include "gameObjectFrameController.h" #include "player.h" +#include "game.h" #include "map.h" -#include "mesh.h" #include "util.h" #include @@ -40,7 +40,6 @@ namespace battleship{ MapEditorAppState::MapEditor::MapEditor(string name, Vector2 size, bool newMap){ this->newMap = newMap; - this->mapSize = size; string basePath = GameManager::getSingleton()->getPath(); prepareTextures(basePath + "Textures/Skyboxes/", true, skyTextures); @@ -54,9 +53,10 @@ namespace battleship{ map = Map::getSingleton(); map->load(name, newMap); + Game *game = Game::getSingleton(); if(newMap){ - addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1))); + game->addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1))); map->addSpawnPoint(Vector3::VEC_ZERO); generatePlane(size); } @@ -64,7 +64,7 @@ namespace battleship{ int numPlayers = map->getNumSpawnPoints(); for(int i = 0; i < numPlayers; i++) - addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1))); + game->addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1))); map->loadPlayerGameObjects(); } @@ -306,10 +306,12 @@ namespace battleship{ doc->SaveFile(name.c_str()); } + //TODO add diagnally adjacent edges to underwater cells vector MapEditorAppState::MapEditor::generateMapCells(){ - Vector3 startPos = -.49 * Vector3(mapSize.x, 0, mapSize.y), cellSize = map->getCellSize(); + Vector3 mapSize = map->getMapSize(); + Vector3 startPos = -.49 * Vector3(mapSize.x, 0, mapSize.z), cellSize = map->getCellSize(); int numHorCells = int(mapSize.x / cellSize.x); - int numVertCells = int(mapSize.y / cellSize.z); + int numVertCells = int(mapSize.z / cellSize.z); vector cells; vector> waterBodyBedPoints; Node *terrainNode = map->getNodeParent(); @@ -344,7 +346,7 @@ namespace battleship{ cells.push_back(Map::Cell(pos, type, edges)); } - vector waterCells; + vector surfaceWaterCells; int currUnderWaterCellId = cells.size(); int weight = 20; @@ -357,27 +359,27 @@ namespace battleship{ for(int i = 0; i < numUnderWaterCells; i++, currUnderWaterCellId++) cells[p.first].underWaterCellIds.push_back(currUnderWaterCellId); - waterCells.push_back(cells[p.first]); + surfaceWaterCells.push_back(cells[p.first]); } } - for(int i = 0; i < waterCells.size(); i++){ - for(int j = 0; j < waterCells[i].underWaterCellIds.size(); j++){ - int aboveCellId = (j == 0 ? waterCells[i].edges[0].srcCellId : j - 1); - vector edges = vector{Map::Edge(weight, waterCells[i].underWaterCellIds[j], aboveCellId)}; + for(int i = 0; i < surfaceWaterCells.size(); i++){ + for(int j = 0; j < surfaceWaterCells[i].underWaterCellIds.size(); j++){ + int aboveCellId = (j == 0 ? surfaceWaterCells[i].edges[0].srcCellId : j - 1); + vector edges = vector{Map::Edge(weight, surfaceWaterCells[i].underWaterCellIds[j], aboveCellId)}; - if(waterCells[i].underWaterCellIds.size() > j + 1) - edges.push_back(Map::Edge(weight, waterCells[i].underWaterCellIds[j], waterCells[i].underWaterCellIds[j + 1])); + if(surfaceWaterCells[i].underWaterCellIds.size() > j + 1) + edges.push_back(Map::Edge(weight, surfaceWaterCells[i].underWaterCellIds[j], surfaceWaterCells[i].underWaterCellIds[j + 1])); - for(int k = 0; k < waterCells[i].edges.size(); k++){ - Map::Cell adjacentUnderwaterCell = cells[waterCells[i].edges[k].destCellId]; + for(int k = 0; k < surfaceWaterCells[i].edges.size() - 1; k++){ + Map::Cell adjacentUnderwaterCell = cells[surfaceWaterCells[i].edges[k].destCellId]; if(adjacentUnderwaterCell.underWaterCellIds.size() >= j + 1){ - edges.push_back(Map::Edge(weight, waterCells[i].underWaterCellIds[j], adjacentUnderwaterCell.underWaterCellIds[j])); + edges.push_back(Map::Edge(weight, surfaceWaterCells[i].underWaterCellIds[j], adjacentUnderwaterCell.underWaterCellIds[j])); } } - Vector3 cellPos = waterCells[i].pos - Vector3::VEC_J * cellSize.y * (j + 1); + Vector3 cellPos = surfaceWaterCells[i].pos - Vector3::VEC_J * cellSize.y * (j + 1); cells.push_back(Map::Cell(cellPos, Map::Cell::Type::WATER, edges)); } } @@ -387,8 +389,11 @@ namespace battleship{ void MapEditorAppState::MapEditor::generateMapScript(){ int numWaterBodies = map->getNodeParent()->getNumChildren() - 1; + vector players = Game::getSingleton()->getPlayers(); + + Vector3 mapSize = map->getMapSize(); string mapScript = "map = {\nnumWaterBodies = " + to_string(numWaterBodies) + ",\n"; - mapScript += "size = {x = " + to_string(mapSize.x) + ", y = 100, z = " + to_string(mapSize.y) + "},\n"; + mapScript += "size = {x = " + to_string(mapSize.x) + ", y = 100, z = " + to_string(mapSize.z) + "},\n"; mapScript += "impassibleNodeValue = " + to_string(IMPASS_NODE_VAL) + ",\n"; mapScript += "numPlayers = " + to_string(players.size()) + ",\n"; @@ -433,7 +438,7 @@ namespace battleship{ mapScript += "units = {\n"; for(int j = 0; j < numUnits; j++){ - Unit *unit = getPlayer(i)->getUnit(j); + Unit *unit = Game::getSingleton()->getPlayer(i)->getUnit(j); string idStr = "id = " + to_string(unit->getId()); @@ -594,7 +599,7 @@ namespace battleship{ switch((Bind)bind){ case Bind::LOOK_AROUND: if(ufCtr->isPlacingFrames()){ - Player *player = mapEditor->getPlayer(0); + Player *player = Game::getSingleton()->getPlayer(0); GameObjectFrame &frame = ufCtr->getGameObjectFrame(0); Model *model = frame.getModel(); Vector3 pos = model->getPosition(); diff --git a/mapEditorAppState.h b/mapEditorAppState.h index 80d8018..c89c965 100644 --- a/mapEditorAppState.h +++ b/mapEditorAppState.h @@ -40,8 +40,6 @@ namespace battleship{ void exportMap(); void prepareTerrainObjects(int = 0, int = -1); void togglePush(bool); - inline void addPlayer(Player *pl){players.push_back(pl);} - inline Player* getPlayer(int id){return players[id];} inline vb01::Node* getSelectedNode(){return selectedTerrainNode;} inline float getGuiThreshold(){return guiThreshold;} inline float getCircleRadius(){return circleRadius;} @@ -66,7 +64,6 @@ namespace battleship{ void prepareTerrainObject(vb01::u32**, Map::Cell*, int[3], float, bool); Map *map; - std::vector players; vb01::Node *selectedTerrainNode = nullptr; TransformAxis transformAxis = X_AXIS; vb01Gui::Listbox *skyListbox = nullptr; @@ -76,7 +73,6 @@ namespace battleship{ const int NUM_SUBDIVS = 100; float circleRadius = MIN_RADIUS, guiThreshold = 200; vb01::Vector3 pushPos = vb01::Vector3::VEC_ZERO; - vb01::Vector2 mapSize; std::vector skyTextures, landmassTextures, waterTextures; };