add running flag

This commit is contained in:
David Markowitz 2024-11-02 21:40:48 -07:00
parent 06897eb2ae
commit 56ec037eb6
3 changed files with 23 additions and 0 deletions

View File

@ -15,6 +15,7 @@ ModelComponent::ModelComponent(Entity* parent) : Component(parent) {
m_OriginalRotation = m_Parent->GetDefaultRotation(); m_OriginalRotation = m_Parent->GetDefaultRotation();
m_userModelID = m_Parent->GetVarAs<LWOOBJID>(u"userModelID"); m_userModelID = m_Parent->GetVarAs<LWOOBJID>(u"userModelID");
m_Running = false;
} }
void ModelComponent::LoadBehaviors() { void ModelComponent::LoadBehaviors() {
@ -67,6 +68,7 @@ void ModelComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialU
} }
void ModelComponent::Update(float deltaTime) { 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);
} }

View File

@ -116,7 +116,11 @@ public:
std::array<std::pair<int32_t, std::string>, 5> GetBehaviorsForSave() const; 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: private:
bool m_Running;
/** /**
* The behaviors of the model * The behaviors of the model
* Note: This is a vector because the order of the behaviors matters when serializing to the client. * 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 // Push equipped items
if (inventoryComponent) inventoryComponent->PushEquippedItems(); 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() { void PropertyManagementComponent::OnFinishBuilding() {
@ -265,6 +274,14 @@ void PropertyManagementComponent::OnFinishBuilding() {
UpdateApprovedStatus(false); UpdateApprovedStatus(false);
Save(); 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) { void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const NiPoint3 position, NiQuaternion rotation) {