Fix up the spatialmap to have an occupied_by method which checks if a square is occupied and returns what is there.

This commit is contained in:
Zed A. Shaw 2025-09-02 12:46:05 -04:00
parent 759f93cae0
commit a11e7de14e
7 changed files with 24 additions and 43 deletions

View file

@ -32,15 +32,19 @@ void SpatialMap::move(Point from, Point to, Entity ent) {
insert(to, ent, data.collision);
}
bool SpatialMap::occupied(Point at) const {
Entity SpatialMap::occupied_by(Point at) const {
auto [begin, end] = $collision.equal_range(at);
for(auto it = begin; it != end; ++it) {
if(it->second.collision) {
return true;
return it->second.entity;
}
}
return false;
return DinkyECS::NONE;
}
bool SpatialMap::occupied(Point at) const {
return occupied_by(at) != DinkyECS::NONE;
}
bool SpatialMap::something_there(Point at) const {