switch to ECS architecture
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
#include "EntityAdmin.h"
|
||||
|
||||
#include "EcsComponents.h"
|
||||
#include "MovementIntent.h"
|
||||
|
||||
entt::entity EntityAdmin::createEntity()
|
||||
{
|
||||
return m_registry.create();
|
||||
}
|
||||
|
||||
bool EntityAdmin::isValid(entt::entity entity)
|
||||
bool EntityAdmin::isValid(entt::entity entity) const
|
||||
{
|
||||
return m_registry.valid(entity);
|
||||
}
|
||||
@@ -19,3 +22,57 @@ void EntityAdmin::clear()
|
||||
{
|
||||
m_registry.clear();
|
||||
}
|
||||
|
||||
entt::entity EntityAdmin::spawnShip(QVector2D position, float hp, float maxHp,
|
||||
float maxSpeedPerTick, float mainAccelPerTick,
|
||||
float maneuveringAccelPerTick, float angularAccelPerTick,
|
||||
float maxRotationSpeedPerTick, float sensorRange,
|
||||
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<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<SensorRange>(entity, SensorRange{sensorRange});
|
||||
add<ShipIdentity>(entity, ShipIdentity{level, schematicId});
|
||||
add<MovementIntent>(entity, MovementIntent{0, QVector2D(0.0f, 0.0f)});
|
||||
return entity;
|
||||
}
|
||||
|
||||
entt::entity EntityAdmin::spawnStation(QPoint anchor, QSize footprint,
|
||||
const std::vector<QPoint>& bodyCells,
|
||||
float hp, float maxHp, bool isEnemy)
|
||||
{
|
||||
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});
|
||||
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});
|
||||
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);
|
||||
return entity;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user