now use unordered_map in MapScene for better performance
This commit is contained in:
parent
a025b51e37
commit
0b8a629309
@ -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
|
||||
|
@ -104,5 +104,6 @@ void MapScene::draw()
|
||||
|
||||
// clearing temporary data structures
|
||||
m_updatedCoordMap.clear();
|
||||
m_updatedCoordMap.rehash(0);
|
||||
m_pixels.clear();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <QMutex>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
struct MapScene : public Map, public BasicScene
|
||||
{
|
||||
@ -48,7 +48,7 @@ private:
|
||||
Pix(glm::vec2 p, glm::vec3 c) : pos(p), color(c) {}
|
||||
};
|
||||
std::vector<Pix> m_pixels;
|
||||
std::map<Coord, int> m_updatedCoordMap;
|
||||
std::unordered_map<Coord, int, CoordHash> m_updatedCoordMap;
|
||||
};
|
||||
|
||||
#endif // MAPSCENE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user