diff --git a/dGame/dComponents/ModelComponent.cpp b/dGame/dComponents/ModelComponent.cpp index 27ebd81f..d072dbf2 100644 --- a/dGame/dComponents/ModelComponent.cpp +++ b/dGame/dComponents/ModelComponent.cpp @@ -69,7 +69,7 @@ void ModelComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialU void ModelComponent::Update(float deltaTime) { if (!m_Running) return; - for (auto& behavior : m_Behaviors) behavior.Update(deltaTime); + for (auto& behavior : m_Behaviors) behavior.Update(deltaTime, *this); } void ModelComponent::UpdatePendingBehaviorId(const int32_t newId) { diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp index 2fb98e41..ba2123ef 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.cpp @@ -22,7 +22,7 @@ Action::Action(const AMFArrayValue& arguments) { } } -void Action::Update(float deltaTime) { +void Action::Update(float deltaTime, const ModelComponent& modelComponent) { // Do nothing } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h index ee333d12..739ee219 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/Action.h @@ -8,6 +8,7 @@ namespace tinyxml2 { }; class AMFArrayValue; +class ModelComponent; /** * @brief Sent if a ControlBehavior message has an Action associated with it @@ -18,7 +19,7 @@ public: Action() = default; Action(const AMFArrayValue& arguments); - void Update(float deltaTime); + void Update(float deltaTime, const ModelComponent& modelComponent); bool Done() const noexcept; diff --git a/dGame/dPropertyBehaviors/PropertyBehavior.cpp b/dGame/dPropertyBehaviors/PropertyBehavior.cpp index 08c0aa88..bd892840 100644 --- a/dGame/dPropertyBehaviors/PropertyBehavior.cpp +++ b/dGame/dPropertyBehaviors/PropertyBehavior.cpp @@ -9,9 +9,9 @@ PropertyBehavior::PropertyBehavior() { m_LastEditedState = BehaviorState::HOME_STATE; } -void PropertyBehavior::Update(float deltaTime) { +void PropertyBehavior::Update(float deltaTime, const ModelComponent& modelComponent) { for (auto& [stateId, state] : m_States) { - state.Update(deltaTime); + state.Update(deltaTime, modelComponent); } } diff --git a/dGame/dPropertyBehaviors/PropertyBehavior.h b/dGame/dPropertyBehaviors/PropertyBehavior.h index 63ef548f..156cfc70 100644 --- a/dGame/dPropertyBehaviors/PropertyBehavior.h +++ b/dGame/dPropertyBehaviors/PropertyBehavior.h @@ -10,6 +10,7 @@ namespace tinyxml2 { enum class BehaviorState : uint32_t; class AMFArrayValue; +class ModelComponent; /** * Represents the Entity of a Property Behavior and holds data associated with the behavior @@ -18,7 +19,7 @@ class PropertyBehavior { public: PropertyBehavior(); - void Update(float deltaTime); + void Update(float deltaTime, const ModelComponent& modelComponent); template void HandleMsg(Msg& msg); diff --git a/dGame/dPropertyBehaviors/State.cpp b/dGame/dPropertyBehaviors/State.cpp index 561e9eef..65048a43 100644 --- a/dGame/dPropertyBehaviors/State.cpp +++ b/dGame/dPropertyBehaviors/State.cpp @@ -4,9 +4,9 @@ #include "ControlBehaviorMsgs.h" #include "tinyxml2.h" -void State::Update(float deltaTime) { +void State::Update(float deltaTime, const ModelComponent& modelComponent) { for (auto& strip : m_Strips) { - strip.Update(deltaTime); + strip.Update(deltaTime, modelComponent); } } @@ -16,7 +16,7 @@ void State::HandleMsg(AddStripMessage& msg) { m_Strips.resize(msg.GetActionContext().GetStripId() + 1); } m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); -}; +} template <> void State::HandleMsg(AddActionMessage& msg) { @@ -25,7 +25,7 @@ void State::HandleMsg(AddActionMessage& msg) { } m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); -}; +} template <> void State::HandleMsg(UpdateStripUiMessage& msg) { @@ -34,7 +34,7 @@ void State::HandleMsg(UpdateStripUiMessage& msg) { } m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); -}; +} template <> void State::HandleMsg(RemoveActionsMessage& msg) { @@ -43,7 +43,7 @@ void State::HandleMsg(RemoveActionsMessage& msg) { } m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); -}; +} template <> void State::HandleMsg(RearrangeStripMessage& msg) { @@ -52,7 +52,7 @@ void State::HandleMsg(RearrangeStripMessage& msg) { } m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); -}; +} template <> void State::HandleMsg(UpdateActionMessage& msg) { @@ -61,7 +61,7 @@ void State::HandleMsg(UpdateActionMessage& msg) { } m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); -}; +} template <> void State::HandleMsg(RemoveStripMessage& msg) { @@ -70,7 +70,7 @@ void State::HandleMsg(RemoveStripMessage& msg) { } m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg); -}; +} template <> void State::HandleMsg(SplitStripMessage& msg) { @@ -87,7 +87,7 @@ void State::HandleMsg(SplitStripMessage& msg) { m_Strips.at(msg.GetDestinationActionContext().GetStripId()).HandleMsg(msg); } -}; +} template <> void State::HandleMsg(MergeStripsMessage& msg) { @@ -104,7 +104,7 @@ void State::HandleMsg(MergeStripsMessage& msg) { m_Strips.at(msg.GetDestinationActionContext().GetStripId()).HandleMsg(msg); } -}; +} template <> void State::HandleMsg(MigrateActionsMessage& msg) { @@ -121,7 +121,7 @@ void State::HandleMsg(MigrateActionsMessage& msg) { m_Strips.at(msg.GetDestinationActionContext().GetStripId()).HandleMsg(msg); } -}; +} bool State::IsEmpty() const { for (const auto& strip : m_Strips) { diff --git a/dGame/dPropertyBehaviors/State.h b/dGame/dPropertyBehaviors/State.h index 9c49bae1..32713475 100644 --- a/dGame/dPropertyBehaviors/State.h +++ b/dGame/dPropertyBehaviors/State.h @@ -8,10 +8,11 @@ namespace tinyxml2 { } class AMFArrayValue; +class ModelComponent; class State { public: - void Update(float deltaTime); + void Update(float deltaTime, const ModelComponent& modelComponent); template void HandleMsg(Msg& msg); diff --git a/dGame/dPropertyBehaviors/Strip.cpp b/dGame/dPropertyBehaviors/Strip.cpp index 1af21f9d..b31519d4 100644 --- a/dGame/dPropertyBehaviors/Strip.cpp +++ b/dGame/dPropertyBehaviors/Strip.cpp @@ -4,11 +4,11 @@ #include "ControlBehaviorMsgs.h" #include "tinyxml2.h" -void Strip::Update(float deltaTime) { +void Strip::Update(float deltaTime, const ModelComponent& modelComponent) { if (m_Actions.empty() || m_ActionIndex >= m_Actions.size()) return; auto& action = m_Actions[m_ActionIndex]; - action.Update(deltaTime); + action.Update(deltaTime, modelComponent); LOG("Running action %s", action.GetType().c_str()); if (action.Done()) m_ActionIndex++; } @@ -17,41 +17,41 @@ template <> void Strip::HandleMsg(AddStripMessage& msg) { m_Actions = msg.GetActionsToAdd(); m_Position = msg.GetPosition(); -}; +} template <> void Strip::HandleMsg(AddActionMessage& msg) { if (msg.GetActionIndex() == -1) return; - m_Actions.insert(m_Actions.begin() + msg.GetActionIndex(), msg.GetAction()); -}; + auto newAction = m_Actions.insert(m_Actions.begin() + msg.GetActionIndex(), msg.GetAction()); +} template <> void Strip::HandleMsg(UpdateStripUiMessage& msg) { m_Position = msg.GetPosition(); -}; +} template <> void Strip::HandleMsg(RemoveStripMessage& msg) { m_Actions.clear(); -}; +} template <> void Strip::HandleMsg(RemoveActionsMessage& msg) { if (msg.GetActionIndex() >= m_Actions.size()) return; m_Actions.erase(m_Actions.begin() + msg.GetActionIndex(), m_Actions.end()); -}; +} template <> void Strip::HandleMsg(UpdateActionMessage& msg) { if (msg.GetActionIndex() >= m_Actions.size()) return; m_Actions.at(msg.GetActionIndex()) = msg.GetAction(); -}; +} template <> void Strip::HandleMsg(RearrangeStripMessage& msg) { if (msg.GetDstActionIndex() >= m_Actions.size() || msg.GetSrcActionIndex() >= m_Actions.size() || msg.GetSrcActionIndex() <= msg.GetDstActionIndex()) return; std::rotate(m_Actions.begin() + msg.GetDstActionIndex(), m_Actions.begin() + msg.GetSrcActionIndex(), m_Actions.end()); -}; +} template <> void Strip::HandleMsg(SplitStripMessage& msg) { @@ -63,7 +63,7 @@ void Strip::HandleMsg(SplitStripMessage& msg) { m_Actions = msg.GetTransferredActions(); m_Position = msg.GetPosition(); } -}; +} template <> void Strip::HandleMsg(MergeStripsMessage& msg) { @@ -73,7 +73,7 @@ void Strip::HandleMsg(MergeStripsMessage& msg) { } else { m_Actions.insert(m_Actions.begin() + msg.GetDstActionIndex(), msg.GetMigratedActions().begin(), msg.GetMigratedActions().end()); } -}; +} template <> void Strip::HandleMsg(MigrateActionsMessage& msg) { @@ -84,7 +84,7 @@ void Strip::HandleMsg(MigrateActionsMessage& msg) { } else { m_Actions.insert(m_Actions.begin() + msg.GetDstActionIndex(), msg.GetMigratedActions().begin(), msg.GetMigratedActions().end()); } -}; +} void Strip::SendBehaviorBlocksToClient(AMFArrayValue& args) const { m_Position.SendBehaviorBlocksToClient(args); diff --git a/dGame/dPropertyBehaviors/Strip.h b/dGame/dPropertyBehaviors/Strip.h index 591f28ce..0a3aacb9 100644 --- a/dGame/dPropertyBehaviors/Strip.h +++ b/dGame/dPropertyBehaviors/Strip.h @@ -11,10 +11,11 @@ namespace tinyxml2 { } class AMFArrayValue; +class ModelComponent; class Strip { public: - void Update(float deltaTime); + void Update(float deltaTime, const ModelComponent& modelComponent); template void HandleMsg(Msg& msg);