move ecs related code to own folder

This commit is contained in:
2026-05-25 08:46:58 +02:00
parent 8ad7530740
commit 25ff3c56c5
54 changed files with 877 additions and 680 deletions

View File

@@ -6,11 +6,15 @@
#include "BuildingSystem.h"
#include "BuildingType.h"
#include "ConfigLoader.h"
#include "EcsComponents.h"
#include "EntityAdmin.h"
#include "FactionComponent.h"
#include "HealthComponent.h"
#include "HqProxyComponent.h"
#include "Rotation.h"
#include "Ship.h"
#include "ShipIdentityComponent.h"
#include "ShipSystem.h"
#include "StationBodyComponent.h"
#include "WeaponComponent.h"
#include "Simulation.h"
#include "Tick.h"
#include "WaveSystem.h"
@@ -112,8 +116,8 @@ TEST_CASE("WaveSystem: Simulation pre-places HQ + 2 player + 2 enemy stations",
// Stations are ECS entities.
int playerCount = 0;
int enemyCount = 0;
sim.admin().forEach<StationBody, Faction>(
[&](entt::entity /*e*/, const StationBody& /*sb*/, const Faction& f)
sim.admin().forEach<StationBodyComponent, FactionComponent>(
[&](entt::entity /*e*/, const StationBodyComponent& /*sb*/, const FactionComponent& f)
{
if (f.isEnemy) { ++enemyCount; }
else { ++playerCount; }
@@ -132,8 +136,8 @@ TEST_CASE("WaveSystem: HQ has correct initial HP from config", "[wave]")
static_cast<float>(sim.config().stations.hq.hpFormula.evaluate(0.0));
bool found = false;
float actualHp = 0.0f;
sim.admin().forEach<HqProxy, Health>(
[&](entt::entity /*e*/, const HqProxy& /*hq*/, const Health& h)
sim.admin().forEach<HqProxyComponent, HealthComponent>(
[&](entt::entity /*e*/, const HqProxyComponent& /*hq*/, const HealthComponent& h)
{
found = true;
actualHp = h.hp;
@@ -165,9 +169,9 @@ TEST_CASE("WaveSystem: player stations have weapon set", "[wave]")
const Simulation sim(loadConfig(), 42);
int armedPlayerStations = 0;
sim.admin().forEach<StationBody, Faction, Weapon>(
[&](entt::entity /*e*/, const StationBody& /*sb*/, const Faction& f,
const Weapon& w)
sim.admin().forEach<StationBodyComponent, FactionComponent, WeaponComponent>(
[&](entt::entity /*e*/, const StationBodyComponent& /*sb*/, const FactionComponent& f,
const WeaponComponent& w)
{
if (!f.isEnemy)
{
@@ -185,9 +189,9 @@ TEST_CASE("WaveSystem: enemy stations have weapon set", "[wave]")
const Simulation sim(loadConfig(), 42);
int armedEnemyStations = 0;
sim.admin().forEach<StationBody, Faction, Weapon>(
[&](entt::entity /*e*/, const StationBody& /*sb*/, const Faction& f,
const Weapon& w)
sim.admin().forEach<StationBodyComponent, FactionComponent, WeaponComponent>(
[&](entt::entity /*e*/, const StationBodyComponent& /*sb*/, const FactionComponent& f,
const WeaponComponent& w)
{
if (f.isEnemy)
{
@@ -217,8 +221,8 @@ TEST_CASE("WaveSystem: enemy ships spawn after the initial gap elapses", "[wave]
}
bool foundEnemyShip = false;
sim.admin().forEach<ShipIdentity, Faction>(
[&](entt::entity /*e*/, const ShipIdentity& /*si*/, const Faction& f)
sim.admin().forEach<ShipIdentityComponent, FactionComponent>(
[&](entt::entity /*e*/, const ShipIdentityComponent& /*si*/, const FactionComponent& f)
{
if (f.isEnemy) { foundEnemyShip = true; }
});
@@ -236,8 +240,8 @@ TEST_CASE("WaveSystem: only eligible ships (cost > 0) appear in waves", "[wave]"
sim.tick();
}
sim.admin().forEach<ShipIdentity, Faction>(
[&](entt::entity /*e*/, const ShipIdentity& si, const Faction& f)
sim.admin().forEach<ShipIdentityComponent, FactionComponent>(
[&](entt::entity /*e*/, const ShipIdentityComponent& si, const FactionComponent& f)
{
if (!f.isEnemy) { return; }
// salvage_ship and repair_ship have cost_formula = "0" and must not spawn.
@@ -255,8 +259,8 @@ TEST_CASE("WaveSystem: destroying both enemy stations triggers a push", "[wave]"
Simulation sim(loadConfig(), 42);
// Damage both enemy stations to 0.
sim.admin().forEach<StationBody, Faction, Health>(
[](entt::entity /*e*/, const StationBody& /*sb*/, const Faction& f, Health& h)
sim.admin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
[](entt::entity /*e*/, const StationBodyComponent& /*sb*/, const FactionComponent& f, HealthComponent& h)
{
if (f.isEnemy) { h.hp = -1.0f; }
});
@@ -265,8 +269,8 @@ TEST_CASE("WaveSystem: destroying both enemy stations triggers a push", "[wave]"
// After push: should have 2 new enemy stations.
int enemyCount = 0;
sim.admin().forEach<StationBody, Faction>(
[&](entt::entity /*e*/, const StationBody& /*sb*/, const Faction& f)
sim.admin().forEach<StationBodyComponent, FactionComponent>(
[&](entt::entity /*e*/, const StationBodyComponent& /*sb*/, const FactionComponent& f)
{
if (f.isEnemy) { ++enemyCount; }
});
@@ -277,8 +281,8 @@ TEST_CASE("WaveSystem: push emits exactly one SchematicDropEvent", "[wave]")
{
Simulation sim(loadConfig(), 42);
sim.admin().forEach<StationBody, Faction, Health>(
[](entt::entity /*e*/, const StationBody& /*sb*/, const Faction& f, Health& h)
sim.admin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
[](entt::entity /*e*/, const StationBodyComponent& /*sb*/, const FactionComponent& f, HealthComponent& h)
{
if (f.isEnemy) { h.hp = -1.0f; }
});
@@ -293,8 +297,8 @@ TEST_CASE("WaveSystem: push schematic drop awards a known ship id", "[wave]")
{
Simulation sim(loadConfig(), 42);
sim.admin().forEach<StationBody, Faction, Health>(
[](entt::entity /*e*/, const StationBody& /*sb*/, const Faction& f, Health& h)
sim.admin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
[](entt::entity /*e*/, const StationBodyComponent& /*sb*/, const FactionComponent& f, HealthComponent& h)
{
if (f.isEnemy) { h.hp = -1.0f; }
});
@@ -322,8 +326,8 @@ TEST_CASE("WaveSystem: push places new enemy stations further right", "[wave]")
// Record the X position of the initial enemy stations.
int initialX = std::numeric_limits<int>::min();
sim.admin().forEach<StationBody, Faction>(
[&](entt::entity /*e*/, const StationBody& sb, const Faction& f)
sim.admin().forEach<StationBodyComponent, FactionComponent>(
[&](entt::entity /*e*/, const StationBodyComponent& sb, const FactionComponent& f)
{
if (f.isEnemy && sb.anchor.x() > initialX)
{
@@ -331,16 +335,16 @@ TEST_CASE("WaveSystem: push places new enemy stations further right", "[wave]")
}
});
sim.admin().forEach<StationBody, Faction, Health>(
[](entt::entity /*e*/, const StationBody& /*sb*/, const Faction& f, Health& h)
sim.admin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
[](entt::entity /*e*/, const StationBodyComponent& /*sb*/, const FactionComponent& f, HealthComponent& h)
{
if (f.isEnemy) { h.hp = -1.0f; }
});
sim.tick();
int newX = std::numeric_limits<int>::min();
sim.admin().forEach<StationBody, Faction>(
[&](entt::entity /*e*/, const StationBody& sb, const Faction& f)
sim.admin().forEach<StationBodyComponent, FactionComponent>(
[&](entt::entity /*e*/, const StationBodyComponent& sb, const FactionComponent& f)
{
if (f.isEnemy && sb.anchor.x() > newX)
{