Compare commits

...

6 Commits

Author SHA1 Message Date
15988afb4c hey it compiles 2023-03-20 21:14:52 -05:00
5e9a956bed Merge branch 'main' into item-component 2023-03-20 21:05:58 -05:00
c2d5be0e5d include 2023-03-20 20:59:11 -05:00
2ae9a92b55 fix cmake 2023-02-10 21:43:39 -06:00
50978620d8 Merge branch 'main' into item-component 2023-02-10 21:35:53 -06:00
c168f6c970 Break out the model component
into the model, item, and mutable model behaviors
2023-02-10 21:33:30 -06:00
10 changed files with 232 additions and 31 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

@@ -70,6 +70,8 @@
#include "RailActivatorComponent.h" #include "RailActivatorComponent.h"
#include "LUPExhibitComponent.h" #include "LUPExhibitComponent.h"
#include "TriggerComponent.h" #include "TriggerComponent.h"
#include "ItemComponent.h"
#include "MutableModelBehaviorComponent.h"
#include "eReplicaComponentType.h" #include "eReplicaComponentType.h"
// Table includes // Table includes
@@ -611,7 +613,7 @@ void Entity::Initialize() {
m_Components.insert(std::make_pair(eReplicaComponentType::SCRIPTED_ACTIVITY, new ScriptedActivityComponent(this, scriptedActivityID))); m_Components.insert(std::make_pair(eReplicaComponentType::SCRIPTED_ACTIVITY, new ScriptedActivityComponent(this, scriptedActivityID)));
} }
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1) != -1 && !GetComponent<PetComponent>()) { if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MODEL, -1) != -1 && !(petComponentId > 0)) {
m_Components.insert(std::make_pair(eReplicaComponentType::MODEL, new ModelComponent(this))); m_Components.insert(std::make_pair(eReplicaComponentType::MODEL, new ModelComponent(this)));
if (m_Components.find(eReplicaComponentType::DESTROYABLE) == m_Components.end()) { if (m_Components.find(eReplicaComponentType::DESTROYABLE) == m_Components.end()) {
auto destroyableComponent = new DestroyableComponent(this); auto destroyableComponent = new DestroyableComponent(this);
@@ -623,8 +625,7 @@ void Entity::Initialize() {
} }
} }
PetComponent* petComponent; if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM) > 0 && !(petComponentId > 0)) {
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM) > 0 && !TryGetComponent(eReplicaComponentType::PET, petComponent) && !HasComponent(eReplicaComponentType::MODEL)) {
m_Components.insert(std::make_pair(eReplicaComponentType::ITEM, nullptr)); m_Components.insert(std::make_pair(eReplicaComponentType::ITEM, nullptr));
} }
@@ -1100,8 +1101,9 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType
characterComponent->Serialize(outBitStream, bIsInitialUpdate, flags); characterComponent->Serialize(outBitStream, bIsInitialUpdate, flags);
} }
if (HasComponent(eReplicaComponentType::ITEM)) { ItemComponent* itemComponent;
outBitStream->Write0(); if (TryGetComponent(eReplicaComponentType::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"
"MutableModelBehaviorComponent.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,50 @@
#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:
static const eReplicaComponentType ComponentType = eReplicaComponentType::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(eReplicaComponentType::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

@@ -7,6 +7,7 @@
#include "eReplicaComponentType.h" #include "eReplicaComponentType.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.
@@ -29,7 +30,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
@@ -41,10 +42,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
*/ */
@@ -55,8 +71,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,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;
};