split MovementSystem to MovementIntentSystem and DynamicBodySystem
This commit is contained in:
@@ -4,6 +4,7 @@ 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}/ItemType.h
|
||||
|
||||
25
src/lib/core/DynamicBodyComponent.h
Normal file
25
src/lib/core/DynamicBodyComponent.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
#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;
|
||||
std::optional<QVector2D> snapTarget; // set when snap-to-target will fire this tick
|
||||
};
|
||||
|
||||
@@ -35,24 +35,9 @@ struct Faction
|
||||
// Ship components (always present on every ship)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct Velocity
|
||||
{
|
||||
QVector2D value;
|
||||
};
|
||||
|
||||
struct Facing
|
||||
{
|
||||
float radians;
|
||||
float rotationSpeed;
|
||||
};
|
||||
|
||||
struct ShipDynamics
|
||||
{
|
||||
float maxSpeedPerTick;
|
||||
float mainAccelerationPerTick;
|
||||
float maneuveringAccelerationPerTick;
|
||||
float angularAccelerationPerTick;
|
||||
float maxRotationSpeedPerTick;
|
||||
};
|
||||
|
||||
struct SensorRange
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "EntityAdmin.h"
|
||||
|
||||
#include "DynamicBodyComponent.h"
|
||||
#include "EcsComponents.h"
|
||||
#include "MovementIntent.h"
|
||||
|
||||
@@ -33,11 +34,19 @@ entt::entity EntityAdmin::spawnShip(QVector2D position, float hp, float maxHp,
|
||||
add<Position>(entity, Position{position});
|
||||
add<Health>(entity, Health{hp, maxHp});
|
||||
add<Faction>(entity, Faction{isEnemy});
|
||||
add<Velocity>(entity, Velocity{QVector2D(0.0f, 0.0f)});
|
||||
add<Facing>(entity, Facing{0.0f, 0.0f});
|
||||
add<ShipDynamics>(entity, ShipDynamics{
|
||||
maxSpeedPerTick, mainAccelPerTick, maneuveringAccelPerTick,
|
||||
angularAccelPerTick, maxRotationSpeedPerTick});
|
||||
add<Facing>(entity, Facing{0.0f});
|
||||
add<DynamicBodyComponent>(entity, DynamicBodyComponent{
|
||||
maxSpeedPerTick,
|
||||
mainAccelPerTick,
|
||||
maneuveringAccelPerTick,
|
||||
angularAccelPerTick,
|
||||
maxRotationSpeedPerTick,
|
||||
QVector2D(0.0f, 0.0f), // velocity
|
||||
0.0f, // angularVelocity
|
||||
QVector2D(0.0f, 0.0f), // linearAcceleration
|
||||
0.0f, // angularAcceleration
|
||||
std::nullopt // snapTarget
|
||||
});
|
||||
add<SensorRange>(entity, SensorRange{sensorRange});
|
||||
add<ShipIdentity>(entity, ShipIdentity{level, schematicId});
|
||||
add<MovementIntent>(entity, MovementIntent{0, QVector2D(0.0f, 0.0f)});
|
||||
|
||||
Reference in New Issue
Block a user