Had to refactor the GameDB to use a list of levels instead of a vector of levels. If you get a _reference_ to an element of a vector, and then resize the vector, you'll get a crash if the realoc moves the data buffer. Using a list is actually what we want.

This commit is contained in:
Zed A. Shaw 2025-12-16 11:40:29 -05:00
parent bf8ce7e16b
commit 0456c73e4f
6 changed files with 53 additions and 37 deletions

View file

@ -29,26 +29,31 @@ namespace boss {
}
shared_ptr<boss::Fight> System::create_bossfight() {
auto& level = GameDB::current_level();
auto prev_world = GameDB::current_world();
dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null.");
auto world = GameDB::clone_load_world(prev_world);
auto& config = prev_world->get_the<GameConfig>();
// need to copy so we can clone it and keep things working, even
// if we don't use things like map and lighting
auto level = GameDB::current_level();
dbc::check(level.world != nullptr, "Starter world for boss fights can't be null.");
level.world = GameDB::clone_load_world(level.world);
auto& config = level.world->get_the<GameConfig>();
auto boss_names = config.bosses.keys();
auto& level_name = boss_names[level.index % boss_names.size()];
auto& boss_data = config.bosses[level_name];
auto boss_id = world->entity();
components::configure_entity(*world, boss_id, boss_data["components"]);
auto boss_id = level.world->entity();
components::configure_entity(*level.world, boss_id, boss_data["components"]);
initialize_actor_ai(*world, boss_id);
dbc::check(world->has<ai::EntityAI>(boss_id), "boss doesn't have an AI");
initialize_actor_ai(*level.world, boss_id);
dbc::check(level.world->has<ai::EntityAI>(boss_id), "boss doesn't have an AI");
initialize_actor_ai(*world, level.player);
dbc::check(world->has<ai::EntityAI>(level.player), "player/host doesn't have an AI");
initialize_actor_ai(*level.world, level.player);
dbc::check(level.world->has<ai::EntityAI>(level.player), "player/host doesn't have an AI");
return make_shared<boss::Fight>(world, boss_id, level.player);
GameDB::register_level(level);
return make_shared<boss::Fight>(level.world, boss_id, level.player);
}
BattleEngine System::create_battle(std::shared_ptr<DinkyECS::World> world, DinkyECS::Entity boss_id) {