move ecs related code to own folder
This commit is contained in:
@@ -10,16 +10,20 @@
|
||||
#include "BuildingSystem.h"
|
||||
#include "BuildingType.h"
|
||||
#include "CombatSystem.h"
|
||||
#include "EcsComponents.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "DynamicBodySystem.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "FactionComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "MovementIntentSystem.h"
|
||||
#include "PositionComponent.h"
|
||||
#include "ScrapSystem.h"
|
||||
#include "Ship.h"
|
||||
#include "ShipIdentityComponent.h"
|
||||
#include "ShipSystem.h"
|
||||
#include "ShipsConfig.h"
|
||||
#include "StationBodyComponent.h"
|
||||
#include "StationsConfig.h"
|
||||
#include "SurfaceMask.h"
|
||||
#include "WeaponComponent.h"
|
||||
|
||||
ArenaSimulation::ArenaSimulation(const GameConfig& gameConfig,
|
||||
ArenaConfig arenaConfig,
|
||||
@@ -87,8 +91,6 @@ void ArenaSimulation::placeStructures()
|
||||
{
|
||||
absCells.push_back(QPoint(anchor.x() + rel.x(), anchor.y() + rel.y()));
|
||||
}
|
||||
const QVector2D center(anchorX + hqParsed.footprint.width() / 2.0f,
|
||||
anchorY + hqParsed.footprint.height() / 2.0f);
|
||||
m_team1HqEntity = m_admin.spawnStation(anchor, hqParsed.footprint, absCells,
|
||||
hp, hp, false);
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
@@ -116,7 +118,7 @@ void ArenaSimulation::placeStructures()
|
||||
auto placeArenaStation = [&](const ArenaStationEntry& entry, bool isEnemy)
|
||||
{
|
||||
float hp = 0.0f;
|
||||
Weapon weapon;
|
||||
WeaponComponent weapon;
|
||||
weapon.cooldownTicks = 0.0f;
|
||||
weapon.currentTarget = std::nullopt;
|
||||
const double lv = static_cast<double>(entry.level);
|
||||
@@ -157,7 +159,7 @@ void ArenaSimulation::placeStructures()
|
||||
}
|
||||
const entt::entity stationEntity = m_admin.spawnStation(
|
||||
anchor, parsed.footprint, absCells, hp, hp, isEnemy);
|
||||
m_admin.addComponent<Weapon>(stationEntity, weapon);
|
||||
m_admin.addComponent<WeaponComponent>(stationEntity, weapon);
|
||||
m_buildingSystem->registerTileOccupancy(absCells, allocateBuildingId());
|
||||
};
|
||||
|
||||
@@ -275,8 +277,9 @@ void ArenaSimulation::tickDeaths()
|
||||
{
|
||||
// Dead ships.
|
||||
std::vector<entt::entity> deadShips;
|
||||
m_admin.forEach<ShipIdentity, Health>(
|
||||
[&deadShips](entt::entity e, const ShipIdentity& /*si*/, const Health& h)
|
||||
m_admin.forEach<ShipIdentityComponent, HealthComponent>(
|
||||
[&deadShips](entt::entity e, const ShipIdentityComponent& /*si*/,
|
||||
const HealthComponent& h)
|
||||
{
|
||||
if (h.hp <= 0.0f)
|
||||
{
|
||||
@@ -286,8 +289,8 @@ void ArenaSimulation::tickDeaths()
|
||||
|
||||
for (entt::entity deadEntity : deadShips)
|
||||
{
|
||||
const ShipIdentity& si = m_admin.get<ShipIdentity>(deadEntity);
|
||||
const Position& pos = m_admin.get<Position>(deadEntity);
|
||||
const ShipIdentityComponent& si = m_admin.get<ShipIdentityComponent>(deadEntity);
|
||||
const PositionComponent& pos = m_admin.get<PositionComponent>(deadEntity);
|
||||
for (const ShipDef& def : m_gameConfig.ships.ships)
|
||||
{
|
||||
if (def.id == si.schematicId && def.loot.scrapDrop > 0)
|
||||
@@ -303,8 +306,9 @@ void ArenaSimulation::tickDeaths()
|
||||
|
||||
// Dead stations.
|
||||
std::vector<entt::entity> deadStations;
|
||||
m_admin.forEach<StationBody, Health>(
|
||||
[&deadStations](entt::entity e, const StationBody& /*sb*/, const Health& h)
|
||||
m_admin.forEach<StationBodyComponent, HealthComponent>(
|
||||
[&deadStations](entt::entity e, const StationBodyComponent& /*sb*/,
|
||||
const HealthComponent& h)
|
||||
{
|
||||
if (h.hp <= 0.0f)
|
||||
{
|
||||
@@ -314,16 +318,16 @@ void ArenaSimulation::tickDeaths()
|
||||
|
||||
for (entt::entity deadEntity : deadStations)
|
||||
{
|
||||
const StationBody& sb = m_admin.get<StationBody>(deadEntity);
|
||||
const StationBodyComponent& sb = m_admin.get<StationBodyComponent>(deadEntity);
|
||||
m_buildingSystem->unregisterTileOccupancy(sb.bodyCells);
|
||||
m_admin.destroy(deadEntity);
|
||||
}
|
||||
|
||||
// Check end conditions — HQ proxy entities.
|
||||
const bool team1HqGone = !m_admin.isValid(m_team1HqEntity)
|
||||
|| m_admin.get<Health>(m_team1HqEntity).hp <= 0.0f;
|
||||
|| m_admin.get<HealthComponent>(m_team1HqEntity).hp <= 0.0f;
|
||||
const bool team2HqGone = !m_admin.isValid(m_team2HqEntity)
|
||||
|| m_admin.get<Health>(m_team2HqEntity).hp <= 0.0f;
|
||||
|| m_admin.get<HealthComponent>(m_team2HqEntity).hp <= 0.0f;
|
||||
|
||||
if (team1HqGone || team2HqGone)
|
||||
{
|
||||
@@ -336,19 +340,19 @@ void ArenaSimulation::tickDeaths()
|
||||
// Check if all ships and defence stations of one team are destroyed.
|
||||
bool team1HasUnits = false;
|
||||
bool team2HasUnits = false;
|
||||
m_admin.forEach<ShipIdentity, Faction>(
|
||||
m_admin.forEach<ShipIdentityComponent, FactionComponent>(
|
||||
[&team1HasUnits, &team2HasUnits](entt::entity /*e*/,
|
||||
const ShipIdentity& /*si*/,
|
||||
const Faction& f)
|
||||
const ShipIdentityComponent& /*si*/,
|
||||
const FactionComponent& f)
|
||||
{
|
||||
if (f.isEnemy) { team2HasUnits = true; }
|
||||
else { team1HasUnits = true; }
|
||||
});
|
||||
|
||||
m_admin.forEach<StationBody, Faction>(
|
||||
m_admin.forEach<StationBodyComponent, FactionComponent>(
|
||||
[&team1HasUnits, &team2HasUnits](entt::entity /*e*/,
|
||||
const StationBody& /*sb*/,
|
||||
const Faction& f)
|
||||
const StationBodyComponent& /*sb*/,
|
||||
const FactionComponent& f)
|
||||
{
|
||||
if (f.isEnemy) { team2HasUnits = true; }
|
||||
else { team1HasUnits = true; }
|
||||
@@ -442,7 +446,7 @@ void ArenaSimulation::updateStatus()
|
||||
hqEntry.total = 1;
|
||||
const entt::entity hqEntity = (ti == 0) ? m_team1HqEntity : m_team2HqEntity;
|
||||
hqEntry.surviving = (m_admin.isValid(hqEntity)
|
||||
&& m_admin.get<Health>(hqEntity).hp > 0.0f) ? 1 : 0;
|
||||
&& m_admin.get<HealthComponent>(hqEntity).hp > 0.0f) ? 1 : 0;
|
||||
teamStatus.entries.push_back(hqEntry);
|
||||
}
|
||||
|
||||
@@ -456,9 +460,10 @@ void ArenaSimulation::updateStatus()
|
||||
|
||||
int surviving = 0;
|
||||
const bool isEnemyTeam = (ti == 1);
|
||||
m_admin.forEach<ShipIdentity, Faction, Health>(
|
||||
m_admin.forEach<ShipIdentityComponent, FactionComponent, HealthComponent>(
|
||||
[&surviving, &shipEntry, isEnemyTeam](entt::entity /*e*/,
|
||||
const ShipIdentity& si, const Faction& f, const Health& h)
|
||||
const ShipIdentityComponent& si, const FactionComponent& f,
|
||||
const HealthComponent& h)
|
||||
{
|
||||
if (f.isEnemy == isEnemyTeam
|
||||
&& si.schematicId == shipEntry.schematicId
|
||||
@@ -484,9 +489,10 @@ void ArenaSimulation::updateStatus()
|
||||
|
||||
int surviving = 0;
|
||||
const bool isEnemyTeam = (ti == 1);
|
||||
m_admin.forEach<StationBody, Faction, Health>(
|
||||
m_admin.forEach<StationBodyComponent, FactionComponent, HealthComponent>(
|
||||
[&surviving, &stationEntry, isEnemyTeam](entt::entity /*e*/,
|
||||
const StationBody& sb, const Faction& f, const Health& h)
|
||||
const StationBodyComponent& sb, const FactionComponent& f,
|
||||
const HealthComponent& h)
|
||||
{
|
||||
if (f.isEnemy == isEnemyTeam
|
||||
&& sb.anchor == stationEntry.position
|
||||
@@ -503,4 +509,3 @@ void ArenaSimulation::updateStatus()
|
||||
std::lock_guard<std::mutex> lock(m_statusMutex);
|
||||
m_status = newStatus;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include "BalancingConfig.h"
|
||||
#include "BeltSystem.h"
|
||||
#include "EcsComponents.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "BuildingId.h"
|
||||
|
||||
|
||||
@@ -10,10 +10,15 @@
|
||||
#include "ArenaSimulation.h"
|
||||
#include "Building.h"
|
||||
#include "BuildingSystem.h"
|
||||
#include "DynamicBodyComponent.h"
|
||||
#include "EcsComponents.h"
|
||||
#include "FacingComponent.h"
|
||||
#include "FactionComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "PositionComponent.h"
|
||||
#include "RepairToolComponent.h"
|
||||
#include "SalvageCargoComponent.h"
|
||||
#include "ScrapSystem.h"
|
||||
#include "Ship.h"
|
||||
#include "ShipIdentityComponent.h"
|
||||
#include "StationBodyComponent.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -101,9 +106,9 @@ void ArenaView::onFrame()
|
||||
{
|
||||
float maxRadius = 0.125f;
|
||||
if (m_sim->admin().isValid(fe.target)
|
||||
&& m_sim->admin().hasAll<StationBody>(fe.target))
|
||||
&& m_sim->admin().hasAll<StationBodyComponent>(fe.target))
|
||||
{
|
||||
const StationBody& sb = m_sim->admin().get<StationBody>(fe.target);
|
||||
const StationBodyComponent& sb = m_sim->admin().get<StationBodyComponent>(fe.target);
|
||||
const int shorter = std::min(sb.footprint.width(),
|
||||
sb.footprint.height());
|
||||
maxRadius = shorter / 2.0f;
|
||||
@@ -197,11 +202,11 @@ QRectF ArenaView::tileRect(QPoint tile) const
|
||||
|
||||
std::optional<QVector2D> ArenaView::entityPosition(entt::entity entity) const
|
||||
{
|
||||
if (!m_sim->admin().isValid(entity) || !m_sim->admin().hasAll<Position>(entity))
|
||||
if (!m_sim->admin().isValid(entity) || !m_sim->admin().hasAll<PositionComponent>(entity))
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
return m_sim->admin().get<Position>(entity).value;
|
||||
return m_sim->admin().get<PositionComponent>(entity).value;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -273,8 +278,8 @@ void ArenaView::drawScrap(QPainter& painter)
|
||||
|
||||
void ArenaView::drawStations(QPainter& painter)
|
||||
{
|
||||
m_sim->admin().forEach<StationBody, Faction, Health>(
|
||||
[&](entt::entity /*e*/, const StationBody& sb, const Faction& f, const Health& h)
|
||||
m_sim->admin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
|
||||
[&](entt::entity /*e*/, const StationBodyComponent& sb, const FactionComponent& f, const HealthComponent& h)
|
||||
{
|
||||
const BuildingType visType = f.isEnemy
|
||||
? BuildingType::EnemyDefenceStation
|
||||
@@ -315,12 +320,14 @@ void ArenaView::drawStations(QPainter& painter)
|
||||
|
||||
void ArenaView::drawShips(QPainter& painter)
|
||||
{
|
||||
m_sim->admin().forEach<ShipIdentity, Position, Facing, Faction>(
|
||||
[&](entt::entity e, const ShipIdentity& /*si*/, const Position& pos,
|
||||
const Facing& facing, const Faction& fac)
|
||||
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent, FacingComponent,
|
||||
FactionComponent>(
|
||||
[&](entt::entity e, const ShipIdentityComponent& /*si*/,
|
||||
const PositionComponent& pos, const FacingComponent& facing,
|
||||
const FactionComponent& fac)
|
||||
{
|
||||
const bool hasCargo = m_sim->admin().hasAll<SalvageCargo>(e);
|
||||
const bool hasRepair = m_sim->admin().hasAll<RepairTool>(e);
|
||||
const bool hasCargo = m_sim->admin().hasAll<SalvageCargoComponent>(e);
|
||||
const bool hasRepair = m_sim->admin().hasAll<RepairToolComponent>(e);
|
||||
const ShipRole role = shipRoleFromComponents(fac.isEnemy, hasCargo, hasRepair);
|
||||
const std::map<ShipRole, ShipVisuals>::const_iterator it =
|
||||
m_visuals->ships.find(role);
|
||||
|
||||
Reference in New Issue
Block a user