|
|
|
@ -53,12 +53,7 @@ Entity SpatialMap::get(Point at) const { |
|
|
|
|
return begin->second.entity; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Avoid doing work by using the dy,dx and confirming that |
|
|
|
|
* at.x or at.y is > 0. If either is 0 then there can't be |
|
|
|
|
* a neighbor since that's out of bounds. |
|
|
|
|
*/ |
|
|
|
|
inline void find_neighbor(const PointEntityMap &table, EntityList &result, Point at, int dy, int dx) { |
|
|
|
|
void SpatialMap::find_neighbor(EntityList &result, Point at, int dy, int dx) const { |
|
|
|
|
// don't bother checking for cells out of bounds
|
|
|
|
|
if((dx < 0 && at.x <= 0) || (dy < 0 && at.y <= 0)) { |
|
|
|
|
return; |
|
|
|
@ -66,11 +61,11 @@ inline void find_neighbor(const PointEntityMap &table, EntityList &result, Point |
|
|
|
|
|
|
|
|
|
Point cell = {at.x + dx, at.y + dy}; |
|
|
|
|
|
|
|
|
|
// Bug #81, should actually for-loop through these and only add ones with collision
|
|
|
|
|
auto it = table.find(cell); |
|
|
|
|
if (it != table.end()) { |
|
|
|
|
result.insert(result.end(), it->second.entity); |
|
|
|
|
} |
|
|
|
|
auto entity = find(cell, [&](auto data) { |
|
|
|
|
return data.collision; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if(entity != DinkyECS::NONE) result.push_back(entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FoundEntities SpatialMap::neighbors(Point cell, bool diag) const { |
|
|
|
@ -78,16 +73,16 @@ FoundEntities SpatialMap::neighbors(Point cell, bool diag) const { |
|
|
|
|
|
|
|
|
|
// just unroll the loop since we only check four directions
|
|
|
|
|
// this also solves the problem that it was detecting that the cell was automatically included as a "neighbor" but it's not
|
|
|
|
|
find_neighbor($collision, result, cell, 0, 1); // north
|
|
|
|
|
find_neighbor($collision, result, cell, 0, -1); // south
|
|
|
|
|
find_neighbor($collision, result, cell, 1, 0); // east
|
|
|
|
|
find_neighbor($collision, result, cell, -1, 0); // west
|
|
|
|
|
find_neighbor(result, cell, 0, 1); // north
|
|
|
|
|
find_neighbor(result, cell, 0, -1); // south
|
|
|
|
|
find_neighbor(result, cell, 1, 0); // east
|
|
|
|
|
find_neighbor(result, cell, -1, 0); // west
|
|
|
|
|
|
|
|
|
|
if(diag) { |
|
|
|
|
find_neighbor($collision, result, cell, 1, -1); // south east
|
|
|
|
|
find_neighbor($collision, result, cell, -1, -1); // south west
|
|
|
|
|
find_neighbor($collision, result, cell, 1, 1); // north east
|
|
|
|
|
find_neighbor($collision, result, cell, -1, 1); // north west
|
|
|
|
|
find_neighbor(result, cell, 1, -1); // south east
|
|
|
|
|
find_neighbor(result, cell, -1, -1); // south west
|
|
|
|
|
find_neighbor(result, cell, 1, 1); // north east
|
|
|
|
|
find_neighbor(result, cell, -1, 1); // north west
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return {!result.empty(), result}; |
|
|
|
|