Refactor some code to have better naming and move Point and related point things into their own .hpp.

This commit is contained in:
Zed A. Shaw 2024-10-26 18:26:42 -04:00
parent c19cd707d1
commit 5a123ae74c
7 changed files with 45 additions and 40 deletions

View file

@ -5,20 +5,20 @@ using namespace fmt;
using DinkyECS::Entity;
void SpatialHashTable::insert(Point pos, Entity ent) {
void spatial_map::insert(Point pos, Entity ent) {
table[pos] = ent;
}
void SpatialHashTable::remove(Point pos) {
void spatial_map::remove(Point pos) {
table.erase(pos);
}
void SpatialHashTable::move(Point from, Point to, Entity ent) {
void spatial_map::move(Point from, Point to, Entity ent) {
remove(from);
insert(to, ent);
}
bool SpatialHashTable::occupied(Point at) const {
bool spatial_map::occupied(Point at) const {
return table.contains(at);
}
@ -27,7 +27,7 @@ bool SpatialHashTable::occupied(Point at) const {
* 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, FoundList &result, Point at, int dy, int dx) {
inline void find_neighbor(const PointEntityMap &table, EntityList &result, Point at, int dy, int dx) {
// don't bother checking for cells out of bounds
if((dx < 0 && at.x <= 0) || (dy < 0 && at.y <= 0)) {
return;
@ -41,8 +41,8 @@ inline void find_neighbor(const PointEntityMap &table, FoundList &result, Point
}
}
std::tuple<bool, FoundList> SpatialHashTable::neighbors(Point cell, bool diag) const {
FoundList result;
std::tuple<bool, EntityList> spatial_map::neighbors(Point cell, bool diag) const {
EntityList result;
// 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