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.
This commit is contained in:
parent
e51fb8627c
commit
569d04725a
2 changed files with 6 additions and 1 deletions
|
@ -7,8 +7,10 @@ using DinkyECS::Entity;
|
||||||
|
|
||||||
void SpatialMap::insert(Point pos, Entity ent, bool has_collision) {
|
void SpatialMap::insert(Point pos, Entity ent, bool has_collision) {
|
||||||
if(has_collision) {
|
if(has_collision) {
|
||||||
|
dbc::check(!yes_collision.contains(pos), "YES_collision already has entity");
|
||||||
yes_collision.insert_or_assign(pos, ent);
|
yes_collision.insert_or_assign(pos, ent);
|
||||||
} else {
|
} else {
|
||||||
|
dbc::check(!no_collision.contains(pos), "no_collision already has entity");
|
||||||
no_collision.insert_or_assign(pos, ent);
|
no_collision.insert_or_assign(pos, ent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,12 +20,14 @@ bool SpatialMap::remove(Point pos) {
|
||||||
yes_collision.erase(pos);
|
yes_collision.erase(pos);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
dbc::check(no_collision.contains(pos), "remove of entity that's not in no_collision");
|
||||||
no_collision.erase(pos);
|
no_collision.erase(pos);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpatialMap::move(Point from, Point to, Entity ent) {
|
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);
|
bool has_collision = remove(from);
|
||||||
insert(to, ent, has_collision);
|
insert(to, ent, has_collision);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();) {
|
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)};
|
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;
|
pos_out = test;
|
||||||
return true;
|
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");
|
dbc::check(placed, "WorldBuild.find_open_spot also failed to position player");
|
||||||
|
|
||||||
world.set<Position>(player.entity, player_pos);
|
world.set<Position>(player.entity, player_pos);
|
||||||
|
$collision.insert(player_pos.location, player.entity, true);
|
||||||
} else {
|
} else {
|
||||||
auto player_data = config.enemies["PLAYER_TILE"];
|
auto player_data = config.enemies["PLAYER_TILE"];
|
||||||
auto player_ent = configure_entity_in_room(world, player_data, 0);
|
auto player_ent = configure_entity_in_room(world, player_data, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue