You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
756 B
33 lines
756 B
4 weeks ago
|
#pragma once
|
||
|
#include <vector>
|
||
|
#include <unordered_map>
|
||
|
#include "map.hpp"
|
||
|
#include "dinkyecs.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> FoundList;
|
||
|
|
||
|
class SpatialHashTable {
|
||
|
public:
|
||
|
SpatialHashTable() {}
|
||
|
|
||
|
// disable copying, I think?
|
||
|
SpatialHashTable(SpatialHashTable &other) = delete;
|
||
|
|
||
|
void insert(Point pos, DinkyECS::Entity obj);
|
||
|
void move(Point from, Point to, DinkyECS::Entity ent);
|
||
|
void remove(Point pos);
|
||
|
bool occupied(Point pos);
|
||
|
|
||
|
std::tuple<bool, FoundList> neighbors(Point position);
|
||
|
|
||
|
private:
|
||
|
std::unordered_map<Point, DinkyECS::Entity, PointHash> table;
|
||
|
};
|