From 6f8db05c02f941ce75da34e3c50c987d03c23e54 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 13 Feb 2023 00:48:43 +0100 Subject: Extracted scenario setup from BaseBattle constructor --- sim/src/BaseBattle.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'sim/src/BaseBattle.cpp') diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index fa91134..0c23065 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -25,20 +25,30 @@ namespace sim { +static void setup_scenario(entt::registry& registry, const campaign::Scenario& scenario); + + BaseBattle::BaseBattle(const campaign::Scenario& scenario) : _registry {} { + setup_scenario(_registry, scenario); + manager.extend(_registry); +} + + +void +setup_scenario(entt::registry& registry, const campaign::Scenario& scenario) +{ RandomSpawner spawner {scenario.last_team(), scenario.radius, 0.1}; - Builder build {_registry, spawner}; + Builder build {registry, spawner}; for (const auto& ship : scenario.ships) { const auto entity = build(ship.loadout.type, ship.team); - _registry.emplace(entity, ship.identifier); - auto& state = _registry.get(entity); + registry.emplace(entity, ship.identifier); + auto& state = registry.get(entity); for (const auto& turret_type : ship.loadout.turrets) { build(turret_type, entity); state.keep_at_range = std::min(state.keep_at_range, turret_type.optimal_range); } - manager.add(ship.team, entity); // registry supports on construction events } } -- cgit v1.1