diff --git a/src/coord.h b/src/coord.h index 1ae4fca..63b0b2f 100644 --- a/src/coord.h +++ b/src/coord.h @@ -33,6 +33,8 @@ struct Coord default : x= 0; y= 0; break; } } + bool operator==(const Coord &c) const + { return x==c.x&&y==c.y;} Coord operator+(const Coord &c) const { return Coord(x+c.x, y+c.y);} Coord& operator+=(const Coord &c) @@ -69,6 +71,13 @@ struct Coord { return dist(*this, c); } int dist(int x, int y) const { return dist(*this, Coord(x, y)); } + +}; + +struct CoordHash{ + size_t operator()(const Coord& val) const{ + return val.x+10000*val.y; + } }; #endif // COORD_H diff --git a/src/mapscene.cpp b/src/mapscene.cpp index 2cccbc1..6c727e2 100644 --- a/src/mapscene.cpp +++ b/src/mapscene.cpp @@ -104,5 +104,6 @@ void MapScene::draw() // clearing temporary data structures m_updatedCoordMap.clear(); + m_updatedCoordMap.rehash(0); m_pixels.clear(); } diff --git a/src/mapscene.h b/src/mapscene.h index 457f882..e006eec 100644 --- a/src/mapscene.h +++ b/src/mapscene.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include struct MapScene : public Map, public BasicScene { @@ -48,7 +48,7 @@ private: Pix(glm::vec2 p, glm::vec3 c) : pos(p), color(c) {} }; std::vector m_pixels; - std::map m_updatedCoordMap; + std::unordered_map m_updatedCoordMap; }; #endif // MAPSCENE_H