add event system and use it to propagate to print traces

This commit is contained in:
2026-06-05 17:18:17 +02:00
parent abc261c03a
commit 9677133c54
14 changed files with 369 additions and 10 deletions

View File

@@ -7,6 +7,7 @@
#include "CombatSystem.h"
#include "DynamicBodySystem.h"
#include "FactionComponent.h"
#include "EventManager.h"
#include "HealthComponent.h"
#include "ModuleOwnerComponent.h"
#include "MovementIntentSystem.h"
@@ -71,9 +72,13 @@ Simulation::Simulation(GameConfig config, unsigned int seed)
}
placeInitialStructures();
registerForEvents();
}
Simulation::~Simulation() = default;
Simulation::~Simulation()
{
unregisterForEvents();
}
const GameConfig& Simulation::config() const
{
@@ -88,6 +93,7 @@ void Simulation::reset(GameConfig newConfig, unsigned int seed)
void Simulation::reset(unsigned int seed)
{
EventManager::destroyInstance();
m_rng.seed(seed);
m_currentTick = 0;
m_nextDepartureTick = secondsToTicks(m_config.world.departureIntervalSeconds);
@@ -147,6 +153,8 @@ void Simulation::reset(unsigned int seed)
void Simulation::tick()
{
EventManager::getInstance()->processEvents();
// Step 1: wave scheduler
m_waveSystem->tickWaveScheduler(m_currentTick, *m_shipSystem,
m_config.world.heightTiles);
@@ -199,8 +207,6 @@ void Simulation::tick()
m_scrapSystem->tickDespawn(m_currentTick);
++m_currentTick;
PRINT_TRACES();
}
// ---------------------------------------------------------------------------
@@ -642,6 +648,11 @@ const EntityAdmin& Simulation::admin() const
return m_admin;
}
void Simulation::handleEvent(std::shared_ptr<const TracePrintRequestedEvent> event)
{
PRINT_TRACES();
}
BuildingId Simulation::allocateBuildingId()
{
return m_nextBuildingId++;

View File

@@ -10,15 +10,16 @@
#include "BeltSystem.h"
#include "EntityAdmin.h"
#include "entt/entity/entity.hpp"
#include "SchematicDropEvent.h"
#include "BuildingType.h"
#include "BuildingId.h"
#include "EventHandler.h"
#include "FireEvent.h"
#include "GameConfig.h"
#include "Rotation.h"
#include "Tick.h"
#include "TracePrintRequestedEvent.h"
class AiSystem;
class BuildingSystem;
@@ -29,7 +30,7 @@ class ShipSystem;
class ScrapSystem;
class WaveSystem;
class Simulation
class Simulation: public CombinedEventHandler<TracePrintRequestedEvent>
{
public:
explicit Simulation(GameConfig config, unsigned int seed = 0);
@@ -83,6 +84,8 @@ public:
const EntityAdmin& admin() const;
private:
void handleEvent(std::shared_ptr<const TracePrintRequestedEvent> event) override;
BuildingId allocateBuildingId(); // Strictly increasing; never returns kInvalidBuildingId.
// Populate HQ, player defence stations, and the first enemy station set.