SpatialMap now uses unordered_multimap to allow for multiple items in a square, but they're also tagged to mark some with collision.
This commit is contained in:
parent
b193bab148
commit
f26189c696
6 changed files with 60 additions and 51 deletions
|
@ -5,10 +5,14 @@
|
|||
#include "dinkyecs.hpp"
|
||||
#include "point.hpp"
|
||||
|
||||
typedef std::vector<DinkyECS::Entity> EntityList;
|
||||
struct CollisionData {
|
||||
DinkyECS::Entity entity = DinkyECS::NONE;
|
||||
bool collision = false;
|
||||
};
|
||||
|
||||
// Point's has is in point.hpp
|
||||
using PointEntityMap = std::unordered_map<Point, DinkyECS::Entity>;
|
||||
using EntityList = std::vector<DinkyECS::Entity>;
|
||||
using PointEntityMap = std::unordered_multimap<Point, CollisionData>;
|
||||
using SortedEntities = std::vector<std::pair<int, DinkyECS::Entity>>;
|
||||
|
||||
struct FoundEntities {
|
||||
|
@ -19,18 +23,17 @@ struct FoundEntities {
|
|||
class SpatialMap {
|
||||
public:
|
||||
SpatialMap() {}
|
||||
PointEntityMap yes_collision;
|
||||
PointEntityMap no_collision;
|
||||
PointEntityMap $collision;
|
||||
|
||||
void insert(Point pos, DinkyECS::Entity obj, bool has_collision);
|
||||
void move(Point from, Point to, DinkyECS::Entity ent);
|
||||
// return value is whether the removed thing has collision
|
||||
bool remove(Point pos);
|
||||
CollisionData remove(Point pos, DinkyECS::Entity entity);
|
||||
bool occupied(Point pos) const;
|
||||
bool something_there(Point at) const;
|
||||
DinkyECS::Entity get(Point at) const;
|
||||
FoundEntities neighbors(Point position, bool diag=false) const;
|
||||
|
||||
SortedEntities distance_sorted(Point from, int max_distance);
|
||||
size_t size() { return yes_collision.size(); }
|
||||
size_t size() { return $collision.size(); }
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue