mirror of
				https://github.com/DarkflameUniverse/DarkflameServer.git
				synced 2025-11-03 22:21:59 +00:00 
			
		
		
		
	pass model component to update
This commit is contained in:
		@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@ Action::Action(const AMFArrayValue& arguments) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Action::Update(float deltaTime) {
 | 
			
		||||
void Action::Update(float deltaTime, const ModelComponent& modelComponent) {
 | 
			
		||||
	// Do nothing
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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 <typename Msg>
 | 
			
		||||
	void HandleMsg(Msg& msg);
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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 <typename Msg>
 | 
			
		||||
	void HandleMsg(Msg& msg);
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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 <typename Msg>
 | 
			
		||||
	void HandleMsg(Msg& msg);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user