Compare commits

...

4 Commits

Author SHA1 Message Date
David Markowitz
b79406c27d f 2024-11-10 12:12:45 -08:00
David Markowitz
ff1523b43f pass model component to update 2024-11-03 21:40:36 -08:00
David Markowitz
56ec037eb6 add running flag 2024-11-02 21:40:48 -07:00
David Markowitz
06897eb2ae ad a bunch of update methods 2024-11-02 21:31:54 -07:00
11 changed files with 110 additions and 21 deletions

View File

@@ -15,6 +15,7 @@ ModelComponent::ModelComponent(Entity* parent) : Component(parent) {
m_OriginalRotation = m_Parent->GetDefaultRotation();
m_userModelID = m_Parent->GetVarAs<LWOOBJID>(u"userModelID");
m_Running = false;
}
void ModelComponent::LoadBehaviors() {
@@ -66,6 +67,11 @@ void ModelComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialU
if (bIsInitialUpdate) outBitStream.Write0(); // We are not writing model editing info
}
void ModelComponent::Update(float deltaTime) {
if (!m_Running) return;
for (auto& behavior : m_Behaviors) behavior.Update(deltaTime, *this);
}
void ModelComponent::UpdatePendingBehaviorId(const int32_t newId) {
for (auto& behavior : m_Behaviors) if (behavior.GetBehaviorId() == -1) behavior.SetBehaviorId(newId);
}

View File

@@ -29,6 +29,8 @@ public:
ModelComponent(Entity* parent);
void Update(float deltaTime) override;
void LoadBehaviors();
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
@@ -114,7 +116,11 @@ public:
std::array<std::pair<int32_t, std::string>, 5> GetBehaviorsForSave() const;
void SetIsRunning(bool isRunning) { m_Running = isRunning; }
bool GetIsRunning() const { return m_Running; }
private:
bool m_Running;
/**
* The behaviors of the model
* Note: This is a vector because the order of the behaviors matters when serializing to the client.

View File

@@ -253,6 +253,15 @@ void PropertyManagementComponent::OnStartBuilding() {
// Push equipped items
if (inventoryComponent) inventoryComponent->PushEquippedItems();
for (const auto obj : models | std::views::keys) {
auto* const model = Game::entityManager->GetEntity(obj);
if (!model) continue;
auto* const modelComponent = model->GetComponent<ModelComponent>();
if (modelComponent) modelComponent->SetIsRunning(false);
}
}
void PropertyManagementComponent::OnFinishBuilding() {
@@ -265,6 +274,14 @@ void PropertyManagementComponent::OnFinishBuilding() {
UpdateApprovedStatus(false);
Save();
for (const auto obj : models | std::views::keys) {
auto* const model = Game::entityManager->GetEntity(obj);
if (!model) continue;
auto* const modelComponent = model->GetComponent<ModelComponent>();
if (modelComponent) modelComponent->SetIsRunning(true);
}
}
void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const NiPoint3 position, NiQuaternion rotation) {

View File

@@ -22,6 +22,26 @@ Action::Action(const AMFArrayValue& arguments) {
}
}
void Action::Update(float deltaTime, const ModelComponent& modelComponent) {
// Do nothing
if (Running()) return;
// model component default speed is 3.0f
if (m_Type == "FlyUp") {
} else if (m_Type == "FlyDown") {
}
}
bool Action::Done() const noexcept {
return true;
}
bool Action::Running() const noexcept {
return false;
}
void Action::SendBehaviorBlocksToClient(AMFArrayValue& args) const {
auto* const actionArgs = args.PushArray();
actionArgs->Insert("Type", m_Type);

View File

@@ -8,6 +8,7 @@ namespace tinyxml2 {
};
class AMFArrayValue;
class ModelComponent;
/**
* @brief Sent if a ControlBehavior message has an Action associated with it
@@ -17,6 +18,13 @@ class Action {
public:
Action() = default;
Action(const AMFArrayValue& arguments);
void Update(float deltaTime, const ModelComponent& modelComponent);
bool Done() const noexcept;
bool Running() const noexcept;
[[nodiscard]] const std::string& GetType() const { return m_Type; };
[[nodiscard]] const std::string& GetValueParameterName() const { return m_ValueParameterName; };
[[nodiscard]] const std::string& GetValueParameterString() const { return m_ValueParameterString; };

View File

@@ -9,6 +9,12 @@ PropertyBehavior::PropertyBehavior() {
m_LastEditedState = BehaviorState::HOME_STATE;
}
void PropertyBehavior::Update(float deltaTime, const ModelComponent& modelComponent) {
for (auto& [stateId, state] : m_States) {
state.Update(deltaTime, modelComponent);
}
}
template<>
void PropertyBehavior::HandleMsg(AddStripMessage& msg) {
m_States[msg.GetActionContext().GetStateId()].HandleMsg(msg);

View File

@@ -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,6 +19,8 @@ class PropertyBehavior {
public:
PropertyBehavior();
void Update(float deltaTime, const ModelComponent& modelComponent);
template <typename Msg>
void HandleMsg(Msg& msg);

View File

@@ -4,13 +4,19 @@
#include "ControlBehaviorMsgs.h"
#include "tinyxml2.h"
void State::Update(float deltaTime, const ModelComponent& modelComponent) {
for (auto& strip : m_Strips) {
strip.Update(deltaTime, modelComponent);
}
}
template <>
void State::HandleMsg(AddStripMessage& msg) {
if (m_Strips.size() <= msg.GetActionContext().GetStripId()) {
m_Strips.resize(msg.GetActionContext().GetStripId() + 1);
}
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
};
}
template <>
void State::HandleMsg(AddActionMessage& msg) {
@@ -19,7 +25,7 @@ void State::HandleMsg(AddActionMessage& msg) {
}
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
};
}
template <>
void State::HandleMsg(UpdateStripUiMessage& msg) {
@@ -28,7 +34,7 @@ void State::HandleMsg(UpdateStripUiMessage& msg) {
}
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
};
}
template <>
void State::HandleMsg(RemoveActionsMessage& msg) {
@@ -37,7 +43,7 @@ void State::HandleMsg(RemoveActionsMessage& msg) {
}
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
};
}
template <>
void State::HandleMsg(RearrangeStripMessage& msg) {
@@ -46,7 +52,7 @@ void State::HandleMsg(RearrangeStripMessage& msg) {
}
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
};
}
template <>
void State::HandleMsg(UpdateActionMessage& msg) {
@@ -55,7 +61,7 @@ void State::HandleMsg(UpdateActionMessage& msg) {
}
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
};
}
template <>
void State::HandleMsg(RemoveStripMessage& msg) {
@@ -64,7 +70,7 @@ void State::HandleMsg(RemoveStripMessage& msg) {
}
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
};
}
template <>
void State::HandleMsg(SplitStripMessage& msg) {
@@ -81,7 +87,7 @@ void State::HandleMsg(SplitStripMessage& msg) {
m_Strips.at(msg.GetDestinationActionContext().GetStripId()).HandleMsg(msg);
}
};
}
template <>
void State::HandleMsg(MergeStripsMessage& msg) {
@@ -98,7 +104,7 @@ void State::HandleMsg(MergeStripsMessage& msg) {
m_Strips.at(msg.GetDestinationActionContext().GetStripId()).HandleMsg(msg);
}
};
}
template <>
void State::HandleMsg(MigrateActionsMessage& msg) {
@@ -115,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) {

View File

@@ -8,9 +8,12 @@ namespace tinyxml2 {
}
class AMFArrayValue;
class ModelComponent;
class State {
public:
void Update(float deltaTime, const ModelComponent& modelComponent);
template <typename Msg>
void HandleMsg(Msg& msg);

View File

@@ -4,45 +4,54 @@
#include "ControlBehaviorMsgs.h"
#include "tinyxml2.h"
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, modelComponent);
LOG("Running action %s", action.GetType().c_str());
if (action.Done()) m_ActionIndex++;
}
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) {
@@ -54,7 +63,7 @@ void Strip::HandleMsg(SplitStripMessage& msg) {
m_Actions = msg.GetTransferredActions();
m_Position = msg.GetPosition();
}
};
}
template <>
void Strip::HandleMsg(MergeStripsMessage& msg) {
@@ -64,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) {
@@ -75,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);

View File

@@ -11,9 +11,12 @@ namespace tinyxml2 {
}
class AMFArrayValue;
class ModelComponent;
class Strip {
public:
void Update(float deltaTime, const ModelComponent& modelComponent);
template <typename Msg>
void HandleMsg(Msg& msg);
@@ -23,6 +26,8 @@ public:
void Serialize(tinyxml2::XMLElement& strip) const;
void Deserialize(const tinyxml2::XMLElement& strip);
private:
uint32_t m_ActionIndex{ 0 };
std::vector<Action> m_Actions;
StripUiPosition m_Position;
};