Resolve many issues with invisible enemies and End Behavior nodes not firing (#1044)

* Finall fix invisible enemies

* Add garbage collection

* Add comment

* Add constexpr for lagFrames
This commit is contained in:
David Markowitz 2023-04-05 06:57:47 -07:00 committed by GitHub
parent 3202b5a36e
commit 541250176c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 51 additions and 24 deletions

View File

@ -13,7 +13,7 @@ void AirMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bi
return; return;
} }
context->RegisterSyncBehavior(handle, this, branch); context->RegisterSyncBehavior(handle, this, branch, this->m_Timeout);
} }
void AirMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { void AirMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
@ -47,4 +47,5 @@ void AirMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitS
} }
void AirMovementBehavior::Load() { void AirMovementBehavior::Load() {
this->m_Timeout = (GetFloat("timeout_ms") / 1000.0f);
} }

View File

@ -4,13 +4,7 @@
class AirMovementBehavior final : public Behavior class AirMovementBehavior final : public Behavior
{ {
public: public:
explicit AirMovementBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {}
/*
* Inherited
*/
explicit AirMovementBehavior(const uint32_t behavior_id) : Behavior(behavior_id) {
}
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
@ -19,4 +13,6 @@ public:
void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void Load() override; void Load() override;
private:
float m_Timeout;
}; };

View File

@ -13,7 +13,7 @@ void AttackDelayBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bi
}; };
for (auto i = 0u; i < this->m_numIntervals; ++i) { for (auto i = 0u; i < this->m_numIntervals; ++i) {
context->RegisterSyncBehavior(handle, this, branch, m_ignoreInterrupts); context->RegisterSyncBehavior(handle, this, branch, m_ignoreInterrupts, this->m_delay * i);
} }
} }

View File

@ -47,7 +47,7 @@ uint32_t BehaviorContext::GetUniqueSkillId() const {
} }
void BehaviorContext::RegisterSyncBehavior(const uint32_t syncId, Behavior* behavior, const BehaviorBranchContext& branchContext, bool ignoreInterrupts) { void BehaviorContext::RegisterSyncBehavior(const uint32_t syncId, Behavior* behavior, const BehaviorBranchContext& branchContext, const float duration, bool ignoreInterrupts) {
auto entry = BehaviorSyncEntry(); auto entry = BehaviorSyncEntry();
entry.handle = syncId; entry.handle = syncId;
@ -55,6 +55,9 @@ void BehaviorContext::RegisterSyncBehavior(const uint32_t syncId, Behavior* beha
entry.branchContext = branchContext; entry.branchContext = branchContext;
entry.branchContext.isSync = true; entry.branchContext.isSync = true;
entry.ignoreInterrupts = ignoreInterrupts; entry.ignoreInterrupts = ignoreInterrupts;
// Add 10 seconds + duration time to account for lag and give clients time to send their syncs to the server.
constexpr float lagTime = 10.0f;
entry.time = lagTime + duration;
this->syncEntries.push_back(entry); this->syncEntries.push_back(entry);
} }
@ -183,6 +186,21 @@ void BehaviorContext::SyncCalculation(const uint32_t syncId, const float time, B
this->syncEntries.push_back(entry); this->syncEntries.push_back(entry);
} }
void BehaviorContext::UpdatePlayerSyncs(float deltaTime) {
uint32_t i = 0;
while (i < this->syncEntries.size()) {
auto& entry = this->syncEntries.at(i);
entry.time -= deltaTime;
if (entry.time >= 0.0f) {
i++;
continue;
}
this->syncEntries.erase(this->syncEntries.begin() + i);
}
}
void BehaviorContext::InvokeEnd(const uint32_t id) { void BehaviorContext::InvokeEnd(const uint32_t id) {
std::vector<BehaviorEndEntry> entries; std::vector<BehaviorEndEntry> entries;

View File

@ -80,7 +80,9 @@ struct BehaviorContext
uint32_t GetUniqueSkillId() const; uint32_t GetUniqueSkillId() const;
void RegisterSyncBehavior(uint32_t syncId, Behavior* behavior, const BehaviorBranchContext& branchContext, bool ignoreInterrupts = false); void UpdatePlayerSyncs(float deltaTime);
void RegisterSyncBehavior(uint32_t syncId, Behavior* behavior, const BehaviorBranchContext& branchContext, const float duration, bool ignoreInterrupts = false);
void RegisterTimerBehavior(Behavior* behavior, const BehaviorBranchContext& branchContext, LWOOBJID second = LWOOBJID_EMPTY); void RegisterTimerBehavior(Behavior* behavior, const BehaviorBranchContext& branchContext, LWOOBJID second = LWOOBJID_EMPTY);

View File

@ -12,7 +12,7 @@ void ChargeUpBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitSt
return; return;
}; };
context->RegisterSyncBehavior(handle, this, branch); context->RegisterSyncBehavior(handle, this, branch, this->m_MaxDuration);
} }
void ChargeUpBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { void ChargeUpBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
@ -24,4 +24,5 @@ void ChargeUpBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStre
void ChargeUpBehavior::Load() { void ChargeUpBehavior::Load() {
this->m_action = GetAction("action"); this->m_action = GetAction("action");
this->m_MaxDuration = GetFloat("max_duration");
} }

View File

@ -4,14 +4,7 @@
class ChargeUpBehavior final : public Behavior class ChargeUpBehavior final : public Behavior
{ {
public: public:
Behavior* m_action; explicit ChargeUpBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {}
/*
* Inherited
*/
explicit ChargeUpBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
}
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
@ -20,4 +13,7 @@ public:
void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void Load() override; void Load() override;
private:
Behavior* m_action;
float m_MaxDuration;
}; };

