Refactor some code to have better naming and move Point and related point things into their own .hpp.
This commit is contained in:
parent
c19cd707d1
commit
5a123ae74c
7 changed files with 45 additions and 40 deletions
14
collider.hpp
14
collider.hpp
|
@ -3,26 +3,22 @@
|
|||
#include <unordered_map>
|
||||
#include "map.hpp"
|
||||
#include "dinkyecs.hpp"
|
||||
#include "point.hpp"
|
||||
#include <tuple>
|
||||
|
||||
struct PointHash {
|
||||
size_t operator()(const Point& p) const {
|
||||
return std::hash<int>()(p.x) ^ std::hash<int>()(p.y);
|
||||
}
|
||||
};
|
||||
typedef std::vector<DinkyECS::Entity> EntityList;
|
||||
|
||||
typedef std::vector<DinkyECS::Entity> FoundList;
|
||||
typedef std::unordered_map<Point, DinkyECS::Entity, PointHash> PointEntityMap;
|
||||
|
||||
class SpatialHashTable {
|
||||
class spatial_map {
|
||||
public:
|
||||
SpatialHashTable() {}
|
||||
spatial_map() {}
|
||||
|
||||
void insert(Point pos, DinkyECS::Entity obj);
|
||||
void move(Point from, Point to, DinkyECS::Entity ent);
|
||||
void remove(Point pos);
|
||||
bool occupied(Point pos) const;
|
||||
std::tuple<bool, FoundList> neighbors(Point position, bool diag=false) const;
|
||||
std::tuple<bool, EntityList> neighbors(Point position, bool diag=false) const;
|
||||
|
||||
private:
|
||||
PointEntityMap table;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue