From 4d88f633384fd35176dbf7db8cefee680a15b7f6 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Sun, 9 Jul 2023 22:37:28 -0700 Subject: [PATCH] PossessionComponent pass --- dGame/dComponents/PossessionComponent.cpp | 54 +++++++++++------------ dGame/dComponents/PossessionComponent.h | 12 ++++- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/dGame/dComponents/PossessionComponent.cpp b/dGame/dComponents/PossessionComponent.cpp index 7bc8635a..1a409843 100644 --- a/dGame/dComponents/PossessionComponent.cpp +++ b/dGame/dComponents/PossessionComponent.cpp @@ -12,29 +12,28 @@ PossessionComponent::PossessionComponent(Entity* parent) : Component(parent) { } PossessionComponent::~PossessionComponent() { - if (m_Possessable != LWOOBJID_EMPTY) { - auto* mount = EntityManager::Instance()->GetEntity(m_Possessable); - if (mount) { - auto* possessable = mount->GetComponent(); - if (possessable) { - if (possessable->GetIsItemSpawned()) { - GameMessages::SendMarkInventoryItemAsActive(m_ParentEntity->GetObjectID(), false, eUnequippableActiveType::MOUNT, GetMountItemID(), m_ParentEntity->GetSystemAddress()); - } - possessable->Dismount(); - } - } + if (m_Possessable == LWOOBJID_EMPTY) return; + + auto* mount = EntityManager::Instance()->GetEntity(m_Possessable); + if (!mount) return; + + auto* possessable = mount->GetComponent(); + if (!possessable) return; + + if (possessable->GetIsItemSpawned()) { + GameMessages::SendMarkInventoryItemAsActive(m_ParentEntity->GetObjectID(), false, eUnequippableActiveType::MOUNT, GetMountItemID(), m_ParentEntity->GetSystemAddress()); } + possessable->Dismount(); } void PossessionComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { outBitStream->Write(m_DirtyPossesor || bIsInitialUpdate); if (m_DirtyPossesor || bIsInitialUpdate) { - m_DirtyPossesor = false; outBitStream->Write(m_Possessable != LWOOBJID_EMPTY); - if (m_Possessable != LWOOBJID_EMPTY) { - outBitStream->Write(m_Possessable); - } + if (m_Possessable != LWOOBJID_EMPTY) outBitStream->Write(m_Possessable); + outBitStream->Write(m_PossessableType); + if (!bIsInitialUpdate) m_DirtyPossesor = false; } } @@ -66,19 +65,18 @@ void PossessionComponent::Dismount(Entity* mount, bool forceDismount) { // Don't do anything if we are busy dismounting if (GetIsDismounting() || !mount) return; SetIsDismounting(true); - - if (mount) { - auto* possessableComponent = mount->GetComponent(); - if (possessableComponent) { - possessableComponent->SetPossessor(LWOOBJID_EMPTY); - if (forceDismount) possessableComponent->ForceDepossess(); - } - EntityManager::Instance()->SerializeEntity(m_ParentEntity); - EntityManager::Instance()->SerializeEntity(mount); - - auto* characterComponent = m_ParentEntity->GetComponent(); - if (characterComponent) characterComponent->SetIsRacing(false); - } // Make sure we don't have wacky controls GameMessages::SendSetPlayerControlScheme(m_ParentEntity, eControlScheme::SCHEME_A); + + if (!mount) return; + auto* possessableComponent = mount->GetComponent(); + if (possessableComponent) { + possessableComponent->SetPossessor(LWOOBJID_EMPTY); + if (forceDismount) possessableComponent->ForceDepossess(); + } + EntityManager::Instance()->SerializeEntity(m_ParentEntity); + EntityManager::Instance()->SerializeEntity(mount); + + auto* characterComponent = m_ParentEntity->GetComponent(); + if (characterComponent) characterComponent->SetIsRacing(false); } diff --git a/dGame/dComponents/PossessionComponent.h b/dGame/dComponents/PossessionComponent.h index 0ef87ef0..cbfb6fb5 100644 --- a/dGame/dComponents/PossessionComponent.h +++ b/dGame/dComponents/PossessionComponent.h @@ -44,7 +44,11 @@ public: * Sets the ID that this entity is possessing * @param value The ID that this entity is possessing */ - void SetPossessable(LWOOBJID value) { m_Possessable = value; m_DirtyPossesor = true; } + void SetPossessable(const LWOOBJID& value) { + if (m_Possessable == value) return; + m_Possessable = value; + m_DirtyPossesor = true; + } /** * Returns the entity that this entity is currently posessing @@ -68,7 +72,11 @@ public: * Sets the possesible type that's currently used, merely used by the shooting gallery if it's 0 * @param value The possesible type to set */ - void SetPossessableType(ePossessionType value) { m_PossessableType = value; m_DirtyPossesor = true; } + void SetPossessableType(ePossessionType value) { + if (m_PossessableType == value) return; + m_PossessableType = value; + m_DirtyPossesor = true; + } /**