View File

@ -16,7 +16,7 @@ void ForceMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream*
Game::logger->Log("ForceMovementBehavior", "Unable to read handle from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits()); Game::logger->Log("ForceMovementBehavior", "Unable to read handle from bitStream, aborting Handle! %i", bitStream->GetNumberOfUnreadBits());
return; return;
} }
context->RegisterSyncBehavior(handle, this, branch); context->RegisterSyncBehavior(handle, this, branch, this->m_Duration);
} }
void ForceMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { void ForceMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {

View File

@ -134,6 +134,10 @@ void SkillComponent::Update(const float deltaTime) {
CalculateUpdate(deltaTime); CalculateUpdate(deltaTime);
} }
if (m_Parent->IsPlayer()) {
for (const auto& pair : this->m_managedBehaviors) pair.second->UpdatePlayerSyncs(deltaTime);
}
std::map<uint32_t, BehaviorContext*> keep{}; std::map<uint32_t, BehaviorContext*> keep{};
for (const auto& pair : this->m_managedBehaviors) { for (const auto& pair : this->m_managedBehaviors) {
@ -192,7 +196,15 @@ void SkillComponent::Interrupt() {
auto* combat = m_Parent->GetComponent<BaseCombatAIComponent>(); auto* combat = m_Parent->GetComponent<BaseCombatAIComponent>();
if (combat != nullptr && combat->GetStunImmune()) return; if (combat != nullptr && combat->GetStunImmune()) return;
for (const auto& behavior : this->m_managedBehaviors) behavior.second->Interrupt(); for (const auto& behavior : this->m_managedBehaviors) {
for (const auto& behaviorEndEntry : behavior.second->endEntries) {
behaviorEndEntry.behavior->End(behavior.second, behaviorEndEntry.branchContext, behaviorEndEntry.second);
}
behavior.second->endEntries.clear();
if (m_Parent->IsPlayer()) continue;
behavior.second->Interrupt();
}
} }
void SkillComponent::RegisterCalculatedProjectile(const LWOOBJID projectileId, BehaviorContext* context, const BehaviorBranchContext& branch, const LOT lot, const float maxTime, void SkillComponent::RegisterCalculatedProjectile(const LWOOBJID projectileId, BehaviorContext* context, const BehaviorBranchContext& branch, const LOT lot, const float maxTime,

View File

@ -22,6 +22,7 @@
<phrases> <phrases>
<phrase>I hope quickbulds are still working!</phrase> <phrase>I hope quickbulds are still working!</phrase>
<phrase>Be careful crossing the gap!</phrase> <phrase>Be careful crossing the gap!</phrase>
<phrase>Have The Maelstrom stopped going invisible?</phrase>
</phrases> </phrases>
<zone id="1800"> <zone id="1800">
<locations> <locations>