From 8964b47ff1a6f1da105d21ad8377596ad4d94b92 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 28 Jul 2024 12:00:51 +0300 Subject: [PATCH 1/4] updated vb01 --- external/vb01 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/vb01 b/external/vb01 index 6077cf9..54b4d55 160000 --- a/external/vb01 +++ b/external/vb01 @@ -1 +1 @@ -Subproject commit 6077cf9cdea190eba994716a74ca67e511d196d0 +Subproject commit 54b4d55f8d2db467bd051734ce7abad78523eadc From cf74b5cae1d5c9c329fc9abbbb0d912ab7b0d26b Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 28 Jul 2024 14:23:54 +0300 Subject: [PATCH 2/4] map reading improvements --- map.cpp | 3 +-- map.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/map.cpp b/map.cpp index 04a2b1d..bc8f6e4 100755 --- a/map.cpp +++ b/map.cpp @@ -142,8 +142,7 @@ namespace battleship{ void Map::loadSpawnPoints(){ sol::state_view SOL_LUA_VIEW = generateView(); string spawnPointInd = "spawnPoints"; - SOL_LUA_VIEW.script("numSpawnPoints = #" + mapTable + "." + spawnPointInd); - int numSpawnPoints = SOL_LUA_VIEW["numSpawnPoints"]; + int numSpawnPoints = ((sol::table)SOL_LUA_VIEW[mapTable][spawnPointInd]).size(); for(int i = 0; i < numSpawnPoints; i++){ sol::table posTable = SOL_LUA_VIEW[mapTable][spawnPointInd][i + 1]; diff --git a/map.h b/map.h index 0d5d4fb..2810b3d 100755 --- a/map.h +++ b/map.h @@ -54,6 +54,7 @@ namespace battleship{ inline vb01::Vector3 getCellSize(){return CELL_SIZE;} inline int getNumSpawnPoints(){return spawnPoints.size();} inline vb01::Vector3 getSpawnPoint(int i){return spawnPoints[i];} + inline vb01::Vector3 getMapSize(){return mapSize;} inline void addSpawnPoint(vb01::Vector3 sp){spawnPoints.push_back(sp);} inline std::vector& getCells(){return cells;} private: From 882ca02b664ce23fd8d01895a58c820006ec31ea Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 28 Jul 2024 14:24:18 +0300 Subject: [PATCH 3/4] 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; }; From bf6a617cff66a91027b8650100c6a4b542f2e2e1 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 28 Jul 2024 16:42:39 +0300 Subject: [PATCH 4/4] changes to accomodate MSVC --- map.cpp | 3 ++- util.cpp | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/map.cpp b/map.cpp index 1390084..52f7741 100755 --- a/map.cpp +++ b/map.cpp @@ -142,7 +142,8 @@ namespace battleship{ void Map::loadSpawnPoints(){ sol::state_view SOL_LUA_VIEW = generateView(); string spawnPointInd = "spawnPoints"; - int numSpawnPoints = ((sol::table)SOL_LUA_VIEW[mapTable][spawnPointInd]).size(); + sol::table spawnPointsTbl = SOL_LUA_VIEW[mapTable][spawnPointInd]; + int numSpawnPoints = spawnPointsTbl.size(); for(int i = 0; i < numSpawnPoints; i++){ sol::table posTable = SOL_LUA_VIEW[mapTable][spawnPointInd][i + 1]; diff --git a/util.cpp b/util.cpp index 330937e..0dd5080 100755 --- a/util.cpp +++ b/util.cpp @@ -288,10 +288,10 @@ namespace battleship{ } Camera *cam = Root::getSingleton()->getCamera(); - float near = cam->getNearPlane(); + float camNorm = cam->getNearPlane(); float tg = tan(radians(cam->getFov()) / 2), ar = midWidth / midHeight; - float camHeight = near * tg, camWidth = camHeight * ar; - Vector3 posOffset = (cam->getLeft() * camWidth * horOffset + cam->getUp() * camHeight * vertOffset + cam->getDirection() * near); + float camHeight = camNorm * tg, camWidth = camHeight * ar; + Vector3 posOffset = (cam->getLeft() * camWidth * horOffset + cam->getUp() * camHeight * vertOffset + cam->getDirection() * camNorm); return cam->getPosition() + posOffset; }