1
0
forked from 0ad/0ad

Provides entity ID for unit in its constructor.

Refs 2eac4af3a4, refs 56bb858802, 91ad17c685, 72bd886f80.

Differential Revision: https://code.wildfiregames.com/D5110
This was SVN commit r27818.
This commit is contained in:
Vladislav Belov 2023-08-28 18:01:44 +00:00
parent 37b2f93a3c
commit b7ef2f2d72
8 changed files with 37 additions and 65 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2023 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -18,18 +18,18 @@
#include "precompiled.h"
#include "Unit.h"
#include "Model.h"
#include "ObjectBase.h"
#include "ObjectEntry.h"
#include "ObjectManager.h"
#include "SkeletonAnim.h"
#include "SkeletonAnimDef.h"
#include "UnitAnimation.h"
#include "graphics/Model.h"
#include "graphics/ObjectBase.h"
#include "graphics/ObjectEntry.h"
#include "graphics/ObjectManager.h"
#include "graphics/SkeletonAnim.h"
#include "graphics/SkeletonAnimDef.h"
#include "graphics/UnitAnimation.h"
#include "ps/CLogger.h"
CUnit::CUnit(CObjectManager& objectManager, const CActorDef& actor, uint32_t seed)
: m_ID(INVALID_ENTITY), m_ObjectManager(objectManager), m_Actor(actor), m_Seed(seed), m_Animation(nullptr)
CUnit::CUnit(CObjectManager& objectManager, const CActorDef& actor, const entity_id_t id, const uint32_t seed)
: m_ObjectManager(objectManager), m_Actor(actor), m_ID(id), m_Seed(seed), m_Animation(nullptr)
{
/**
* When entity selections change, we might end up with a different layout in terms of variants/groups,
@ -48,13 +48,13 @@ CUnit::~CUnit()
delete m_Model;
}
CUnit* CUnit::Create(const CStrW& actorName, uint32_t seed, CObjectManager& objectManager)
CUnit* CUnit::Create(const CStrW& actorName, const entity_id_t id, const uint32_t seed, CObjectManager& objectManager)
{
auto [success, actor] = objectManager.FindActorDef(actorName);
UNUSED2(success);
CUnit* unit = new CUnit(objectManager, actor, seed);
CUnit* unit = new CUnit(objectManager, actor, id, seed);
if (!unit->m_Model)
{
delete unit;
@ -69,13 +69,6 @@ void CUnit::UpdateModel(float frameTime)
m_Animation->Update(frameTime*1000.0f);
}
void CUnit::SetID(entity_id_t id)
{
m_ID = id;
if (m_Animation)
m_Animation->SetEntityID(id);
}
void CUnit::SetEntitySelection(const CStr& key, const CStr& selection)
{
CStr selection_lc = selection.LowerCase();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2023 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -18,12 +18,12 @@
#ifndef INCLUDED_UNIT
#define INCLUDED_UNIT
#include <map>
#include <set>
#include "ps/CStr.h"
#include "simulation2/system/Entity.h" // entity_id_t
#include <map>
#include <set>
class CActorDef;
class CModelAbstract;
class CObjectEntry;
@ -38,15 +38,14 @@ class CUnit
NONCOPYABLE(CUnit);
private:
// Private constructor. Needs complete list of selections for the variation.
CUnit(CObjectManager& objectManager, const CActorDef& actor, uint32_t seed);
CUnit(CObjectManager& objectManager, const CActorDef& actor, const entity_id_t id, const uint32_t seed);
public:
// Attempt to create a unit with the given actor.
// If specific selections are wanted, call SetEntitySelection or SetActorSelections after creation.
// Returns NULL on failure.
static CUnit* Create(const CStrW& actorName, uint32_t seed, CObjectManager& objectManager);
static CUnit* Create(const CStrW& actorName, const entity_id_t id, const uint32_t seed, CObjectManager& objectManager);
// destructor
~CUnit();
// get unit's template object
@ -71,7 +70,6 @@ public:
// persistently despite saving/loading maps. Default for new units is -1; should
// usually be set to CUnitManager::GetNewID() after creation.
entity_id_t GetID() const { return m_ID; }
void SetID(entity_id_t id);
const std::set<CStr>& GetActorSelections() const { return m_ActorSelections; }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2023 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -50,11 +50,6 @@ CUnitAnimation::CUnitAnimation(entity_id_t ent, CModel* model, CObjectEntry* obj
ReloadUnit(model, object);
}
void CUnitAnimation::SetEntityID(entity_id_t ent)
{
m_Entity = ent;
}
void CUnitAnimation::AddModel(CModel* model, const CObjectEntry* object)
{
SModelAnimState state;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2023 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -19,7 +19,6 @@
#define INCLUDED_UNITANIMATION
#include "ps/CStr.h"
#include "simulation2/system/Entity.h"
#include <vector>
@ -43,12 +42,6 @@ public:
*/
CUnitAnimation(entity_id_t ent, CModel* model, CObjectEntry* object);
/**
* Change the entity ID associated with this animation
* (currently used for playing locational sound effects).
*/
void SetEntityID(entity_id_t ent);
/**
* Start playing an animation.
* The unit's actor defines the available animations, and if more than one is available

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2022 Wildfire Games.
/* Copyright (C) 2023 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -15,19 +15,13 @@
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Container that owns all units
*/
#include "precompiled.h"
#include <float.h>
#include "Model.h"
#include "UnitManager.h"
#include "Unit.h"
#include "ObjectManager.h"
#include "ObjectEntry.h"
#include "graphics/Model.h"
#include "graphics/ObjectEntry.h"
#include "graphics/ObjectManager.h"
#include "graphics/Unit.h"
#include "graphics/UnitManager.h"
#include "ps/Game.h"
#include "ps/World.h"
@ -87,12 +81,12 @@ void CUnitManager::DeleteAll()
///////////////////////////////////////////////////////////////////////////////
// CreateUnit: create a new unit and add it to the world
CUnit* CUnitManager::CreateUnit(const CStrW& actorName, uint32_t seed)
CUnit* CUnitManager::CreateUnit(const CStrW& actorName, const entity_id_t id, const uint32_t seed)
{
if (! m_ObjectManager)
return NULL;
CUnit* unit = CUnit::Create(actorName, seed, *m_ObjectManager);
CUnit* unit = CUnit::Create(actorName, id, seed, *m_ObjectManager);
if (unit)
AddUnit(unit);
return unit;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2022 Wildfire Games.
/* Copyright (C) 2023 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -23,6 +23,7 @@
#define INCLUDED_UNITMANAGER
#include "ps/CStrForward.h"
#include "simulation2/system/Entity.h"
#include <vector>
#include <set>
@ -49,7 +50,7 @@ public:
void DeleteAll();
// creates a new unit and adds it to the world
CUnit* CreateUnit(const CStrW& actorName, uint32_t seed);
CUnit* CreateUnit(const CStrW& actorName, const entity_id_t id, const uint32_t seed);
// return the units
const std::vector<CUnit*>& GetUnits() const { return m_Units; }
@ -69,4 +70,4 @@ private:
CObjectManager* m_ObjectManager;
};
#endif
#endif // INCLUDED_UNITMANAGER

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2022 Wildfire Games.
/* Copyright (C) 2023 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -202,7 +202,7 @@ uint32_t CCmpProjectileManager::LaunchProjectile(CFixedVector3D launchPoint, CFi
projectile.origin = launchPoint;
projectile.unit = GetSimContext().GetUnitManager().CreateUnit(actorName, m_ActorSeed++);
projectile.unit = GetSimContext().GetUnitManager().CreateUnit(actorName, INVALID_ENTITY, m_ActorSeed++);
if (!projectile.unit) // The error will have already been logged
return currentId;
@ -301,7 +301,7 @@ void CCmpProjectileManager::Interpolate(float frameTime)
quat.ToMatrix(transform);
transform.Translate(m_Projectiles[i].pos);
CUnit* unit = GetSimContext().GetUnitManager().CreateUnit(m_Projectiles[i].impactActorName, m_ActorSeed++);
CUnit* unit = GetSimContext().GetUnitManager().CreateUnit(m_Projectiles[i].impactActorName, INVALID_ENTITY, m_ActorSeed++);
unit->GetModel().SetTransform(transform);
ProjectileImpactAnimation projectileImpactAnimation;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2022 Wildfire Games.
/* Copyright (C) 2023 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -591,7 +591,7 @@ void CCmpVisualActor::InitModel()
std::wstring actorName = m_ActorName;
if (actorName.find(L".xml") == std::wstring::npos)
actorName += L".xml";
m_Unit = GetSimContext().GetUnitManager().CreateUnit(actorName, GetActorSeed());
m_Unit = GetSimContext().GetUnitManager().CreateUnit(actorName, GetEntityId(), GetActorSeed());
if (!m_Unit)
return;
@ -621,8 +621,6 @@ void CCmpVisualActor::InitModel()
model.ToCModelDecal()->RemoveShadows();
}
m_Unit->SetID(GetEntityId());
bool floating = m_Unit->GetObject().m_Base->m_Properties.m_FloatOnWater;
CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle());
if (cmpPosition)