diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs index 6f8568d476..987b77790e 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs @@ -63,7 +63,8 @@ public sealed partial class ExplosionSystem : EntitySystem return; _activeExplosion = null; - _nodeGroupSystem.Snoozing = false; + _nodeGroupSystem.PauseUpdating = false; + _pathfindingSystem.PauseUpdating = false; } /// @@ -107,7 +108,8 @@ public sealed partial class ExplosionSystem : EntitySystem // just a lil nap if (SleepNodeSys) { - _nodeGroupSystem.Snoozing = true; + _nodeGroupSystem.PauseUpdating = true; + _pathfindingSystem.PauseUpdating = true; // snooze grid-chunk regeneration? // snooze power network (recipients look for new suppliers as wires get destroyed). } @@ -136,7 +138,8 @@ public sealed partial class ExplosionSystem : EntitySystem // Ensure the system does not get stuck in an error-loop. _activeExplosion = null; RaiseNetworkEvent(new ExplosionOverlayUpdateEvent(_explosionCounter, int.MaxValue)); - _nodeGroupSystem.Snoozing = false; + _nodeGroupSystem.PauseUpdating = false; + _pathfindingSystem.PauseUpdating = false; throw; } #endif @@ -163,7 +166,8 @@ public sealed partial class ExplosionSystem : EntitySystem RaiseNetworkEvent(new ExplosionOverlayUpdateEvent(_explosionCounter, int.MaxValue)); //wakey wakey - _nodeGroupSystem.Snoozing = false; + _nodeGroupSystem.PauseUpdating = false; + _pathfindingSystem.PauseUpdating = false; } /// diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs index 21e45aef93..1d4b5b5998 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs @@ -3,6 +3,7 @@ using Content.Server.Administration.Logs; using Content.Server.Atmos.Components; using Content.Server.Explosion.Components; using Content.Server.NodeContainer.EntitySystems; +using Content.Server.NPC.Pathfinding; using Content.Shared.Camera; using Content.Shared.Damage; using Content.Shared.Database; @@ -32,6 +33,7 @@ public sealed partial class ExplosionSystem : EntitySystem [Dependency] private readonly DamageableSystem _damageableSystem = default!; [Dependency] private readonly NodeGroupSystem _nodeGroupSystem = default!; + [Dependency] private readonly PathfindingSystem _pathfindingSystem = default!; [Dependency] private readonly SharedCameraRecoilSystem _recoilSystem = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly ThrowingSystem _throwingSystem = default!; @@ -85,14 +87,16 @@ public sealed partial class ExplosionSystem : EntitySystem { _explosionQueue.Clear(); _activeExplosion = null; - _nodeGroupSystem.Snoozing = false; + _nodeGroupSystem.PauseUpdating = false; + _pathfindingSystem.PauseUpdating = false; } public override void Shutdown() { base.Shutdown(); UnsubscribeCvars(); - _nodeGroupSystem.Snoozing = false; + _nodeGroupSystem.PauseUpdating = false; + _pathfindingSystem.PauseUpdating = false; } private void OnGetResistance(EntityUid uid, ExplosionResistanceComponent component, GetExplosionResistanceEvent args) diff --git a/Content.Server/NPC/Pathfinding/PathfindingSystem.Grid.cs b/Content.Server/NPC/Pathfinding/PathfindingSystem.Grid.cs index 0919b5c8fe..881e8c2a3b 100644 --- a/Content.Server/NPC/Pathfinding/PathfindingSystem.Grid.cs +++ b/Content.Server/NPC/Pathfinding/PathfindingSystem.Grid.cs @@ -27,6 +27,15 @@ public sealed partial class PathfindingSystem public const int PathfindingCollisionMask = (int) CollisionGroup.MobMask; public const int PathfindingCollisionLayer = (int) CollisionGroup.MobLayer; + /// + /// If true, UpdateGrid() will not process grids. + /// + /// + /// Useful if something like a large explosion is in the process of shredding the grid, as it avoids uneccesary + /// updating. + /// + public bool PauseUpdating = false; + private readonly Stopwatch _stopwatch = new(); // Probably can't pool polys as there might be old pathfinding refs to them. @@ -66,6 +75,9 @@ public sealed partial class PathfindingSystem private void UpdateGrid() { + if (PauseUpdating) + return; + var curTime = _timing.CurTime; #if DEBUG var updateCount = 0; diff --git a/Content.Server/NodeContainer/EntitySystems/NodeGroupSystem.cs b/Content.Server/NodeContainer/EntitySystems/NodeGroupSystem.cs index ff0fa20810..3c652902cb 100644 --- a/Content.Server/NodeContainer/EntitySystems/NodeGroupSystem.cs +++ b/Content.Server/NodeContainer/EntitySystems/NodeGroupSystem.cs @@ -45,7 +45,14 @@ namespace Content.Server.NodeContainer.EntitySystems private int _gen = 1; private int _groupNetIdCounter = 1; - public bool Snoozing = false; + /// + /// If true, UpdateGrid() will not process grids. + /// + /// + /// Useful if something like a large explosion is in the process of shredding the grid, as it avoids uneccesary + /// updating. + /// + public bool PauseUpdating = false; public override void Initialize() { @@ -135,7 +142,7 @@ namespace Content.Server.NodeContainer.EntitySystems { base.Update(frameTime); - if (!Snoozing) + if (!PauseUpdating) { DoGroupUpdates(); VisDoUpdate(frameTime);