From e4f278fef15d6c45dd52ac9b0230365743cf2cc2 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 6 Jan 2024 10:28:05 +0200 Subject: [PATCH 1/6] optimized Djikstra's shortest path algorithm implementation --- map.cpp | 12 +------ map.h | 3 +- pathfinder.cpp | 81 +++++++++++++++++++++++++--------------------- pathfinder.h | 3 +- pathfinderTest.cpp | 11 +++++-- pathfinderTest.h | 2 ++ 6 files changed, 60 insertions(+), 52 deletions(-) diff --git a/map.cpp b/map.cpp index a6d562f..35be47f 100755 --- a/map.cpp +++ b/map.cpp @@ -22,16 +22,6 @@ using namespace gameBase; namespace battleship{ using namespace configData; - //TODO check if edges have lower weight than impassible weight value for the Pathfinder - int Map::Cell::getEdgeWeight(int destCellId){ - int weight = Pathfinder::getSingleton()->getImpassibleNodeVal(); - - for(Edge e : edges) - if(e.destCellId == destCellId) - weight = e.weight; - - return weight; - } Map *map = nullptr; @@ -230,7 +220,7 @@ namespace battleship{ Node *node = new Node(cellPos + Vector3::VEC_J * .1); node->attachMesh(quad); - cellNode->attachChild(node); + //cellNode->attachChild(node); cells.push_back(Cell(cellPos, cellType, edges, underWaterCellIds)); } diff --git a/map.h b/map.h index 951ebc2..28a724b 100755 --- a/map.h +++ b/map.h @@ -31,6 +31,7 @@ namespace battleship{ struct Cell{ enum Type{LAND, WATER}; + bool checked = false; Type type; vb01::Vector3 pos; std::vector edges; @@ -38,7 +39,7 @@ namespace battleship{ Cell(){} Cell(vb01::Vector3 p, Type t, std::vector e = std::vector{}, std::vector uc = std::vector{}): pos(p), type(t), edges(e), underWaterCellIds(uc){} - int getEdgeWeight(int); + //int getEdgeWeight(int); }; static Map* getSingleton(); diff --git a/pathfinder.cpp b/pathfinder.cpp index 7db4c59..9fb5290 100644 --- a/pathfinder.cpp +++ b/pathfinder.cpp @@ -16,56 +16,65 @@ namespace battleship{ return pathfinder; } - Pathfinder::Pathfinder(){ + int Pathfinder::findMinDistVert(vector &cells, u32 distances[]){ + int numCells = cells.size(), minDistVert; + + for(int i = 0; i < numCells; i++) + if(!cells[i].checked){ + minDistVert = i; + break; + } + + for(int i = 0; i < numCells; i++){ + bool checked = cells[i].checked; + + if(!checked && distances[i] < distances[minDistVert]) + minDistVert = i; + } + + return minDistVert; } vector Pathfinder::findPath(vector &cells, int source, int dest, int unitType){ int size = cells.size(); - u32 distances[size]; - vector paths[size]; - paths[source].push_back(source); + u32 distances[size]; + vector paths[size]; + paths[source].push_back(source); - for(int i = 0; i < size; i++) - distances[i] = (i == source ? 0 : impassibleNodeVal); + for(int i = 0; i < size; i++){ + cells[i].checked = false; + distances[i] = (i == source ? 0 : impassibleNodeVal); + } - vector checkedNodes; + while(!cells[dest].checked){ + int vertStrich = findMinDistVert(cells, distances); + cells[vertStrich].checked = true; - while(find(checkedNodes.begin(), checkedNodes.end(), dest) == checkedNodes.end()){ - bool initVertStrichSet = false; - int vertStrich; + int numEdges = cells[vertStrich].edges.size(); - for(int i = 0; i < size; i++){ - bool isChecked = find(checkedNodes.begin(), checkedNodes.end(), i) != checkedNodes.end(); + for(int i = 0; i < numEdges; i++){ + bool canMoveToStrichCell = true; + bool ship = ((UnitType)unitType == UnitType::UNDERWATER || (UnitType)unitType == UnitType::SEA_LEVEL); - if(!isChecked){ - if(!initVertStrichSet){ - vertStrich = i; - initVertStrichSet = true; - } + if((ship && cells[vertStrich].type != Map::Cell::WATER) || ((UnitType)unitType == UnitType::LAND && cells[vertStrich].type != Map::Cell::LAND)) + canMoveToStrichCell = false; - if(initVertStrichSet && (distances[vertStrich] > distances[i])) - vertStrich = i; - } - } + if(canMoveToStrichCell){ + int edgeNode = cells[vertStrich].edges[i].destCellId; + bool isChecked = cells[edgeNode].checked; - checkedNodes.push_back(vertStrich); - - for(int i = 0; i < size; i++){ - bool isChecked = find(checkedNodes.begin(), checkedNodes.end(), i) != checkedNodes.end(); - bool canMoveToStrichCell = true; - bool ship = ((UnitType)unitType == UnitType::UNDERWATER || (UnitType)unitType == UnitType::SEA_LEVEL); - - if((ship && cells[vertStrich].type != Map::Cell::WATER) || ((UnitType)unitType == UnitType::LAND && cells[vertStrich].type != Map::Cell::LAND)) - canMoveToStrichCell = false; - - if(!isChecked && (canMoveToStrichCell && distances[vertStrich] + cells[vertStrich].getEdgeWeight(i) < distances[i])){ - distances[i] = distances[vertStrich] + cells[vertStrich].getEdgeWeight(i); - paths[i] = paths[vertStrich]; - paths[i].push_back(i); + if(!isChecked && (distances[vertStrich] + cells[vertStrich].edges[i].weight < distances[edgeNode])){ + distances[edgeNode] = distances[vertStrich] + cells[vertStrich].edges[i].weight; + paths[edgeNode] = paths[vertStrich]; + paths[edgeNode].push_back(edgeNode); } } } + } - return paths[dest]; + for(int i = 0; i < size; i++) + cells[i].checked = false; + + return paths[dest]; } } diff --git a/pathfinder.h b/pathfinder.h index de76f0b..4fdaa02 100644 --- a/pathfinder.h +++ b/pathfinder.h @@ -15,7 +15,8 @@ namespace battleship{ inline vb01::u32 getImpassibleNodeVal(){return impassibleNodeVal;} inline void setImpassibleNodeVal(vb01::u32 val){this->impassibleNodeVal = val;} private: - Pathfinder(); + Pathfinder(){} + int findMinDistVert(std::vector&, vb01::u32[]); vb01::u32 impassibleNodeVal; }; diff --git a/pathfinderTest.cpp b/pathfinderTest.cpp index a1f7779..989cc73 100644 --- a/pathfinderTest.cpp +++ b/pathfinderTest.cpp @@ -16,7 +16,7 @@ namespace battleship{ Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector{Map::Edge(0, 1, 1), Map::Edge(1, 1, 2), Map::Edge(9, 1, 3), Map::Edge(13, 1, 4)}), Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector{Map::Edge(0, 2, 2), Map::Edge(2, 2, 1), Map::Edge(4, 2, 4), Map::Edge(5, 2, 5)}), Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector{Map::Edge(0, 3, 3), Map::Edge(1, 3, 6)}), - Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector{Map::Edge(0, 4, 4), Map::Edge(1, 4, 0), Map::Edge(1, 4, 3), Map::Edge(3, 4, 6)}), + Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector{Map::Edge(0, 4, 4), Map::Edge(1, 4, 1), Map::Edge(1, 4, 3), Map::Edge(2, 4, 5), Map::Edge(3, 4, 6)}), Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector{Map::Edge(0, 5, 5), Map::Edge(9, 5, 4), Map::Edge(2, 5, 6)}), Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector{Map::Edge(0, 6, 6)}) }; @@ -29,12 +29,17 @@ namespace battleship{ int sumPathWeights = 0; - for(int i = 1; i < path.size(); i++) - sumPathWeights += cells[path[i - 1]].getEdgeWeight(path[i]); + for(int i = 0; i < path.size() - 1; i++) + for(int j = 0; j < cells[path[i]].edges.size(); j++) + if(cells[path[i]].edges[j].destCellId == path[i + 1]) + sumPathWeights += cells[path[i]].edges[j].weight; CPPUNIT_ASSERT(sumPathWeights == 9); } + void PathfinderTest::testFindBigPath(){ + } + void PathfinderTest::setUp(){ pathfinder = Pathfinder::getSingleton(); } diff --git a/pathfinderTest.h b/pathfinderTest.h index 2cc4f09..fd0be64 100644 --- a/pathfinderTest.h +++ b/pathfinderTest.h @@ -10,11 +10,13 @@ namespace battleship{ class PathfinderTest : public CppUnit::TestFixture{ CPPUNIT_TEST_SUITE(PathfinderTest); CPPUNIT_TEST(testFindPath); + CPPUNIT_TEST(testFindBigPath); CPPUNIT_TEST_SUITE_END(); public: PathfinderTest(){} void testFindPath(); + void testFindBigPath(); void setUp(); void tearDown(); private: From ad5e71d00d88f92caf966147aba9ef9446c425c0 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 6 Jan 2024 11:18:00 +0200 Subject: [PATCH 2/6] added test for speed of pathfinding for large maps --- map.cpp | 32 ++++++++++++++++++++++++- map.h | 1 + pathfinderTest.cpp | 58 +++++++++++++++++++++++++++++++++++----------- pathfinderTest.h | 36 ++++++++++++++++------------ 4 files changed, 97 insertions(+), 30 deletions(-) diff --git a/map.cpp b/map.cpp index 35be47f..0dfbd4d 100755 --- a/map.cpp +++ b/map.cpp @@ -22,7 +22,6 @@ using namespace gameBase; namespace battleship{ using namespace configData; - Map *map = nullptr; Map* Map::getSingleton(){ @@ -32,6 +31,37 @@ namespace battleship{ return map; } + vector Map::generateAdjacentNodeEdges(int numVertCells, int i, int numHorCells, int j, int weight){ + vector edges; + bool up = (i > 0), right = (j < numHorCells - 1), down = (i < numVertCells - 1), left = (j > 0); + + if(left) + edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * i + j - 1)); + + if(right) + edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * i + j + 1)); + + if(up) + edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i - 1) + j)); + + if(down) + edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i + 1) + j)); + + if(up && left) + edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i - 1) + j - 1)); + + if(up && right) + edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i - 1) + j + 1)); + + if(down && left) + edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i + 1) + j - 1)); + + if(down && right) + edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i + 1) + j + 1)); + + return edges; + } + void Map::update(){ } diff --git a/map.h b/map.h index 28a724b..9b76cac 100755 --- a/map.h +++ b/map.h @@ -44,6 +44,7 @@ namespace battleship{ static Map* getSingleton(); ~Map(){} + static std::vector generateAdjacentNodeEdges(int, int, int, int, int); void update(); void load(std::string, bool = false); void unload(); diff --git a/pathfinderTest.cpp b/pathfinderTest.cpp index 989cc73..0a6ba6b 100644 --- a/pathfinderTest.cpp +++ b/pathfinderTest.cpp @@ -1,6 +1,5 @@ #include "pathfinderTest.h" #include "pathfinder.h" -#include "map.h" #include @@ -10,8 +9,31 @@ namespace battleship{ using namespace std; using namespace vb01; + vector PathfinderTest::generateCellGraph(int numCellsOnSide){ + vector cells; + + for(int i = 0; i < numCellsOnSide; i++) + for(int j = 0; j < numCellsOnSide; j++){ + vector edges = Map::generateAdjacentNodeEdges(numCellsOnSide, i, numCellsOnSide, j, 1); + cells.push_back(Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, edges)); + } + + return cells; + } + + int PathfinderTest::calcPathLength(vector &path){ + int sumPathWeights = 0; + + for(int i = 0; i < path.size() - 1; i++) + for(int j = 0; j < cells[path[i]].edges.size(); j++) + if(cells[path[i]].edges[j].destCellId == path[i + 1]) + sumPathWeights += cells[path[i]].edges[j].weight; + + return sumPathWeights; + } + void PathfinderTest::testFindPath(){ - vector cells = vector{ + cells = vector{ Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector{Map::Edge(0, 0, 0), Map::Edge(2, 0, 1), Map::Edge(4, 0, 2)}), Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector{Map::Edge(0, 1, 1), Map::Edge(1, 1, 2), Map::Edge(9, 1, 3), Map::Edge(13, 1, 4)}), Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector{Map::Edge(0, 2, 2), Map::Edge(2, 2, 1), Map::Edge(4, 2, 4), Map::Edge(5, 2, 5)}), @@ -21,29 +43,37 @@ namespace battleship{ Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector{Map::Edge(0, 6, 6)}) }; - int size = cells.size(); const u16 INF = u16(0 - 1); pathfinder->setImpassibleNodeVal(INF); - vector path = pathfinder->findPath(cells, 0, size - 1); + + vector path = pathfinder->findPath(cells, 0, cells.size() - 1); CPPUNIT_ASSERT(path == vector({0, 1, 2, 4, 3, 6})); - int sumPathWeights = 0; - - for(int i = 0; i < path.size() - 1; i++) - for(int j = 0; j < cells[path[i]].edges.size(); j++) - if(cells[path[i]].edges[j].destCellId == path[i + 1]) - sumPathWeights += cells[path[i]].edges[j].weight; - + int sumPathWeights = calcPathLength(path); CPPUNIT_ASSERT(sumPathWeights == 9); } void PathfinderTest::testFindBigPath(){ + int numIterations = 10; + cells = generateCellGraph(60); + s64 sumTime = 0; + + for(int i = 0; i < numIterations; i++){ + s64 t0 = getTime(); + pathfinder->findPath(cells, 0, cells.size() - 1); + s64 t1 = getTime(); + sumTime += t1 - t0; + } + + int threshold = 100; + double avg = (double)sumTime / numIterations, eps = .1; + cout << "Total time: " << sumTime << endl; + CPPUNIT_ASSERT(sumTime <= threshold); } void PathfinderTest::setUp(){ - pathfinder = Pathfinder::getSingleton(); + pathfinder = Pathfinder::getSingleton(); } - void PathfinderTest::tearDown(){ - } + void PathfinderTest::tearDown(){} } diff --git a/pathfinderTest.h b/pathfinderTest.h index fd0be64..7a35ee1 100644 --- a/pathfinderTest.h +++ b/pathfinderTest.h @@ -4,24 +4,30 @@ #include #include +#include "map.h" + namespace battleship{ - class Pathfinder; + class Pathfinder; - class PathfinderTest : public CppUnit::TestFixture{ - CPPUNIT_TEST_SUITE(PathfinderTest); - CPPUNIT_TEST(testFindPath); - CPPUNIT_TEST(testFindBigPath); - CPPUNIT_TEST_SUITE_END(); + class PathfinderTest : public CppUnit::TestFixture{ + CPPUNIT_TEST_SUITE(PathfinderTest); + CPPUNIT_TEST(testFindPath); + CPPUNIT_TEST(testFindBigPath); + CPPUNIT_TEST_SUITE_END(); - public: - PathfinderTest(){} - void testFindPath(); - void testFindBigPath(); - void setUp(); - void tearDown(); - private: - Pathfinder *pathfinder = nullptr; - }; + public: + PathfinderTest(){} + void testFindPath(); + void testFindBigPath(); + void setUp(); + void tearDown(); + private: + Pathfinder *pathfinder = nullptr; + std::vector cells; + + std::vector generateCellGraph(int); + int calcPathLength(std::vector&); + }; } #endif From b3ea94629d0f5449a3dcd161e71bc411a304ca4d Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 6 Jan 2024 12:38:25 +0200 Subject: [PATCH 3/6] styling --- pathfinder.cpp | 6 +++--- pathfinder.h | 22 +++++++++++----------- pathfinderTest.cpp | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pathfinder.cpp b/pathfinder.cpp index 9fb5290..2d6148a 100644 --- a/pathfinder.cpp +++ b/pathfinder.cpp @@ -10,10 +10,10 @@ namespace battleship{ static Pathfinder *pathfinder = nullptr; Pathfinder* Pathfinder::getSingleton(){ - if(!pathfinder) - pathfinder = new Pathfinder(); + if(!pathfinder) + pathfinder = new Pathfinder(); - return pathfinder; + return pathfinder; } int Pathfinder::findMinDistVert(vector &cells, u32 distances[]){ diff --git a/pathfinder.h b/pathfinder.h index 4fdaa02..d1fb88b 100644 --- a/pathfinder.h +++ b/pathfinder.h @@ -8,18 +8,18 @@ #include namespace battleship{ - class Pathfinder{ - public: - static Pathfinder* getSingleton(); - std::vector findPath(std::vector&, int, int, int = -1); - inline vb01::u32 getImpassibleNodeVal(){return impassibleNodeVal;} - inline void setImpassibleNodeVal(vb01::u32 val){this->impassibleNodeVal = val;} - private: - Pathfinder(){} - int findMinDistVert(std::vector&, vb01::u32[]); + class Pathfinder{ + public: + static Pathfinder* getSingleton(); + std::vector findPath(std::vector&, int, int, int = -1); + inline vb01::u32 getImpassibleNodeVal(){return impassibleNodeVal;} + inline void setImpassibleNodeVal(vb01::u32 val){this->impassibleNodeVal = val;} + private: + Pathfinder(){} + int findMinDistVert(std::vector&, vb01::u32[]); - vb01::u32 impassibleNodeVal; - }; + vb01::u32 impassibleNodeVal; + }; } #endif diff --git a/pathfinderTest.cpp b/pathfinderTest.cpp index 0a6ba6b..ab46c25 100644 --- a/pathfinderTest.cpp +++ b/pathfinderTest.cpp @@ -54,7 +54,7 @@ namespace battleship{ } void PathfinderTest::testFindBigPath(){ - int numIterations = 10; + int numIterations = 1; cells = generateCellGraph(60); s64 sumTime = 0; From 0a552d24b67050f0e8b66cf1ebf2464a30e13a07 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 6 Jan 2024 14:09:33 +0200 Subject: [PATCH 4/6] removed checked flag from Map::Cell --- map.h | 2 -- pathfinder.cpp | 20 +++++++++----------- pathfinder.h | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/map.h b/map.h index 9b76cac..e0f8958 100755 --- a/map.h +++ b/map.h @@ -31,7 +31,6 @@ namespace battleship{ struct Cell{ enum Type{LAND, WATER}; - bool checked = false; Type type; vb01::Vector3 pos; std::vector edges; @@ -39,7 +38,6 @@ namespace battleship{ Cell(){} Cell(vb01::Vector3 p, Type t, std::vector e = std::vector{}, std::vector uc = std::vector{}): pos(p), type(t), edges(e), underWaterCellIds(uc){} - //int getEdgeWeight(int); }; static Map* getSingleton(); diff --git a/pathfinder.cpp b/pathfinder.cpp index 2d6148a..fbe8f41 100644 --- a/pathfinder.cpp +++ b/pathfinder.cpp @@ -16,17 +16,17 @@ namespace battleship{ return pathfinder; } - int Pathfinder::findMinDistVert(vector &cells, u32 distances[]){ + int Pathfinder::findMinDistVert(vector> &cells, u32 distances[]){ int numCells = cells.size(), minDistVert; for(int i = 0; i < numCells; i++) - if(!cells[i].checked){ + if(!cells[i].second){ minDistVert = i; break; } for(int i = 0; i < numCells; i++){ - bool checked = cells[i].checked; + bool checked = cells[i].second; if(!checked && distances[i] < distances[minDistVert]) minDistVert = i; @@ -40,15 +40,16 @@ namespace battleship{ u32 distances[size]; vector paths[size]; paths[source].push_back(source); + vector> cellsByCheck; for(int i = 0; i < size; i++){ - cells[i].checked = false; + cellsByCheck.push_back(pair(i, false)); distances[i] = (i == source ? 0 : impassibleNodeVal); } - while(!cells[dest].checked){ - int vertStrich = findMinDistVert(cells, distances); - cells[vertStrich].checked = true; + while(!cellsByCheck[dest].second){ + int vertStrich = findMinDistVert(cellsByCheck, distances); + cellsByCheck[vertStrich].second = true; int numEdges = cells[vertStrich].edges.size(); @@ -61,7 +62,7 @@ namespace battleship{ if(canMoveToStrichCell){ int edgeNode = cells[vertStrich].edges[i].destCellId; - bool isChecked = cells[edgeNode].checked; + bool isChecked = cellsByCheck[edgeNode].second; if(!isChecked && (distances[vertStrich] + cells[vertStrich].edges[i].weight < distances[edgeNode])){ distances[edgeNode] = distances[vertStrich] + cells[vertStrich].edges[i].weight; @@ -72,9 +73,6 @@ namespace battleship{ } } - for(int i = 0; i < size; i++) - cells[i].checked = false; - return paths[dest]; } } diff --git a/pathfinder.h b/pathfinder.h index d1fb88b..a91d64b 100644 --- a/pathfinder.h +++ b/pathfinder.h @@ -16,7 +16,7 @@ namespace battleship{ inline void setImpassibleNodeVal(vb01::u32 val){this->impassibleNodeVal = val;} private: Pathfinder(){} - int findMinDistVert(std::vector&, vb01::u32[]); + int findMinDistVert(std::vector>&, vb01::u32[]); vb01::u32 impassibleNodeVal; }; From 5b34058ac7dcdedcd64d07b68ff48121e2d5610e Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 6 Jan 2024 14:25:52 +0200 Subject: [PATCH 5/6] optimized edge calculation for adjacent cells --- mapEditorAppState.cpp | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index ebf1f17..0350f0e 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -329,34 +329,7 @@ namespace battleship{ } } - vector edges; - int weight = 1; - bool up = (i > 0), right = (j < numHorCells - 1), down = (i < numVertCells - 1), left = (j > 0); - - if(left) - edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * i + j - 1)); - - if(right) - edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * i + j + 1)); - - if(up) - edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i - 1) + j)); - - if(down) - edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i + 1) + j)); - - if(up && left) - edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i - 1) + j - 1)); - - if(up && right) - edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i - 1) + j + 1)); - - if(down && left) - edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i + 1) + j - 1)); - - if(down && right) - edges.push_back(Map::Edge(weight, numVertCells * i + j, numVertCells * (i + 1) + j + 1)); - + vector edges = Map::generateAdjacentNodeEdges(numVertCells, i, numHorCells, j, 1); cells.push_back(Map::Cell(pos, type, edges)); } From 4f86880433b9bec07aad6a0f804ac94b7a5d3355 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 6 Jan 2024 15:40:51 +0200 Subject: [PATCH 6/6] bandaid fix for poor performance on 300x300+ maps --- external/vb01 | 2 +- map.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/external/vb01 b/external/vb01 index 8d7a886..9cd6604 160000 --- a/external/vb01 +++ b/external/vb01 @@ -1 +1 @@ -Subproject commit 8d7a88688c6ac93e9d40a181aded07351b848d77 +Subproject commit 9cd660454cc2b3d6bd988539848a08659c100a19 diff --git a/map.cpp b/map.cpp index 0dfbd4d..25b63cb 100755 --- a/map.cpp +++ b/map.cpp @@ -220,6 +220,7 @@ namespace battleship{ cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm()); } + //TODO implement toggleable cell rendering void Map::loadCells(){ sol::state_view SOL_LUA_VIEW = generateView(); int numCells = SOL_LUA_VIEW[mapTable]["numCells"]; @@ -250,7 +251,6 @@ namespace battleship{ Node *node = new Node(cellPos + Vector3::VEC_J * .1); node->attachMesh(quad); - //cellNode->attachChild(node); cells.push_back(Cell(cellPos, cellType, edges, underWaterCellIds)); }