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/dComponents/CMakeLists.txt b/dGame/dComponents/CMakeLists.txt index 9f4b0d06..8379bd41 100644 --- a/dGame/dComponents/CMakeLists.txt +++ b/dGame/dComponents/CMakeLists.txt @@ -22,6 +22,7 @@ set(DGAME_DCOMPONENTS_SOURCES "AchievementVendorComponent.cpp" "ModuleAssemblyComponent.cpp" "MovementAIComponent.cpp" "MovingPlatformComponent.cpp" + "MutableModelBehaviorComponent.cpp" "PetComponent.cpp" "PhantomPhysicsComponent.cpp" "PlayerForcedMovementComponent.cpp" diff --git a/dGame/dComponents/ItemComponent.cpp b/dGame/dComponents/ItemComponent.cpp index c06b4b46..fcfb3721 100644 --- a/dGame/dComponents/ItemComponent.cpp +++ b/dGame/dComponents/ItemComponent.cpp @@ -1,5 +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 index 6be074a4..ccfa63a8 100644 --- a/dGame/dComponents/ItemComponent.h +++ b/dGame/dComponents/ItemComponent.h @@ -1,15 +1,50 @@ -#ifndef __ITEMCOMPONENT__H__ -#define __ITEMCOMPONENT__H__ - +#pragma once +#include "dCommonVars.h" +#include "RakNetTypes.h" +#include "NiPoint3.h" +#include "NiQuaternion.h" #include "Component.h" #include "eReplicaComponentType.h" class Entity; +enum class eUgcModerationStatus : uint32_t; class ItemComponent : public Component { public: - inline static const eReplicaComponentType ComponentType = eReplicaComponentType::ITEM; - ItemComponent(Entity* parent); -}; + static const eReplicaComponentType ComponentType = eReplicaComponentType::ITEM; -#endif //!__ITEMCOMPONENT__H__ + 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/ModelBehaviorComponent.cpp b/dGame/dComponents/ModelBehaviorComponent.cpp index 479601ad..e7493250 100644 --- a/dGame/dComponents/ModelBehaviorComponent.cpp +++ b/dGame/dComponents/ModelBehaviorComponent.cpp @@ -1,31 +1,23 @@ #include "ModelBehaviorComponent.h" #include "Entity.h" +#include "ePhysicsBehaviorType.h" ModelBehaviorComponent::ModelBehaviorComponent(Entity* parent) : Component(parent) { + m_DirtyModelInfo = false; + m_IsPickable = false; + m_PhysicsType = ePhysicsBehaviorType::STANDARD; m_OriginalPosition = m_ParentEntity->GetDefaultPosition(); m_OriginalRotation = m_ParentEntity->GetDefaultRotation(); - - m_userModelID = m_ParentEntity->GetVarAs(u"userModelID"); } void ModelBehaviorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { - // ItemComponent Serialization. Pets do not get this serialization. - if (!m_ParentEntity->HasComponent(eReplicaComponentType::PET)) { - outBitStream->Write1(); - outBitStream->Write(m_userModelID != LWOOBJID_EMPTY ? m_userModelID : m_ParentEntity->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/ModelBehaviorComponent.h b/dGame/dComponents/ModelBehaviorComponent.h index 18a26faf..09b3ff3a 100644 --- a/dGame/dComponents/ModelBehaviorComponent.h +++ b/dGame/dComponents/ModelBehaviorComponent.h @@ -7,6 +7,7 @@ #include "eReplicaComponentType.h" class Entity; +enum class ePhysicsBehaviorType : int32_t; /** * Component that represents entities that are a model, e.g. collectible models and BBB models. @@ -29,7 +30,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 @@ -41,10 +42,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 */ @@ -55,8 +71,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..2256fa31 --- /dev/null +++ b/dGame/dComponents/MutableModelBehaviorComponent.h @@ -0,0 +1,53 @@ +#pragma once +#include "dCommonVars.h" +#include "RakNetTypes.h" +#include "NiPoint3.h" +#include "NiQuaternion.h" +#include "Component.h" +#include "eReplicaComponentType.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 eReplicaComponentType ComponentType = eReplicaComponentType::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; +};