#include "collider.hpp" using DinkyECS::Entity; void SpatialHashTable::insert(Point pos, Entity ent) { table[pos] = ent; } void SpatialHashTable::remove(Point pos) { table.erase(pos); } void SpatialHashTable::move(Point from, Point to, Entity ent) { remove(from); insert(to, ent); } bool SpatialHashTable::occupied(Point at) { return table[at]; } std::tuple SpatialHashTable::neighbors(Point cell) { FoundList result; // Check the current cell and its 8 neighbors // BUG: this can sign underflow, assert it won't for (size_t x = cell.x - 1; x <= cell.x + 1; x++) { for (size_t y = cell.y - 1; y <= cell.y + 1; y++) { Point neighborCell = {x, y}; auto it = table.find(neighborCell); if (it != table.end()) { result.insert(result.end(), it->second); } } } return std::tuple(!result.empty(), result); }