Implemented a simple collision hash table.
This commit is contained in:
parent
dbc2a10933
commit
743f906bc7
7 changed files with 174 additions and 1 deletions
32
collider.hpp
Normal file
32
collider.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#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;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue