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
10 changed files with 51 additions and 24 deletions

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();
entry.handle = syncId;
@@ -55,6 +55,9 @@ void BehaviorContext::RegisterSyncBehavior(const uint32_t syncId, Behavior* beha
entry.branchContext = branchContext;
entry.branchContext.isSync = true;
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);
}
@@ -183,6 +186,21 @@ void BehaviorContext::SyncCalculation(const uint32_t syncId, const float time, B
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) {
std::vector<BehaviorEndEntry> entries;