make construction its own system

ConstructionSystem takes over the construction queue: it runs the front site's
timer and, when it elapses, builds the Building itself — ports, buffers, belt
registration, and starting the next queued site. Simulation::tick calls it
directly, in the same position tickConstruction held.

No handoff. The earlier sketch had it return the completed site for BuildingSystem
to materialise, which put an intermediate value in Simulation and made the two
calls correct only when adjacent and ordered. Once the queries and the buffer
helpers became free functions there was nothing left on BuildingSystem that
materialisation needed, so the system does the whole job and the invariant
disappears rather than being documented.

Holds only the config; the world arrives per tick, like the systems in
lib/ecs/system.

Verified with a golden-checksum capture before and after — all four sample ticks
identical, which is the check that matters here since this moves a call in the
tick order.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YHcUerKAZKWNvSKJxYKbnG
This commit is contained in:
2026-08-05 06:49:20 +02:00
parent 009f8c6d14
commit 56b7248ac7
9 changed files with 196 additions and 148 deletions

View File

@@ -15,6 +15,7 @@
#include "BeltSystem.h"
#include "Building.h"
#include "BuildingSystem.h"
#include "ConstructionSystem.h"
#include "FactoryState.h"
#include "BuildingType.h"
#include "ConfigLoader.h"
@@ -63,6 +64,7 @@ struct Fixture
std::mt19937 rng;
EntityAdmin admin;
BuildingSystem buildings;
ConstructionSystem construction;
ShipSystem ships;
AiSystem ai;
SalvagerSystem salvager;
@@ -85,6 +87,7 @@ struct Fixture
[](const std::string&, QVector2D, const std::optional<ShipLayoutConfig>&) {},
[](const std::string&) -> bool { return true; },
rng)
, construction(cfg)
, ships(cfg, admin)
, ai(cfg)
, salvager(admin)
@@ -957,7 +960,7 @@ TEST_CASE("BehaviorSystem: full-cargo salvage ship moves toward SalvageBay", "[b
Tick t = 0;
for (int i = 0; i < 500; ++i)
{
f.buildings.tickConstruction(f.state, t++);
f.construction.tick(f.state, f.belts, t++);
if (findBuilding(f.state, bayId) != nullptr)
{
break;
@@ -992,7 +995,7 @@ TEST_CASE("SalvagerSystem: full-cargo ship at its SalvageBay hands over cargo",
Tick t = 0;
for (int i = 0; i < 500; ++i)
{
f.buildings.tickConstruction(f.state, t++);
f.construction.tick(f.state, f.belts, t++);
if (findBuilding(f.state, bayId) != nullptr) { break; }
}
const Building* bay = findBuilding(f.state, bayId);