#pragma once #include #include #include "map.hpp" #include "dinkyecs.hpp" #include "point.hpp" struct CollisionData { DinkyECS::Entity entity = DinkyECS::NONE; bool collision = false; }; struct EntityDistance { int dist_square=0; DinkyECS::Entity entity=DinkyECS::NONE; float wiggle=0.0f; }; // Point's has is in point.hpp using EntityList = std::vector; using PointEntityMap = std::unordered_multimap; using SortedEntities = std::vector; struct FoundEntities { bool found; EntityList nearby; }; class SpatialMap { public: SpatialMap() {} 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 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 $collision.size(); } };