Refactor some code to have better naming and move Point and related point things into their own .hpp.

This commit is contained in:
Zed A. Shaw 2024-10-26 18:26:42 -04:00
parent c19cd707d1
commit 5a123ae74c
7 changed files with 45 additions and 40 deletions

View file

@ -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;