diff --git a/GenMap/src/Cell.cpp b/GenMap/src/Cell.cpp index c6af62ba17e88a60acf51809bbae70da97ff1440..b2fb897e4c7c8214c2aef34c2c37ec860e7b66ce 100644 --- a/GenMap/src/Cell.cpp +++ b/GenMap/src/Cell.cpp @@ -25,7 +25,7 @@ Cell* Cell::FindAdjRegion() const { if (area == nullptr) { - auto c = std::find_if(begin(neighbors), end(neighbors), [](Cell* c) {return (c->GetRegion() != nullptr); }); + auto c = std::find_if(begin(neighbors), end(neighbors), [](Cell* c) {if (c!= nullptr) return (c->GetRegion() != nullptr); }); return (c == end(neighbors) ? nullptr : *c); } else return nullptr; diff --git a/GenMap/src/Cell.h b/GenMap/src/Cell.h index 772a9e01e6175a2a7dc25535d969bd629a2f9b14..e0a9913d348535467c86dbafcc0f8ccb1882ae82 100644 --- a/GenMap/src/Cell.h +++ b/GenMap/src/Cell.h @@ -4,6 +4,7 @@ #include <array> #include <algorithm> #include <set> +#include <iostream> class Region; @@ -13,16 +14,19 @@ protected: Region* area; unsigned int x; unsigned int y; - std::vector<Cell*> neighbors; + //std::vector<Cell*> neighbors; + std::array<Cell*,6> neighbors; + unsigned int n_neighbors; public: - Cell(unsigned int X, unsigned int Y, Region* R) : x(X), y(Y), area(R), neighbors{} {}; + Cell(unsigned int X, unsigned int Y, Region* R): x(X), y(Y), area(R), neighbors{}, n_neighbors(0) {}; Cell(const Cell& c) = default; Cell(Cell&& c) = default; virtual ~Cell() = default; Cell& operator=(const Cell& c) = delete; Cell& operator=(Cell&& c) = delete; - inline void AddNeighbor(Cell* c) { neighbors.push_back(c); }; + inline void AddNeighbor(Cell* c) { neighbors[n_neighbors++] = c; }; + //inline void AddNeighbor(Cell* c) { neighbors.push_back(c); }; std::array<std::pair<int, int>, 6> NeighborsCoords(unsigned int r, unsigned int c); inline const std::pair<unsigned int, unsigned int> GetCoords() const { return { x,y }; }; inline Region* GetRegion() const { return area; }; diff --git a/GenMap/src/Map.h b/GenMap/src/Map.h index c863429cb3a29bdaba2d97c3fc52e00c5d6dc4f4..e13661771152832edb2984a56cf6b031ea8242c0 100644 --- a/GenMap/src/Map.h +++ b/GenMap/src/Map.h @@ -24,7 +24,6 @@ public: void DeleteRandRegions(); bool ContiguityTest(Region* r); std::vector<std::vector<std::pair<unsigned int, unsigned int>>> GetRegions(); - };