gather the factory's world data into FactoryState
BuildingSystem is the one system in the codebase that owns the world data it operates on. The ecs/system/ classes already do the opposite — AiSystem and SalvagerSystem hold config and their own scratch, and take EntityAdmin and the other systems as tick arguments — so this is bringing the outlier in line, not inventing a pattern. Phase 1 of that: the buildings vector, both work queues and the tile grid move into a FactoryState struct, still owned by BuildingSystem. Every method reaches through m_state. The public API is untouched, so none of the 33 files that reference BuildingSystem needed a change. DeconstructionEntry moves out of BuildingSystem's private section into FactoryState.h, since the queue that holds it lives there now. m_asteroidWidth_tiles stays on the system: it is not checksummed and is a cached placement bound derived from config and the expansion count, not factory data. The intent is for Simulation to own FactoryState and pass it into the tick methods, leaving the systems stateless over it. FactoryState.h notes explicitly that this is a data/behaviour split and not a step toward putting buildings in the entity model, which architecture.md rules out. 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:
45
src/lib/sim/FactoryState.h
Normal file
45
src/lib/sim/FactoryState.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
#include "Building.h"
|
||||
#include "BuildingGrid.h"
|
||||
#include "BuildingId.h"
|
||||
#include "ItemType.h"
|
||||
#include "Tick.h"
|
||||
|
||||
// One pending demolition of a fully-built building (REQ-BLD-DECON-QUEUE).
|
||||
// completesAt == 0 means "queued but its timer has not started yet"
|
||||
// (mirrors ConstructionSite). For a Splitter, the filters it had are captured
|
||||
// here so cancelDeconstruction can restore them on re-registration.
|
||||
struct DeconstructionEntry
|
||||
{
|
||||
BuildingId id = kInvalidBuildingId;
|
||||
Tick completesAt = 0;
|
||||
std::vector<ItemType> splitterFilterA;
|
||||
std::vector<ItemType> splitterFilterB;
|
||||
};
|
||||
|
||||
// The factory's world data: every building, the work queued on them, and the
|
||||
// tile ownership index. This is the buildings-side counterpart to EntityAdmin —
|
||||
// data with no behaviour of its own beyond what BuildingGrid encapsulates.
|
||||
//
|
||||
// Buildings deliberately stay a plain vector rather than becoming EnTT entities
|
||||
// (see docs/architecture.md). Separating this data from the systems that operate
|
||||
// on it is not a step toward putting them in the entity model; it is the same
|
||||
// data/behaviour split the ecs/system/ classes already follow, where world data
|
||||
// arrives as a tick argument instead of being owned by the system.
|
||||
//
|
||||
// Owned by BuildingSystem for now. The intent is to hand ownership to Simulation
|
||||
// and pass this into the tick methods, so the systems become stateless over it.
|
||||
struct FactoryState
|
||||
{
|
||||
std::vector<Building> buildings;
|
||||
std::deque<ConstructionSite> constructionQueue;
|
||||
std::deque<DeconstructionEntry> deconstructionQueue;
|
||||
|
||||
// The authority on which building owns which tile; every placement and removal
|
||||
// path claims and releases its body cells here.
|
||||
BuildingGrid grid;
|
||||
};
|
||||
Reference in New Issue
Block a user