From e96eed531613a315456c8d0108ca762c3a5f2d2c Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Thu, 3 Apr 2025 00:15:15 -0700 Subject: [PATCH] Add comments, remove dead code etc. --- dGame/dComponents/ModelComponent.cpp | 12 ++++++--- dGame/dComponents/ModelComponent.h | 3 +++ .../PropertyManagementComponent.cpp | 4 --- .../dComponents/PropertyManagementComponent.h | 2 -- dGame/dPropertyBehaviors/PropertyBehavior.cpp | 5 ---- dGame/dPropertyBehaviors/PropertyBehavior.h | 8 ++---- dGame/dPropertyBehaviors/State.h | 5 ++-- dGame/dPropertyBehaviors/Strip.cpp | 26 ++++++++++++------- dGame/dPropertyBehaviors/Strip.h | 14 +++++++--- 9 files changed, 42 insertions(+), 37 deletions(-) diff --git a/dGame/dComponents/ModelComponent.cpp b/dGame/dComponents/ModelComponent.cpp index 99562c6b..6b164995 100644 --- a/dGame/dComponents/ModelComponent.cpp +++ b/dGame/dComponents/ModelComponent.cpp @@ -10,6 +10,7 @@ #include "SimplePhysicsComponent.h" #include "Database.h" +#include "DluAssert.h" ModelComponent::ModelComponent(Entity* parent) : Component(parent) { m_OriginalPosition = m_Parent->GetDefaultPosition(); @@ -36,9 +37,14 @@ bool ModelComponent::OnResetModelToDefaults(GameMessages::GameMsg& msg) { } bool ModelComponent::OnRequestUse(GameMessages::GameMsg& msg) { - auto& requestUse = static_cast(msg); - for (auto& behavior : m_Behaviors) behavior.HandleMsg(requestUse); - return true; + bool toReturn = false; + if (!m_IsPaused) { + auto& requestUse = static_cast(msg); + for (auto& behavior : m_Behaviors) behavior.HandleMsg(requestUse); + toReturn = true; + } + + return toReturn; } void ModelComponent::Update(float deltaTime) { diff --git a/dGame/dComponents/ModelComponent.h b/dGame/dComponents/ModelComponent.h index 636a73df..d16e7daa 100644 --- a/dGame/dComponents/ModelComponent.h +++ b/dGame/dComponents/ModelComponent.h @@ -127,10 +127,13 @@ public: void Resume(); private: + // Whether or not this component needs to have its extra data serialized. bool m_Dirty{}; + // The number of strips listening for a RequestUse GM to come in. uint32_t m_NumListeningInteract{}; + // Whether or not the model is paused and should reject all interactions regarding behaviors. bool m_IsPaused{}; /** * The behaviors of the model diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index 60c5cc80..6b40f575 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -221,8 +221,6 @@ bool PropertyManagementComponent::Claim(const LWOOBJID playerId) { } void PropertyManagementComponent::OnStartBuilding() { - m_IsBuilding = true; - auto* ownerEntity = GetOwner(); if (ownerEntity == nullptr) return; @@ -270,8 +268,6 @@ void PropertyManagementComponent::OnStartBuilding() { } void PropertyManagementComponent::OnFinishBuilding() { - m_IsBuilding = false; - auto* ownerEntity = GetOwner(); if (ownerEntity == nullptr) return; diff --git a/dGame/dComponents/PropertyManagementComponent.h b/dGame/dComponents/PropertyManagementComponent.h index 700b3f02..6a9ed09d 100644 --- a/dGame/dComponents/PropertyManagementComponent.h +++ b/dGame/dComponents/PropertyManagementComponent.h @@ -239,6 +239,4 @@ private: * The privacy setting before it was changed, saved to set back after a player finishes building */ PropertyPrivacyOption originalPrivacyOption = PropertyPrivacyOption::Private; - - bool m_IsBuilding{}; }; diff --git a/dGame/dPropertyBehaviors/PropertyBehavior.cpp b/dGame/dPropertyBehaviors/PropertyBehavior.cpp index ad6af59a..c4c9d359 100644 --- a/dGame/dPropertyBehaviors/PropertyBehavior.cpp +++ b/dGame/dPropertyBehaviors/PropertyBehavior.cpp @@ -169,11 +169,6 @@ void PropertyBehavior::Deserialize(const tinyxml2::XMLElement& behavior) { } } -const State& PropertyBehavior::GetState(const BehaviorState state) { - DluAssert(state >= BehaviorState::HOME_STATE && state <= BehaviorState::STAR_STATE); - return m_States[state]; -} - void PropertyBehavior::Update(float deltaTime, ModelComponent& modelComponent) { for (auto& state : m_States | std::views::values) state.Update(deltaTime, modelComponent); } diff --git a/dGame/dPropertyBehaviors/PropertyBehavior.h b/dGame/dPropertyBehaviors/PropertyBehavior.h index 893306b2..5232d7f0 100644 --- a/dGame/dPropertyBehaviors/PropertyBehavior.h +++ b/dGame/dPropertyBehaviors/PropertyBehavior.h @@ -33,14 +33,10 @@ public: void Serialize(tinyxml2::XMLElement& behavior) const; void Deserialize(const tinyxml2::XMLElement& behavior); - const std::map& GetStates() const { return m_States; } - const State& GetState(const BehaviorState state); - const State& GetActiveState() const { return m_States.at(m_ActiveState); } - State& GetActiveStateMut() { return m_States.at(m_ActiveState); } - void Update(float deltaTime, ModelComponent& modelComponent); -private: +private: + // The current active behavior state. Behaviors can only be in ONE state at a time. BehaviorState m_ActiveState; // The states this behavior has. diff --git a/dGame/dPropertyBehaviors/State.h b/dGame/dPropertyBehaviors/State.h index babc9725..ab6d76a4 100644 --- a/dGame/dPropertyBehaviors/State.h +++ b/dGame/dPropertyBehaviors/State.h @@ -21,11 +21,10 @@ public: void Serialize(tinyxml2::XMLElement& state) const; void Deserialize(const tinyxml2::XMLElement& state); - const std::vector& GetStrips() const { return m_Strips; } - std::vector& GetStripsMut() { return m_Strips; } - void Update(float deltaTime, ModelComponent& modelComponent); private: + + // The strips contained within this state. std::vector m_Strips; }; diff --git a/dGame/dPropertyBehaviors/Strip.cpp b/dGame/dPropertyBehaviors/Strip.cpp index 4ffead9d..f425c6ae 100644 --- a/dGame/dPropertyBehaviors/Strip.cpp +++ b/dGame/dPropertyBehaviors/Strip.cpp @@ -7,6 +7,8 @@ #include "ModelComponent.h" #include "PlayerManager.h" +#include "DluAssert.h" + template <> void Strip::HandleMsg(AddStripMessage& msg) { m_Actions = msg.GetActionsToAdd(); @@ -105,7 +107,7 @@ void Strip::IncrementAction() { void Strip::Spawn(LOT lot, Entity& entity) { EntityInfo info{}; - info.lot = lot; // Dark Ronin property + info.lot = lot; info.pos = entity.GetPosition(); info.rot = NiQuaternionConstant::IDENTITY; info.spawnerID = entity.GetObjectID(); @@ -126,17 +128,17 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) { auto numberAsInt = static_cast(number); auto nextActionType = GetNextAction().GetType(); if (nextActionType == "SpawnStromling") { - Spawn(10495, entity); + Spawn(10495, entity); // Stromling property } else if (nextActionType == "SpawnPirate") { - Spawn(10497, entity); + Spawn(10497, entity); // Maelstrom Pirate property } else if (nextActionType == "SpawnRonin") { - Spawn(10498, entity); + Spawn(10498, entity); // Dark Ronin property } else if (nextActionType == "DropImagination") { - for (; numberAsInt > 0; numberAsInt--) SpawnDrop(935, entity); + for (; numberAsInt > 0; numberAsInt--) SpawnDrop(935, entity); // 1 Imagination powerup } else if (nextActionType == "DropHealth") { - for (; numberAsInt > 0; numberAsInt--) SpawnDrop(177, entity); + for (; numberAsInt > 0; numberAsInt--) SpawnDrop(177, entity); // 1 Life powerup } else if (nextActionType == "DropArmor") { - for (; numberAsInt > 0; numberAsInt--) SpawnDrop(6431, entity); + for (; numberAsInt > 0; numberAsInt--) SpawnDrop(6431, entity); // 1 Armor powerup } else if (nextActionType == "Smash") { GameMessages::Smash smash{}; smash.target = entity.GetObjectID(); @@ -157,10 +159,10 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) { sound.soundID = numberAsInt; sound.Send(UNASSIGNED_SYSTEM_ADDRESS); } else { - static std::set g_PlayedSounds; - if (!g_PlayedSounds.contains(nextActionType.data())) { + static std::set g_WarnedActions; + if (!g_WarnedActions.contains(nextActionType.data())) { LOG("Tried to play action (%s) which is not supported.", nextActionType.data()); - g_PlayedSounds.insert(nextActionType.data()); + g_WarnedActions.insert(nextActionType.data()); } return; } @@ -235,6 +237,10 @@ void Strip::Deserialize(const tinyxml2::XMLElement& strip) { } } +const Action& Strip::GetNextAction() const { + DluAssert(m_NextActionIndex < m_Actions.size()); return m_Actions[m_NextActionIndex]; +} + const Action& Strip::GetPreviousAction() const { DluAssert(m_NextActionIndex < m_Actions.size()); size_t index = m_NextActionIndex == 0 ? m_Actions.size() - 1 : m_NextActionIndex - 1; diff --git a/dGame/dPropertyBehaviors/Strip.h b/dGame/dPropertyBehaviors/Strip.h index d159fb59..3f929a7d 100644 --- a/dGame/dPropertyBehaviors/Strip.h +++ b/dGame/dPropertyBehaviors/Strip.h @@ -4,8 +4,6 @@ #include "Action.h" #include "StripUiPosition.h" -#include "DluAssert.h" - #include namespace tinyxml2 { @@ -26,8 +24,7 @@ public: void Serialize(tinyxml2::XMLElement& strip) const; void Deserialize(const tinyxml2::XMLElement& strip); - const std::vector& GetActions() const { return m_Actions; } - const Action& GetNextAction() const { DluAssert(m_NextActionIndex < m_Actions.size()); return m_Actions[m_NextActionIndex]; } + const Action& GetNextAction() const; const Action& GetPreviousAction() const; void IncrementAction(); @@ -37,10 +34,19 @@ public: void ProcNormalAction(float deltaTime, ModelComponent& modelComponent); void RemoveStates(ModelComponent& modelComponent) const; private: + // Indicates this Strip is waiting for an action to be taken upon it to progress to its actions bool m_WaitingForAction{ false }; + + // The amount of time this strip is paused for. Any interactions with this strip should be bounced if this is greater than 0. float m_PausedTime{ 0.0f }; + + // The index of the next action to be played. This should always be within range of [0, m_Actions.size()). size_t m_NextActionIndex{ 0 }; + + // The list of actions to be executed on this behavior. std::vector m_Actions; + + // The location of this strip on the UGBehaviorEditor UI StripUiPosition m_Position; };