Remove shared pointer, ODR of componentType variable

This commit is contained in:
David Markowitz 2023-06-09 01:22:45 -07:00
parent ec00f5fd9d
commit 62aa863997
49 changed files with 60 additions and 75 deletions

View File

@ -102,7 +102,6 @@ Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity)
m_ChildEntities = {};
m_ScheduleKiller = nullptr;
m_TargetsInPhantom = {};
m_Components = {};
m_DieCallbacks = {};
m_PhantomCollisionCallbacks = {};
m_IsParentChildDirty = true;

View File

@ -48,7 +48,7 @@ namespace CppScripts {
* Entities are composed of components which define their behavior.
*/
using ComponentPtr = std::shared_ptr<Component>;
using ComponentPtr = std::unique_ptr<Component>;
class Entity {
public:
@ -278,15 +278,6 @@ public:
template<typename Cmpt>
Cmpt* GetComponent() const;
/**
* @brief Get an owning reference to a component.
*
* @tparam Cmpt The component to get a shared reference of
* @return std::shared_ptr<Cmpt> The owning shared pointer
*/
template<typename Cmpt>
std::shared_ptr<Cmpt> GetSharedComponent() const;
/**
* @brief Adds a component to this Entity.
*

View File

@ -9,10 +9,15 @@ Cmpt* Entity::GetComponent() const {
const auto& componentItr = this->m_Components.find(Cmpt::ComponentType);
return componentItr == this->m_Components.end() ? nullptr : dynamic_cast<Cmpt*>(componentItr->second.get());
}
template<typename Cmpt>
std::shared_ptr<Cmpt> Entity::GetSharedComponent() const {
const auto& componentItr = this->m_Components.find(Cmpt::ComponentType);
return componentItr == this->m_Components.end() ? nullptr : std::dynamic_pointer_cast<Cmpt>(componentItr->second);
template<typename Cmpt, typename...ConstructorValues>
Cmpt* Entity::AddComponent(ConstructorValues...arguments) {
auto component = GetComponent<Cmpt>();
if (component) return dynamic_cast<Cmpt*>(component);
auto& insertedComponent = m_Components.insert_or_assign(Cmpt::ComponentType,
std::make_unique<Cmpt>(this, std::forward<ConstructorValues>(arguments)...)).first->second;
return dynamic_cast<Cmpt*>(insertedComponent.get());
}
template<typename T>
@ -146,13 +151,3 @@ T Entity::GetNetworkVar(const std::u16string& name) {
return LDFData<T>::Default;
}
template<typename Cmpt, typename...ConstructorValues>
Cmpt* Entity::AddComponent(ConstructorValues...arguments) {
auto component = GetComponent<Cmpt>();
if (component) return dynamic_cast<Cmpt*>(component);
auto& insertedComponent = m_Components.insert_or_assign(Cmpt::ComponentType,
std::make_shared<Cmpt>(this, std::forward<ConstructorValues>(arguments)...)).first->second;
return dynamic_cast<Cmpt*>(insertedComponent.get());
}

View File

@ -190,7 +190,7 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
}
if (m_MovementAI == nullptr) {
m_MovementAI = m_OwningEntity->GetSharedComponent<MovementAIComponent>();
m_MovementAI = m_OwningEntity->GetComponent<MovementAIComponent>();
if (m_MovementAI == nullptr) {
return;
}

View File

@ -48,7 +48,7 @@ struct AiSkillEntry
*/
class BaseCombatAIComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::BASE_COMBAT_AI;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::BASE_COMBAT_AI;
BaseCombatAIComponent(Entity* parentEntity, uint32_t id);
~BaseCombatAIComponent() override;
@ -320,7 +320,7 @@ private:
/**
* The component that handles movement AI, also owned by this entity
*/
std::shared_ptr<MovementAIComponent> m_MovementAI;
MovementAIComponent* m_MovementAI;
/**
* The position at which this entity spawned

View File

@ -12,7 +12,7 @@
*/
class BouncerComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::BOUNCER;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::BOUNCER;
BouncerComponent(Entity* parentEntity);
~BouncerComponent() override;

View File

@ -42,7 +42,7 @@ struct Buff
*/
class BuffComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::BUFF;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::BUFF;
explicit BuffComponent(Entity* parent);

View File

@ -16,7 +16,7 @@
*/
class BuildBorderComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::BUILD_BORDER;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::BUILD_BORDER;
BuildBorderComponent(Entity* parent);
~BuildBorderComponent() override;

View File

@ -62,7 +62,7 @@ enum StatisticID {
*/
class CharacterComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::CHARACTER;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::CHARACTER;
CharacterComponent(Entity* parent, Character* character);
~CharacterComponent() override;

View File

@ -21,7 +21,7 @@ enum class eStateChangeType : uint32_t;
*/
class ControllablePhysicsComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::CONTROLLABLE_PHYSICS;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::CONTROLLABLE_PHYSICS;
ControllablePhysicsComponent(Entity* entity);
~ControllablePhysicsComponent() override;

View File

@ -10,7 +10,7 @@
*/
class HavokVehiclePhysicsComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::HAVOK_VEHICLE_PHYSICS;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::HAVOK_VEHICLE_PHYSICS;
HavokVehiclePhysicsComponent(Entity* parentEntity);
~HavokVehiclePhysicsComponent() override;

View File

@ -38,7 +38,7 @@ enum class eItemType : int32_t;
class InventoryComponent : public Component
{
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::INVENTORY;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::INVENTORY;
explicit InventoryComponent(Entity* parent, tinyxml2::XMLDocument* document = nullptr);
void Update(float deltaTime) override;

View File

@ -11,7 +11,7 @@
class LUPExhibitComponent : public Component
{
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::EXHIBIT;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::EXHIBIT;
LUPExhibitComponent(Entity* parent);
~LUPExhibitComponent();

View File

@ -13,7 +13,7 @@
class LevelProgressionComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::LEVEL_PROGRESSION;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::LEVEL_PROGRESSION;
/**
* Constructor for this component

View File

@ -27,7 +27,7 @@ class AchievementCacheKey;
class MissionComponent : public Component
{
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::MISSION;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MISSION;
explicit MissionComponent(Entity* parent);
~MissionComponent() override;

View File

@ -61,7 +61,7 @@ private:
*/
class MissionOfferComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::MISSION_OFFER;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MISSION_OFFER;
MissionOfferComponent(Entity* parent, LOT parentLot);
~MissionOfferComponent() override;

View File

@ -13,7 +13,7 @@ class Entity;
*/
class ModelBehaviorComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::MODEL_BEHAVIOR;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MODEL_BEHAVIOR;
ModelBehaviorComponent(Entity* parent);

View File

@ -12,7 +12,7 @@
*/
class ModuleAssemblyComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::MODULE_ASSEMBLY;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MODULE_ASSEMBLY;
ModuleAssemblyComponent(Entity* parent);
~ModuleAssemblyComponent() override;

View File

@ -22,7 +22,7 @@ MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) :
m_BaseCombatAI = nullptr;
m_BaseCombatAI = m_OwningEntity->GetSharedComponent<BaseCombatAIComponent>();
m_BaseCombatAI = m_OwningEntity->GetComponent<BaseCombatAIComponent>();
//Try and fix the insane values:
if (m_Info.wanderRadius > 5.0f) m_Info.wanderRadius = m_Info.wanderRadius * 0.5f;

View File

@ -310,7 +310,7 @@ private:
/**
* Optional direct link to the combat AI component of the parent entity
*/
std::shared_ptr<BaseCombatAIComponent> m_BaseCombatAI = nullptr;
BaseCombatAIComponent* m_BaseCombatAI = nullptr;
/**
* The path the entity is currently following

View File

@ -106,7 +106,7 @@ public:
*/
class MovingPlatformComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::MOVING_PLATFORM;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MOVING_PLATFORM;
MovingPlatformComponent(Entity* parent, const std::string& pathName);
~MovingPlatformComponent() override;

View File

@ -11,7 +11,7 @@
*/
class MultiZoneEntranceComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::MULTI_ZONE_ENTRANCE;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MULTI_ZONE_ENTRANCE;
/**
* Constructor for this component, builds the m_LUPWorlds vector

View File

@ -363,7 +363,7 @@ void PetComponent::Update(float deltaTime) {
}
if (m_MovementAI == nullptr) {
m_MovementAI = m_OwningEntity->GetSharedComponent<MovementAIComponent>();
m_MovementAI = m_OwningEntity->GetComponent<MovementAIComponent>();
if (!m_MovementAI) return;
}
@ -792,7 +792,7 @@ void PetComponent::ClientFailTamingMinigame() {
}
void PetComponent::Wander() {
if (!m_MovementAI) m_MovementAI = m_OwningEntity->GetSharedComponent<MovementAIComponent>();
if (!m_MovementAI) m_MovementAI = m_OwningEntity->GetComponent<MovementAIComponent>();
if (m_MovementAI == nullptr || !m_MovementAI->AtFinalWaypoint()) {
return;

View File

@ -21,7 +21,7 @@ enum class PetAbilityType
class PetComponent : public Component
{
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::PET;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PET;
explicit PetComponent(Entity* parentEntity, uint32_t componentId);
~PetComponent() override;
@ -349,7 +349,7 @@ private:
/**
* The movement AI component that is related to this pet, required to move it around
*/
std::shared_ptr<MovementAIComponent> m_MovementAI;
MovementAIComponent* m_MovementAI;
/**
* Preconditions that need to be met before an entity can tame this pet

View File

@ -27,7 +27,7 @@ enum class ePhysicsEffectType : uint32_t ;
*/
class PhantomPhysicsComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::PHANTOM_PHYSICS;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PHANTOM_PHYSICS;
PhantomPhysicsComponent(Entity* parent);
~PhantomPhysicsComponent() override;

View File

@ -10,7 +10,7 @@
*/
class PlayerForcedMovementComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::PLAYER_FORCED_MOVEMENT;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PLAYER_FORCED_MOVEMENT;
/**
* Constructor for this component

View File

@ -14,7 +14,7 @@
*/
class PossessableComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::POSSESSABLE;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::POSSESSABLE;
PossessableComponent(Entity* parentEntity, uint32_t componentId);

View File

@ -18,7 +18,7 @@ enum class ePossessionType : uint8_t {
*/
class PossessorComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::POSSESSOR;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::POSSESSOR;
PossessorComponent(Entity* parent);
~PossessorComponent() override;

View File

@ -22,7 +22,7 @@ struct PropertyState {
*/
class PropertyComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY;
explicit PropertyComponent(Entity* parentEntity);
~PropertyComponent() override;
[[nodiscard]] PropertyState* GetPropertyState() const { return m_PropertyState; };

View File

@ -13,7 +13,7 @@
*/
class PropertyEntranceComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_ENTRANCE;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_ENTRANCE;
explicit PropertyEntranceComponent(uint32_t componentID, Entity* parent);
/**

View File

@ -32,7 +32,7 @@ enum class PropertyPrivacyOption
class PropertyManagementComponent : public Component
{
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_MANAGEMENT;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_MANAGEMENT;
PropertyManagementComponent(Entity* parent);
static PropertyManagementComponent* Instance();

View File

@ -10,7 +10,7 @@
class PropertyVendorComponent : public Component
{
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_VENDOR;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_VENDOR;
explicit PropertyVendorComponent(Entity* parent);
/**

View File

@ -19,7 +19,7 @@
*/
class ProximityMonitorComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::PROXIMITY_MONITOR;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PROXIMITY_MONITOR;
ProximityMonitorComponent(Entity* parentEntity, int smallRadius = -1, int largeRadius = -1);
~ProximityMonitorComponent() override;

View File

@ -105,7 +105,7 @@ struct RacingPlayerInfo {
*/
class RacingControlComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL;
RacingControlComponent(Entity* parentEntity);
~RacingControlComponent();

View File

@ -15,7 +15,7 @@ public:
explicit RailActivatorComponent(Entity* parent, int32_t componentID);
~RailActivatorComponent() override;
static const eReplicaComponentType ComponentType = eReplicaComponentType::RAIL_ACTIVATOR;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RAIL_ACTIVATOR;
/**
* Handles the OnUse event from some entity, initiates the rail movement

View File

@ -22,7 +22,7 @@ enum class eQuickBuildFailReason : uint32_t;
*/
class RebuildComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD;
RebuildComponent(Entity* entity);
~RebuildComponent() override;

View File

@ -56,7 +56,7 @@ struct Effect {
*/
class RenderComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::RENDER;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RENDER;
RenderComponent(Entity* entity, int32_t componentId = -1);
~RenderComponent() override;

View File

@ -19,7 +19,7 @@
*/
class RigidbodyPhantomPhysicsComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::PHANTOM_PHYSICS;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PHANTOM_PHYSICS;
RigidbodyPhantomPhysicsComponent(Entity* parent);
~RigidbodyPhantomPhysicsComponent() override;

View File

@ -18,7 +18,7 @@ class PreconditionExpression;
*/
class RocketLaunchpadControlComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::ROCKET_LAUNCHPAD_CONTROL;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::ROCKET_LAUNCHPAD_CONTROL;
RocketLaunchpadControlComponent(Entity* parent, int rocketId);
~RocketLaunchpadControlComponent() override;

View File

@ -156,7 +156,7 @@ struct ActivityPlayer {
*/
class ScriptedActivityComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::SCRIPTED_ACTIVITY;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::SCRIPTED_ACTIVITY;
ScriptedActivityComponent(Entity* parent, int activityID);
~ScriptedActivityComponent() override;

View File

@ -73,7 +73,7 @@ struct StaticShootingGalleryParams {
*/
class ShootingGalleryComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::SHOOTING_GALLERY;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::SHOOTING_GALLERY;
explicit ShootingGalleryComponent(Entity* parent);
~ShootingGalleryComponent();

View File

@ -28,7 +28,7 @@ enum class eClimbableType : int32_t {
*/
class SimplePhysicsComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::SIMPLE_PHYSICS;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::SIMPLE_PHYSICS;
SimplePhysicsComponent(uint32_t componentID, Entity* parent);
~SimplePhysicsComponent() override;

View File

@ -59,7 +59,7 @@ struct SkillExecutionResult {
*/
class SkillComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::SKILL;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::SKILL;
explicit SkillComponent(Entity* parent);
~SkillComponent() override;

View File

@ -20,7 +20,7 @@ struct MusicCue {
*/
class SoundTriggerComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::SOUND_TRIGGER;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::SOUND_TRIGGER;
explicit SoundTriggerComponent(Entity* parent);
~SoundTriggerComponent() override;

View File

@ -10,7 +10,7 @@ SwitchComponent::SwitchComponent(Entity* parent) : Component(parent) {
m_ResetTime = m_OwningEntity->GetVarAs<int32_t>(u"switch_reset_time");
m_Rebuild = m_OwningEntity->GetSharedComponent<RebuildComponent>();
m_Rebuild = m_OwningEntity->GetComponent<RebuildComponent>();
}
SwitchComponent::~SwitchComponent() {

View File

@ -16,7 +16,7 @@
*/
class SwitchComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::SWITCH;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::SWITCH;
SwitchComponent(Entity* parent);
~SwitchComponent() override;
@ -75,7 +75,7 @@ private:
/**
* Attached rebuild component.
*/
std::shared_ptr<RebuildComponent> m_Rebuild;
RebuildComponent* m_Rebuild;
/**
* If the switch is on or off.

View File

@ -7,7 +7,7 @@
class TriggerComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::TRIGGER;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::TRIGGER;
explicit TriggerComponent(Entity* parent, const std::string triggerInfo);

View File

@ -14,7 +14,7 @@
*/
class VendorComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::VENDOR;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::VENDOR;
VendorComponent(Entity* parent);
~VendorComponent() override;

View File

@ -19,7 +19,7 @@ class Entity;
*/
class ScriptComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::SCRIPT;
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::SCRIPT;
ScriptComponent(Entity* parent, std::string scriptName, bool serialized, bool client = false);
~ScriptComponent() override;