move FactoryState ownership out of BuildingSystem to Simulation
Simulation (and ArenaSimulation in the balancing tool) now owns the factory's world data; BuildingSystem holds a reference to it. This is what lets the systems that operate on the data be handed the same state — phase 3's construction and deconstruction systems, and later the ecs/system/ classes that today take a BuildingSystem& only to query it. reset() clears the state alongside m_admin and m_beltSystem, matching how the subsystems were already rebuilt from scratch. Falls short of the tick-argument form I sketched: BuildingSystem still reaches the data through a member reference rather than a parameter. Making it truly stateless means the const query surface has to find the data some other way, and that surface is large — findBuilding alone has 64 call sites, with findSite, getAllBuildings, getAllSites, isTileOccupied and the rest behind it. Doing that needs a queries facade behind Simulation::getBuildings() so the callers do not all move, which is its own decision rather than a side effect of this one. The constructor gains a parameter, so the four owners and the three test fixtures that build a BuildingSystem directly are updated; the 33 files that only use one are untouched. Verified with a golden-checksum capture before and after — all four sample ticks identical. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YHcUerKAZKWNvSKJxYKbnG
This commit is contained in:
@@ -47,6 +47,7 @@ class BuildingSystem
|
||||
{
|
||||
public:
|
||||
BuildingSystem(const GameConfig& config,
|
||||
FactoryState& state,
|
||||
BeltSystem& belts,
|
||||
std::function<BuildingId()> allocateBuildingId,
|
||||
std::function<void(int)> addBuildingBlocks,
|
||||
@@ -285,6 +286,11 @@ private:
|
||||
QPoint anchor) const;
|
||||
|
||||
const GameConfig& m_config;
|
||||
|
||||
// The factory's world data — buildings, queued work, tile ownership. Owned by
|
||||
// Simulation, not by this system (see FactoryState.h).
|
||||
FactoryState& m_state;
|
||||
|
||||
BeltSystem& m_belts;
|
||||
std::function<BuildingId()> m_allocateBuildingId;
|
||||
std::function<void(int)> m_addBuildingBlocks;
|
||||
@@ -293,9 +299,4 @@ private:
|
||||
std::function<bool(const std::string&)> m_isItemUnlocked;
|
||||
std::mt19937& m_rng;
|
||||
int m_asteroidWidth_tiles;
|
||||
|
||||
// The factory's world data — buildings, queued work, tile ownership. Held here
|
||||
// for now; the intent is for Simulation to own it and pass it into the tick
|
||||
// methods, leaving this system stateless over it (see FactoryState.h).
|
||||
FactoryState m_state;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user