From c168f6c97023ef01ac8ca94a8ddae692f872e384 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Fri, 10 Feb 2023 21:33:30 -0600 Subject: [PATCH 1/4] Break out the model component into the model, item, and mutable model behaviors --- dCommon/dEnums/ePhysicsBehaviorType.h | 14 +++++ dCommon/dEnums/eUgcModerationStatus.h | 13 +++++ dGame/Entity.cpp | 14 ++--- dGame/dComponents/CMakeLists.txt | 2 + dGame/dComponents/ItemComponent.cpp | 33 ++++++++++++ dGame/dComponents/ItemComponent.h | 49 +++++++++++++++++ dGame/dComponents/ModelComponent.cpp | 32 +++++------- dGame/dComponents/ModelComponent.h | 24 ++++++--- .../MutableModelBehaviorComponent.cpp | 30 +++++++++++ .../MutableModelBehaviorComponent.h | 52 +++++++++++++++++++ 10 files changed, 231 insertions(+), 32 deletions(-) create mode 100644 dCommon/dEnums/ePhysicsBehaviorType.h create mode 100644 dCommon/dEnums/eUgcModerationStatus.h create mode 100644 dGame/dComponents/ItemComponent.cpp create mode 100644 dGame/dComponents/ItemComponent.h create mode 100644 dGame/dComponents/MutableModelBehaviorComponent.cpp create mode 100644 dGame/dComponents/MutableModelBehaviorComponent.h diff --git a/dCommon/dEnums/ePhysicsBehaviorType.h b/dCommon/dEnums/ePhysicsBehaviorType.h new file mode 100644 index 00000000..52862daa --- /dev/null +++ b/dCommon/dEnums/ePhysicsBehaviorType.h @@ -0,0 +1,14 @@ +#ifndef __EPHYSICSBEHAVIORTYPE__H__ +#define __EPHYSICSBEHAVIORTYPE__H__ + +#include + +enum class ePhysicsBehaviorType : int32_t { + INVALID = -1, + GROUND, + FLYING, + STANDARD, + DYNAMIC +}; + +#endif //!__EPHYSICSBEHAVIORTYPE__H__ diff --git a/dCommon/dEnums/eUgcModerationStatus.h b/dCommon/dEnums/eUgcModerationStatus.h new file mode 100644 index 00000000..ae289b74 --- /dev/null +++ b/dCommon/dEnums/eUgcModerationStatus.h @@ -0,0 +1,13 @@ + +#ifndef __EUGCMODERATIONSTATUS__H__ +#define __EUGCMODERATIONSTATUS__H__ + +#include + +enum class eUgcModerationStatus : uint32_t { + NoStatus, + Approved, + Rejected, +}; + +#endif //!__EUGCMODERATIONSTATUS__H__ diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index eefa5107..ae70c892 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -68,6 +68,7 @@ #include "ShootingGalleryComponent.h" #include "RailActivatorComponent.h" #include "LUPExhibitComponent.h" +#include "ItemComponent.h" Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity) { m_ObjectID = objectID; @@ -618,7 +619,7 @@ void Entity::Initialize() { m_Components.insert(std::make_pair(COMPONENT_TYPE_SCRIPTED_ACTIVITY, new ScriptedActivityComponent(this, scriptedActivityID))); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MODEL, -1) != -1 && !GetComponent()) { + if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MODEL, -1) != -1 && !(petComponentId > 0)) { m_Components.insert(std::make_pair(COMPONENT_TYPE_MODEL, new ModelComponent(this))); if (m_Components.find(COMPONENT_TYPE_DESTROYABLE) == m_Components.end()) { auto destroyableComponent = new DestroyableComponent(this); @@ -630,9 +631,9 @@ void Entity::Initialize() { } } - PetComponent* petComponent; - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_ITEM) > 0 && !TryGetComponent(COMPONENT_TYPE_PET, petComponent) && !HasComponent(COMPONENT_TYPE_MODEL)) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_ITEM, nullptr)); + + if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_ITEM) > 0 && !(petComponentId > 0)) { + m_Components.emplace(COMPONENT_TYPE_ITEM, new ItemComponent(this)); } // Shooting gallery component @@ -1103,8 +1104,9 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType characterComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } - if (HasComponent(COMPONENT_TYPE_ITEM)) { - outBitStream->Write0(); + ItemComponent* itemComponent; + if (TryGetComponent(COMPONENT_TYPE_ITEM, itemComponent)) { + itemComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } InventoryComponent* inventoryComponent; diff --git a/dGame/dComponents/CMakeLists.txt b/dGame/dComponents/CMakeLists.txt index 0995428b..e237ccaf 100644 --- a/dGame/dComponents/CMakeLists.txt +++ b/dGame/dComponents/CMakeLists.txt @@ -7,6 +7,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp" "ControllablePhysicsComponent.cpp" "DestroyableComponent.cpp" "InventoryComponent.cpp" + "ItemComponent.cpp" "LevelProgressionComponent.cpp" "LUPExhibitComponent.cpp" "MissionComponent.cpp" @@ -15,6 +16,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp" "ModuleAssemblyComponent.cpp" "MovementAIComponent.cpp" "MovingPlatformComponent.cpp" + "MutableModelBehaviorCoponent.cpp" "PetComponent.cpp" "PhantomPhysicsComponent.cpp" "PlayerForcedMovementComponent.cpp" diff --git a/dGame/dComponents/ItemComponent.cpp b/dGame/dComponents/ItemComponent.cpp new file mode 100644 index 00000000..fcfb3721 --- /dev/null +++ b/dGame/dComponents/ItemComponent.cpp @@ -0,0 +1,33 @@ +#include "ItemComponent.h" +#include "Entity.h" +#include "eUgcModerationStatus.h" + + +ItemComponent::ItemComponent(Entity* parent) : Component(parent) { + m_Parent = parent; + + m_DirtyItemInfo = false; + + m_UgId = m_Parent->GetVarAs(u"userModelID"); + if (m_UgId == LWOOBJID_EMPTY) m_UgId = m_Parent->GetObjectID(); + + m_UgModerationStatus = eUgcModerationStatus::NoStatus; + + m_UgDescription = u""; +} + +void ItemComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { + + outBitStream->Write(m_DirtyItemInfo || bIsInitialUpdate); + if (m_DirtyItemInfo || bIsInitialUpdate){ + outBitStream->Write(m_UgId); + outBitStream->Write(m_UgModerationStatus); + outBitStream->Write(m_UgDescription != u""); + if (m_UgDescription != u""){ + outBitStream->Write(m_UgDescription.length()); + for (uint16_t character : m_UgDescription) outBitStream->Write(character); + } + m_DirtyItemInfo = false; + } + +} diff --git a/dGame/dComponents/ItemComponent.h b/dGame/dComponents/ItemComponent.h new file mode 100644 index 00000000..ca5cbfeb --- /dev/null +++ b/dGame/dComponents/ItemComponent.h @@ -0,0 +1,49 @@ +#pragma once +#include "dCommonVars.h" +#include "RakNetTypes.h" +#include "NiPoint3.h" +#include "NiQuaternion.h" +#include "Component.h" + +class Entity; +enum class eUgcModerationStatus : uint32_t; + +class ItemComponent : public Component { +public: + static const uint32_t ComponentType = COMPONENT_TYPE_ITEM; + + ItemComponent(Entity* parent); + + void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); + + void SetUgId(LWOOBJID id) { m_UgId = id; m_DirtyItemInfo = true; }; + LWOOBJID GetUgId() { return m_UgId; }; + + void SetUgModerationStatus(eUgcModerationStatus status) { m_UgModerationStatus = status; m_DirtyItemInfo = true; }; + eUgcModerationStatus GetUgModerationStatus() { return m_UgModerationStatus; }; + + void SetUgDescription(std::u16string description) { m_UgDescription = description; m_DirtyItemInfo = true; }; + std::u16string GetUgDescription() { return m_UgDescription;}; + +private: + + /** + * If we have change the item info + */ + bool m_DirtyItemInfo; + + /** + * The ID of the user that made the model + */ + LWOOBJID m_UgId; + + /** + * + */ + eUgcModerationStatus m_UgModerationStatus; + + /** + * The user generated description + */ + std::u16string m_UgDescription; +}; diff --git a/dGame/dComponents/ModelComponent.cpp b/dGame/dComponents/ModelComponent.cpp index 8fa085f2..9e53a05d 100644 --- a/dGame/dComponents/ModelComponent.cpp +++ b/dGame/dComponents/ModelComponent.cpp @@ -1,31 +1,23 @@ #include "ModelComponent.h" #include "Entity.h" +#include "ePhysicsBehaviorType.h" ModelComponent::ModelComponent(Entity* parent) : Component(parent) { + m_DirtyModelInfo = false; + m_IsPickable = false; + m_PhysicsType = ePhysicsBehaviorType::STANDARD; m_OriginalPosition = m_Parent->GetDefaultPosition(); m_OriginalRotation = m_Parent->GetDefaultRotation(); - - m_userModelID = m_Parent->GetVarAs(u"userModelID"); } void ModelComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { - // ItemComponent Serialization. Pets do not get this serialization. - if (!m_Parent->HasComponent(COMPONENT_TYPE_PET)) { - outBitStream->Write1(); - outBitStream->Write(m_userModelID != LWOOBJID_EMPTY ? m_userModelID : m_Parent->GetObjectID()); - outBitStream->Write(0); - outBitStream->Write0(); + outBitStream->Write(m_DirtyModelInfo || bIsInitialUpdate); + if (m_DirtyModelInfo || bIsInitialUpdate) { + outBitStream->Write(m_IsPickable); + outBitStream->Write(m_PhysicsType); + outBitStream->Write(m_OriginalPosition); + outBitStream->Write(m_OriginalRotation); + m_DirtyModelInfo = false; } - - //actual model component: - outBitStream->Write1(); // Yes we are writing model info - outBitStream->Write0(); // Is pickable - outBitStream->Write(2); // Physics type - outBitStream->Write(m_OriginalPosition); // Original position - outBitStream->Write(m_OriginalRotation); // Original rotation - - outBitStream->Write1(); // We are writing behavior info - outBitStream->Write(0); // Number of behaviors - outBitStream->Write1(); // Is this model paused - if (bIsInitialUpdate) outBitStream->Write0(); // We are not writing model editing info } + diff --git a/dGame/dComponents/ModelComponent.h b/dGame/dComponents/ModelComponent.h index 81342059..8f491168 100644 --- a/dGame/dComponents/ModelComponent.h +++ b/dGame/dComponents/ModelComponent.h @@ -6,6 +6,7 @@ #include "Component.h" class Entity; +enum class ePhysicsBehaviorType : int32_t; /** * Component that represents entities that are a model, e.g. collectible models and BBB models. @@ -28,7 +29,7 @@ public: * Sets the original position of the model * @param pos the original position to set */ - void SetPosition(const NiPoint3& pos) { m_OriginalPosition = pos; } + void SetPosition(const NiPoint3& pos) { m_OriginalPosition = pos; m_DirtyModelInfo = true; } /** * Returns the original rotation of the model @@ -40,10 +41,25 @@ public: * Sets the original rotation of the model * @param rot the original rotation to set */ - void SetRotation(const NiQuaternion& rot) { m_OriginalRotation = rot; } + void SetRotation(const NiQuaternion& rot) { m_OriginalRotation = rot; m_DirtyModelInfo = true; } private: + /** + * if the model info has changed + */ + bool m_DirtyModelInfo; + + /** + * If the model is pickable + */ + bool m_IsPickable; + + /** + * the phsyics type of the model + */ + ePhysicsBehaviorType m_PhysicsType; + /** * The original position of the model */ @@ -54,8 +70,4 @@ private: */ NiQuaternion m_OriginalRotation; - /** - * The ID of the user that made the model - */ - LWOOBJID m_userModelID; }; diff --git a/dGame/dComponents/MutableModelBehaviorComponent.cpp b/dGame/dComponents/MutableModelBehaviorComponent.cpp new file mode 100644 index 00000000..9dfd041c --- /dev/null +++ b/dGame/dComponents/MutableModelBehaviorComponent.cpp @@ -0,0 +1,30 @@ +#include "MutableModelBehaviorComponent.h" +#include "Entity.h" + +MutableModelBehaviorComponent::MutableModelBehaviorComponent(Entity* parent) : Component(parent) { + m_DirtyModelBehaviorInfo = false; + m_BehaviorCount = 0; + m_IsPaused = true; + + m_DirtyModelEditingInfo = false; + m_OldObjId = LWOOBJID_EMPTY; + m_Editor = LWOOBJID_EMPTY; + +} + +void MutableModelBehaviorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { + outBitStream->Write(m_DirtyModelBehaviorInfo || bIsInitialUpdate); + if (m_DirtyModelBehaviorInfo){ + outBitStream->Write(m_BehaviorCount); + outBitStream->Write(m_IsPaused); + m_DirtyModelBehaviorInfo = false; + } + + outBitStream->Write(m_DirtyModelEditingInfo && bIsInitialUpdate); + if (m_DirtyModelEditingInfo && bIsInitialUpdate) { + outBitStream->Write(m_OldObjId); + outBitStream->Write(m_Editor); + m_DirtyModelEditingInfo = false; + } +} + diff --git a/dGame/dComponents/MutableModelBehaviorComponent.h b/dGame/dComponents/MutableModelBehaviorComponent.h new file mode 100644 index 00000000..42187818 --- /dev/null +++ b/dGame/dComponents/MutableModelBehaviorComponent.h @@ -0,0 +1,52 @@ +#pragma once +#include "dCommonVars.h" +#include "RakNetTypes.h" +#include "NiPoint3.h" +#include "NiQuaternion.h" +#include "Component.h" + +class Entity; + +/** + * Component that represents entities that are a model, e.g. collectible models and BBB models. + */ +class MutableModelBehaviorComponent : public Component { +public: + static const uint32_t ComponentType = COMPONENT_TYPE_MODEL; + + MutableModelBehaviorComponent(Entity* parent); + + void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); + +private: + + /** + * if the behavior info has changed + */ + bool m_DirtyModelBehaviorInfo; + + /** + * The number of behaviors on the model + */ + uint32_t m_BehaviorCount; + + /** + * if the models behaviors are paused + */ + bool m_IsPaused; + + /** + * if the editing info is dirty + */ + bool m_DirtyModelEditingInfo; + + /** + * The old ID of the model + */ + LWOOBJID m_OldObjId; + + /** + * The ID of the editor of the model + */ + LWOOBJID m_Editor; +}; From 2ae9a92b553f3d646ebb0afa67ce044081f13ccf Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Fri, 10 Feb 2023 21:43:39 -0600 Subject: [PATCH 2/4] fix cmake --- dGame/dComponents/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dComponents/CMakeLists.txt b/dGame/dComponents/CMakeLists.txt index 18fbe19a..7e10b586 100644 --- a/dGame/dComponents/CMakeLists.txt +++ b/dGame/dComponents/CMakeLists.txt @@ -16,7 +16,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp" "ModuleAssemblyComponent.cpp" "MovementAIComponent.cpp" "MovingPlatformComponent.cpp" - "MutableModelBehaviorCoponent.cpp" + "MutableModelBehaviorComponent.cpp" "PetComponent.cpp" "PhantomPhysicsComponent.cpp" "PlayerForcedMovementComponent.cpp" From c2d5be0e5ddf83d9c109446d14b9d76025726625 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 20 Mar 2023 20:59:11 -0500 Subject: [PATCH 3/4] include --- dGame/Entity.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 3707e5db..49f8a9d2 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -71,6 +71,7 @@ #include "LUPExhibitComponent.h" #include "TriggerComponent.h" #include "ItemComponent.h" +#include "MutableModelBehaviorComponent.h" Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity) { m_ObjectID = objectID; From 15988afb4ce5ed26c65383153f677b7291b8fef6 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 20 Mar 2023 21:14:52 -0500 Subject: [PATCH 4/4] hey it compiles --- dGame/dComponents/ItemComponent.h | 3 ++- dGame/dComponents/MutableModelBehaviorComponent.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dGame/dComponents/ItemComponent.h b/dGame/dComponents/ItemComponent.h index ca5cbfeb..ccfa63a8 100644 --- a/dGame/dComponents/ItemComponent.h +++ b/dGame/dComponents/ItemComponent.h @@ -4,13 +4,14 @@ #include "NiPoint3.h" #include "NiQuaternion.h" #include "Component.h" +#include "eReplicaComponentType.h" class Entity; enum class eUgcModerationStatus : uint32_t; class ItemComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_ITEM; + static const eReplicaComponentType ComponentType = eReplicaComponentType::ITEM; ItemComponent(Entity* parent); diff --git a/dGame/dComponents/MutableModelBehaviorComponent.h b/dGame/dComponents/MutableModelBehaviorComponent.h index 42187818..2256fa31 100644 --- a/dGame/dComponents/MutableModelBehaviorComponent.h +++ b/dGame/dComponents/MutableModelBehaviorComponent.h @@ -4,6 +4,7 @@ #include "NiPoint3.h" #include "NiQuaternion.h" #include "Component.h" +#include "eReplicaComponentType.h" class Entity; @@ -12,7 +13,7 @@ class Entity; */ class MutableModelBehaviorComponent : public Component { public: - static const uint32_t ComponentType = COMPONENT_TYPE_MODEL; + static const eReplicaComponentType ComponentType = eReplicaComponentType::MODEL; MutableModelBehaviorComponent(Entity* parent);