move ecs related code to own folder
This commit is contained in:
@@ -4,14 +4,12 @@ SET(HDRS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Rotation.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildingType.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EntityAdmin.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/DynamicBodyComponent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EcsComponents.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Blueprint.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildingId.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/FireEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ItemType.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Item.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Port.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/MovementIntent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/FireEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SchematicDropEvent.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QVector2D>
|
||||
|
||||
struct DynamicBodyComponent
|
||||
{
|
||||
// --- dynamics parameters (formerly ShipDynamics) ---
|
||||
float maxSpeedPerTick;
|
||||
float mainAccelerationPerTick;
|
||||
float maneuveringAccelerationPerTick;
|
||||
float angularAccelerationPerTick;
|
||||
float maxRotationSpeedPerTick;
|
||||
|
||||
// --- integrated state ---
|
||||
QVector2D velocity;
|
||||
float angularVelocity;
|
||||
|
||||
// --- written each tick by MovementIntentSystem, consumed by DynamicBodySystem ---
|
||||
QVector2D linearAcceleration;
|
||||
float angularAcceleration;
|
||||
};
|
||||
@@ -1,91 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <QPoint>
|
||||
#include <QSize>
|
||||
#include <QVector2D>
|
||||
|
||||
#include "Tick.h"
|
||||
|
||||
#include "entt/entity/entity.hpp"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Shared components (used by ships, stations, scrap, HQ proxy)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct Position
|
||||
{
|
||||
QVector2D value;
|
||||
};
|
||||
|
||||
struct Health
|
||||
{
|
||||
float hp;
|
||||
float maxHp;
|
||||
};
|
||||
|
||||
struct Faction
|
||||
{
|
||||
bool isEnemy;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Ship components (always present on every ship)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct Facing
|
||||
{
|
||||
float radians;
|
||||
};
|
||||
|
||||
struct SensorRange
|
||||
{
|
||||
float value;
|
||||
};
|
||||
|
||||
struct ShipIdentity
|
||||
{
|
||||
int level;
|
||||
std::string schematicId;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Ship optional components (hardware + behavior, in Ship.h)
|
||||
// ---------------------------------------------------------------------------
|
||||
// Weapon, SalvageCargo, RepairTool, ThreatResponseBehavior, SalvageBehavior,
|
||||
// RepairBehavior, HomeReturnBehavior, RallyBehavior remain defined in Ship.h.
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Station components
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct StationBody
|
||||
{
|
||||
QPoint anchor;
|
||||
QSize footprint;
|
||||
std::vector<QPoint> bodyCells;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Scrap components
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct ScrapData
|
||||
{
|
||||
int amount;
|
||||
};
|
||||
|
||||
struct DespawnAt
|
||||
{
|
||||
Tick tick;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// HQ proxy (empty tag)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct HqProxy { char unused = 0; };
|
||||
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
#include "EntityAdmin.h"
|
||||
|
||||
#include "DespawnAtComponent.h"
|
||||
#include "DynamicBodyComponent.h"
|
||||
#include "EcsComponents.h"
|
||||
#include "MovementIntent.h"
|
||||
#include "FacingComponent.h"
|
||||
#include "FactionComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "HqProxyComponent.h"
|
||||
#include "MovementIntentComponent.h"
|
||||
#include "PositionComponent.h"
|
||||
#include "ScrapDataComponent.h"
|
||||
#include "SensorRangeComponent.h"
|
||||
#include "ShipIdentityComponent.h"
|
||||
#include "StationBodyComponent.h"
|
||||
|
||||
entt::entity EntityAdmin::createEntity()
|
||||
{
|
||||
@@ -31,10 +40,10 @@ entt::entity EntityAdmin::spawnShip(QVector2D position, float hp, float maxHp,
|
||||
int level, const std::string& schematicId, bool isEnemy)
|
||||
{
|
||||
entt::entity entity = createEntity();
|
||||
add<Position>(entity, Position{position});
|
||||
add<Health>(entity, Health{hp, maxHp});
|
||||
add<Faction>(entity, Faction{isEnemy});
|
||||
add<Facing>(entity, Facing{0.0f});
|
||||
add<PositionComponent>(entity, PositionComponent{position});
|
||||
add<HealthComponent>(entity, HealthComponent{hp, maxHp});
|
||||
add<FactionComponent>(entity, FactionComponent{isEnemy});
|
||||
add<FacingComponent>(entity, FacingComponent{0.0f});
|
||||
add<DynamicBodyComponent>(entity, DynamicBodyComponent{
|
||||
maxSpeedPerTick,
|
||||
mainAccelPerTick,
|
||||
@@ -46,9 +55,9 @@ entt::entity EntityAdmin::spawnShip(QVector2D position, float hp, float maxHp,
|
||||
QVector2D(0.0f, 0.0f), // linearAcceleration
|
||||
0.0f // angularAcceleration
|
||||
});
|
||||
add<SensorRange>(entity, SensorRange{sensorRange});
|
||||
add<ShipIdentity>(entity, ShipIdentity{level, schematicId});
|
||||
add<MovementIntent>(entity, MovementIntent{0, QVector2D(0.0f, 0.0f)});
|
||||
add<SensorRangeComponent>(entity, SensorRangeComponent{sensorRange});
|
||||
add<ShipIdentityComponent>(entity, ShipIdentityComponent{level, schematicId});
|
||||
add<MovementIntentComponent>(entity, MovementIntentComponent{0, QVector2D(0.0f, 0.0f)});
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -59,28 +68,28 @@ entt::entity EntityAdmin::spawnStation(QPoint anchor, QSize footprint,
|
||||
entt::entity entity = createEntity();
|
||||
QVector2D center(anchor.x() + footprint.width() / 2.0f,
|
||||
anchor.y() + footprint.height() / 2.0f);
|
||||
add<Position>(entity, Position{center});
|
||||
add<Health>(entity, Health{hp, maxHp});
|
||||
add<Faction>(entity, Faction{isEnemy});
|
||||
add<StationBody>(entity, StationBody{anchor, footprint, bodyCells});
|
||||
add<PositionComponent>(entity, PositionComponent{center});
|
||||
add<HealthComponent>(entity, HealthComponent{hp, maxHp});
|
||||
add<FactionComponent>(entity, FactionComponent{isEnemy});
|
||||
add<StationBodyComponent>(entity, StationBodyComponent{anchor, footprint, bodyCells});
|
||||
return entity;
|
||||
}
|
||||
|
||||
entt::entity EntityAdmin::spawnScrap(QVector2D position, int amount, Tick despawnAt)
|
||||
{
|
||||
entt::entity entity = createEntity();
|
||||
add<Position>(entity, Position{position});
|
||||
add<ScrapData>(entity, ScrapData{amount});
|
||||
add<DespawnAt>(entity, DespawnAt{despawnAt});
|
||||
add<PositionComponent>(entity, PositionComponent{position});
|
||||
add<ScrapDataComponent>(entity, ScrapDataComponent{amount});
|
||||
add<DespawnAtComponent>(entity, DespawnAtComponent{despawnAt});
|
||||
return entity;
|
||||
}
|
||||
|
||||
entt::entity EntityAdmin::spawnHqProxy(QVector2D position, float hp, float maxHp)
|
||||
{
|
||||
entt::entity entity = createEntity();
|
||||
add<Position>(entity, Position{position});
|
||||
add<Health>(entity, Health{hp, maxHp});
|
||||
add<Faction>(entity, Faction{false});
|
||||
add<HqProxy>(entity);
|
||||
add<PositionComponent>(entity, PositionComponent{position});
|
||||
add<HealthComponent>(entity, HealthComponent{hp, maxHp});
|
||||
add<FactionComponent>(entity, FactionComponent{false});
|
||||
add<HqProxyComponent>(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QVector2D>
|
||||
|
||||
// A ship-behavior system writes this each tick before movement runs; the
|
||||
// highest-priority write wins. Priority order is fixed globally — see
|
||||
// architecture.md "Movement Arbitration".
|
||||
struct MovementIntent
|
||||
{
|
||||
int priority;
|
||||
QVector2D target;
|
||||
};
|
||||
Reference in New Issue
Block a user