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.
45 lines
1.2 KiB
45 lines
1.2 KiB
#pragma once
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#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<DinkyECS::Entity>;
|
|
using PointEntityMap = std::unordered_multimap<Point, CollisionData>;
|
|
using SortedEntities = std::vector<EntityDistance>;
|
|
|
|
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;
|
|
|
|
void distance_sorted(SortedEntities& sorted_sprites, Point from, int max_distance);
|
|
size_t size() { return $collision.size(); }
|
|
};
|
|
|