From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Wed, 30 Apr 2025 00:51:41 +0000 (-0400) Subject: Fix NPCs stalling when too many exist (#37056) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=e3c3f4898f1d6b9900c84113c84e587dee568659;p=space-station-14.git Fix NPCs stalling when too many exist (#37056) Fix NPC stalling when too many exist --- diff --git a/Content.Server/NPC/HTN/HTNSystem.cs b/Content.Server/NPC/HTN/HTNSystem.cs index 89b4ae7786..4d9e321dd9 100644 --- a/Content.Server/NPC/HTN/HTNSystem.cs +++ b/Content.Server/NPC/HTN/HTNSystem.cs @@ -180,11 +180,24 @@ public sealed class HTNSystem : EntitySystem _planQueue.Process(); var query = EntityQueryEnumerator(); + // Move ahead "count" entries in the query. + // This is to ensure that if we didn't process all the npcs the first time, + // we get to the remaining ones instead of iterating over the beginning again. + for (var i = 0; i < count; i++) + { + query.MoveNext(out _, out _); + } + + // the amount of updates we've processed during this iteration. + var updates = 0; while (query.MoveNext(out var uid, out _, out var comp)) { // If we're over our max count or it's not MapInit then ignore the NPC. - if (count >= maxUpdates) - break; + if (updates >= maxUpdates) + { + // Intentional return. We don't want to go to the end logic and reset count. + return; + } if (!comp.Enabled) continue; @@ -274,7 +287,12 @@ public sealed class HTNSystem : EntitySystem Update(comp, frameTime); count++; + updates++; } + + // only reset our counter back to 0 if we finish iterating. + // otherwise it lets us know where we left off. + count = 0; } private void AppendDebugText(HTNTask task, StringBuilder text, List planBtr, List btr, ref int level) diff --git a/Content.Server/NPC/Systems/NPCSystem.cs b/Content.Server/NPC/Systems/NPCSystem.cs index bc21916976..c7690cb295 100644 --- a/Content.Server/NPC/Systems/NPCSystem.cs +++ b/Content.Server/NPC/Systems/NPCSystem.cs @@ -136,7 +136,6 @@ namespace Content.Server.NPC.Systems if (!Enabled) return; - _count = 0; // Add your system here. _htn.UpdateNPC(ref _count, _maxUpdates, frameTime); }