Mostly working spatical map with 2 level collision/space structure. Not the best implementation but this is the idea.

This commit is contained in:
Zed A. Shaw 2025-07-29 03:12:44 -04:00
parent fd53f92fe6
commit d6326c9e41
7 changed files with 60 additions and 31 deletions

View file

@ -23,8 +23,8 @@ TEST_CASE("confirm basic collision operations", "[collision]") {
Entity enemy = world.entity();
SpatialMap collider;
collider.insert({11,11}, player);
collider.insert({21,21}, enemy);
collider.insert({11,11}, player, true);
collider.insert({21,21}, enemy, true);
{ // not found
auto [found, nearby] = collider.neighbors({1,1});
@ -43,7 +43,7 @@ TEST_CASE("confirm basic collision operations", "[collision]") {
REQUIRE(nearby.empty());
}
collider.insert({11,11}, player); // setup for the move test
collider.insert({11,11}, player, true); // setup for the move test
{ // moving, not found
collider.move({11,11}, {12, 12}, player);
auto [found, nearby] = collider.neighbors({10,10}, true);
@ -72,10 +72,10 @@ TEST_CASE("confirm multiple entities moving", "[collision]") {
Entity e3 = world.entity();
SpatialMap collider;
collider.insert({11,11}, player);
collider.insert({10,10}, e2);
collider.insert({11,10}, e3);
collider.insert({21,21}, e1);
collider.insert({11,11}, player, true);
collider.insert({10,10}, e2, true);
collider.insert({11,10}, e3, true);
collider.insert({21,21}, e1, true);
EntityList nearby = require_found(collider, {11,11}, false, 1);
REQUIRE(nearby[0] == e3);
@ -95,10 +95,10 @@ TEST_CASE("test edge cases that might crash", "[collision]") {
Entity enemy = world.entity();
SpatialMap collider;
collider.insert({0,0}, player);
collider.insert({0,0}, player, true);
Point enemy_at = {1, 0};
collider.insert(enemy_at, enemy);
collider.insert(enemy_at, enemy, true);
EntityList nearby = require_found(collider, {0,0}, true, 1);
@ -118,10 +118,10 @@ TEST_CASE("check all diagonal works", "[collision]") {
SpatialMap collider;
Point player_at = {1,1};
collider.insert(player_at, player);
collider.insert(player_at, player, true);
Point enemy_at = {1, 0};
collider.insert(enemy_at, enemy);
collider.insert(enemy_at, enemy, true);
for(size_t x = 0; x <= 2; x++) {
for(size_t y = 0; y <= 2; y++) {
@ -150,7 +150,7 @@ TEST_CASE("confirm can iterate through all", "[spatialmap-sort]") {
size_t y = Random::uniform<size_t>(0, 251);
Entity ent = world.entity();
collider.insert({x,y}, ent);
collider.insert({x,y}, ent, true);
}
auto sprite_distance = collider.distance_sorted(player, 1000);