From 569d04725a54ab8d45088b04eb7232fee13d63f3 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 31 Jul 2025 00:03:13 -0400 Subject: [PATCH] This is the cause of the bug where going to the next level caused things to disappear. What happened is that on next level this code was adding the player but _not_ adding them to collision. Then when the player moved the spatialmap would remove them, see they're technically 'no collision' and then add them back in without collision. --- spatialmap.cpp | 4 ++++ worldbuilder.cpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spatialmap.cpp b/spatialmap.cpp index 2c11aa0..ab6fff9 100644 --- a/spatialmap.cpp +++ b/spatialmap.cpp @@ -7,8 +7,10 @@ using DinkyECS::Entity; void SpatialMap::insert(Point pos, Entity ent, bool has_collision) { if(has_collision) { + dbc::check(!yes_collision.contains(pos), "YES_collision already has entity"); yes_collision.insert_or_assign(pos, ent); } else { + dbc::check(!no_collision.contains(pos), "no_collision already has entity"); no_collision.insert_or_assign(pos, ent); } } @@ -18,12 +20,14 @@ bool SpatialMap::remove(Point pos) { yes_collision.erase(pos); return true; } else { + dbc::check(no_collision.contains(pos), "remove of entity that's not in no_collision"); no_collision.erase(pos); return false; } } void SpatialMap::move(Point from, Point to, Entity ent) { + dbc::check(!occupied(to), "attempt to move to point with an existing entity"); bool has_collision = remove(from); insert(to, ent, has_collision); } diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 37f552e..a800f5f 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -69,7 +69,7 @@ bool WorldBuilder::find_open_spot(Point& pos_out) { for(matrix::rando_box it{$map.walls(), pos_out.x, pos_out.y, i}; it.next();) { Point test{size_t(it.x), size_t(it.y)}; - if($map.can_move(test) && !$collision.occupied(test)) { + if($map.can_move(test) && !$collision.something_there(test)) { pos_out = test; return true; } @@ -210,6 +210,7 @@ void WorldBuilder::place_entities(DinkyECS::World &world) { dbc::check(placed, "WorldBuild.find_open_spot also failed to position player"); world.set(player.entity, player_pos); + $collision.insert(player_pos.location, player.entity, true); } else { auto player_data = config.enemies["PLAYER_TILE"]; auto player_ent = configure_entity_in_room(world, player_data, 0);