Break out the model component

into the model, item, and mutable model behaviors
This commit is contained in:
Aaron Kimbre 2023-02-10 21:33:30 -06:00
parent d17f51183e
commit c168f6c970
10 changed files with 231 additions and 32 deletions

View File

@ -0,0 +1,14 @@
#ifndef __EPHYSICSBEHAVIORTYPE__H__
#define __EPHYSICSBEHAVIORTYPE__H__
#include <cstdint>
enum class ePhysicsBehaviorType : int32_t {
INVALID = -1,
GROUND,
FLYING,
STANDARD,
DYNAMIC
};
#endif //!__EPHYSICSBEHAVIORTYPE__H__

View File

@ -0,0 +1,13 @@
#ifndef __EUGCMODERATIONSTATUS__H__
#define __EUGCMODERATIONSTATUS__H__
#include <cstdint>
enum class eUgcModerationStatus : uint32_t {
NoStatus,
Approved,
Rejected,
};
#endif //!__EUGCMODERATIONSTATUS__H__

View File

@ -68,6 +68,7 @@
#include "ShootingGalleryComponent.h" #include "ShootingGalleryComponent.h"
#include "RailActivatorComponent.h" #include "RailActivatorComponent.h"
#include "LUPExhibitComponent.h" #include "LUPExhibitComponent.h"
#include "ItemComponent.h"
Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity) { Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity) {
m_ObjectID = objectID; m_ObjectID = objectID;
@ -618,7 +619,7 @@ void Entity::Initialize() {
m_Components.insert(std::make_pair(COMPONENT_TYPE_SCRIPTED_ACTIVITY, new ScriptedActivityComponent(this, scriptedActivityID))); 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<PetComponent>()) { if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MODEL, -1) != -1 && !(petComponentId > 0)) {
m_Components.insert(std::make_pair(COMPONENT_TYPE_MODEL, new ModelComponent(this))); m_Components.insert(std::make_pair(COMPONENT_TYPE_MODEL, new ModelComponent(this)));
if (m_Components.find(COMPONENT_TYPE_DESTROYABLE) == m_Components.end()) { if (m_Components.find(COMPONENT_TYPE_DESTROYABLE) == m_Components.end()) {
auto destroyableComponent = new DestroyableComponent(this); 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)) { if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_ITEM) > 0 && !(petComponentId > 0)) {
m_Components.insert(std::make_pair(COMPONENT_TYPE_ITEM, nullptr)); m_Components.emplace(COMPONENT_TYPE_ITEM, new ItemComponent(this));
} }
// Shooting gallery component // Shooting gallery component
@ -1103,8 +1104,9 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType
characterComponent->Serialize(outBitStream, bIsInitialUpdate, flags); characterComponent->Serialize(outBitStream, bIsInitialUpdate, flags);
} }
if (HasComponent(COMPONENT_TYPE_ITEM)) { ItemComponent* itemComponent;
outBitStream->Write0(); if (TryGetComponent(COMPONENT_TYPE_ITEM, itemComponent)) {
itemComponent->Serialize(outBitStream, bIsInitialUpdate, flags);
} }
InventoryComponent* inventoryComponent; InventoryComponent* inventoryComponent;

View File

@ -7,6 +7,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp"
"ControllablePhysicsComponent.cpp" "ControllablePhysicsComponent.cpp"
"DestroyableComponent.cpp" "DestroyableComponent.cpp"
"InventoryComponent.cpp" "InventoryComponent.cpp"
"ItemComponent.cpp"
"LevelProgressionComponent.cpp" "LevelProgressionComponent.cpp"
"LUPExhibitComponent.cpp" "LUPExhibitComponent.cpp"
"MissionComponent.cpp" "MissionComponent.cpp"
@ -15,6 +16,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp"
"ModuleAssemblyComponent.cpp" "ModuleAssemblyComponent.cpp"
"MovementAIComponent.cpp" "MovementAIComponent.cpp"
"MovingPlatformComponent.cpp" "MovingPlatformComponent.cpp"
"MutableModelBehaviorCoponent.cpp"
"PetComponent.cpp" "PetComponent.cpp"
"PhantomPhysicsComponent.cpp" "PhantomPhysicsComponent.cpp"
"PlayerForcedMovementComponent.cpp" "PlayerForcedMovementComponent.cpp"

View File

@ -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<LWOOBJID>(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<uint32_t>(m_UgDescription.length());
for (uint16_t character : m_UgDescription) outBitStream->Write(character);
}
m_DirtyItemInfo = false;
}
}

View File

@ -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;
};

View File

@ -1,31 +1,23 @@
#include "ModelComponent.h" #include "ModelComponent.h"
#include "Entity.h" #include "Entity.h"
#include "ePhysicsBehaviorType.h"
ModelComponent::ModelComponent(Entity* parent) : Component(parent) { ModelComponent::ModelComponent(Entity* parent) : Component(parent) {
m_DirtyModelInfo = false;
m_IsPickable = false;
m_PhysicsType = ePhysicsBehaviorType::STANDARD;
m_OriginalPosition = m_Parent->GetDefaultPosition(); m_OriginalPosition = m_Parent->GetDefaultPosition();
m_OriginalRotation = m_Parent->GetDefaultRotation(); m_OriginalRotation = m_Parent->GetDefaultRotation();
m_userModelID = m_Parent->GetVarAs<LWOOBJID>(u"userModelID");
} }
void ModelComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { void ModelComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
// ItemComponent Serialization. Pets do not get this serialization. outBitStream->Write(m_DirtyModelInfo || bIsInitialUpdate);
if (!m_Parent->HasComponent(COMPONENT_TYPE_PET)) { if (m_DirtyModelInfo || bIsInitialUpdate) {
outBitStream->Write1(); outBitStream->Write(m_IsPickable);
outBitStream->Write<LWOOBJID>(m_userModelID != LWOOBJID_EMPTY ? m_userModelID : m_Parent->GetObjectID()); outBitStream->Write(m_PhysicsType);
outBitStream->Write<int>(0); outBitStream->Write(m_OriginalPosition);
outBitStream->Write0(); outBitStream->Write(m_OriginalRotation);
m_DirtyModelInfo = false;
} }
//actual model component:
outBitStream->Write1(); // Yes we are writing model info
outBitStream->Write0(); // Is pickable
outBitStream->Write<uint32_t>(2); // Physics type
outBitStream->Write(m_OriginalPosition); // Original position
outBitStream->Write(m_OriginalRotation); // Original rotation
outBitStream->Write1(); // We are writing behavior info
outBitStream->Write<uint32_t>(0); // Number of behaviors
outBitStream->Write1(); // Is this model paused
if (bIsInitialUpdate) outBitStream->Write0(); // We are not writing model editing info
} }

View File

@ -6,6 +6,7 @@
#include "Component.h" #include "Component.h"
class Entity; class Entity;
enum class ePhysicsBehaviorType : int32_t;
/** /**
* Component that represents entities that are a model, e.g. collectible models and BBB models. * 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 * Sets the original position of the model
* @param pos the original position to set * @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 * Returns the original rotation of the model
@ -40,10 +41,25 @@ public:
* Sets the original rotation of the model * Sets the original rotation of the model
* @param rot the original rotation to set * @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: 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 * The original position of the model
*/ */
@ -54,8 +70,4 @@ private:
*/ */
NiQuaternion m_OriginalRotation; NiQuaternion m_OriginalRotation;
/**
* The ID of the user that made the model
*/
LWOOBJID m_userModelID;
}; };

View File

@ -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;
}
}

View File

@ -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;
};