From b0526ca51bb506435545fbf1442140a494077ab8 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sat, 27 Aug 2022 21:25:24 +0400 Subject: [PATCH] Refactoring --- lib/rmg/RmgArea.cpp | 6 ++---- lib/rmg/RmgArea.h | 3 +++ lib/rmg/RmgMap.cpp | 7 ++----- lib/rmg/RmgPath.cpp | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/rmg/RmgArea.cpp b/lib/rmg/RmgArea.cpp index ee6cd9d1a..a2fb40045 100644 --- a/lib/rmg/RmgArea.cpp +++ b/lib/rmg/RmgArea.cpp @@ -88,11 +88,9 @@ bool Area::connected() const std::list connectedAreas(const Area & area, bool disableDiagonalConnections) { auto allDirs = int3::getDirs(); - std::vector dirs; + std::vector dirs(allDirs.begin(), allDirs.end()); if(disableDiagonalConnections) - dirs.insert(dirs.begin(), allDirs.begin(), allDirs.begin() + 4); - else - dirs.insert(dirs.begin(), allDirs.begin(), allDirs.end()); + dirs.assign(rmg::dirs4.begin(), rmg::dirs4.end()); std::list result; Tileset connected = area.getTiles(); diff --git a/lib/rmg/RmgArea.h b/lib/rmg/RmgArea.h index 367571688..bc821dc02 100644 --- a/lib/rmg/RmgArea.h +++ b/lib/rmg/RmgArea.h @@ -15,6 +15,9 @@ namespace rmg { + static const std::array dirs4 = { int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0) }; + static const std::array dirsDiagonal= { int3(1,1,0),int3(1,-1,0),int3(-1,1,0),int3(-1,-1,0) }; + using Tileset = std::set; using DistanceMap = std::map; void toAbsolute(Tileset & tiles, const int3 & position); diff --git a/lib/rmg/RmgMap.cpp b/lib/rmg/RmgMap.cpp index d6074106b..732bb59af 100644 --- a/lib/rmg/RmgMap.cpp +++ b/lib/rmg/RmgMap.cpp @@ -30,9 +30,6 @@ #include "Functions.h" #include "CMapGenerator.h" -static const int3 dirs4[] = {int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0)}; -static const int3 dirsDiagonal[] = { int3(1,1,0),int3(1,-1,0),int3(-1,1,0),int3(-1,-1,0) }; - RmgMap::RmgMap(const CMapGenOptions& mapGenOptions) : mapGenOptions(mapGenOptions), zonesTotal(0) { @@ -54,7 +51,7 @@ void RmgMap::foreach_neighbour(const int3 &pos, std::function f void RmgMap::foreachDirectNeighbour(const int3& pos, std::function foo) { - for(const int3 &dir : dirs4) + for(const int3 &dir : rmg::dirs4) { int3 n = pos + dir; if(mapInstance->isInTheMap(n)) @@ -64,7 +61,7 @@ void RmgMap::foreachDirectNeighbour(const int3& pos, std::function foo) { - for (const int3 &dir : dirsDiagonal) + for (const int3 &dir : rmg::dirsDiagonal) { int3 n = pos + dir; if (mapInstance->isInTheMap(n)) diff --git a/lib/rmg/RmgPath.cpp b/lib/rmg/RmgPath.cpp index 5fdd9a887..7e38ae04c 100644 --- a/lib/rmg/RmgPath.cpp +++ b/lib/rmg/RmgPath.cpp @@ -137,7 +137,7 @@ Path Path::search(const Tileset & dst, bool straight, std::function neighbors(dirs.begin(), dirs.end()); if(straight) - neighbors = { { int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0) } }; + neighbors.assign(rmg::dirs4.begin(), rmg::dirs4.end()); for(auto & i : neighbors) { computeTileScore(currentNode + i);