Add IResettingEntitySystem for entity systems that do resetting cleanup (#2257)

* Add IResettingEntitySystem for entity systems that do resetting cleanup

* You got a license for that submodule update?
This commit is contained in:
DrSmugleaf
2020-10-14 22:45:53 +02:00
committed by GitHub
parent 6be80c119b
commit 50bc61b672
17 changed files with 76 additions and 54 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using Content.Server.GameObjects.Components.Access;
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Pathfinders;
using Content.Shared.AI;
using Content.Shared.GameTicking;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects.Components;
@@ -22,7 +23,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
/// </summary>
/// Long-term can be used to do hierarchical pathfinding
[UsedImplicitly]
public sealed class AiReachableSystem : EntitySystem
public sealed class AiReachableSystem : EntitySystem, IResettingEntitySystem
{
/*
* The purpose of this is to provide a higher-level / hierarchical abstraction of the actual pathfinding graph
@@ -134,14 +135,6 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
_mapManager.OnGridRemoved -= GridRemoved;
}
public void ResettingCleanup()
{
_queuedUpdates.Clear();
_regions.Clear();
_cachedAccessible.Clear();
_queuedCacheDeletions.Clear();
}
private void RecalculateNodeRegions(PathfindingChunkUpdateMessage message)
{
// TODO: Only need to do changed nodes ideally
@@ -683,6 +676,14 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
#endif
}
public void Reset()
{
_queuedUpdates.Clear();
_regions.Clear();
_cachedAccessible.Clear();
_queuedCacheDeletions.Clear();
}
#if DEBUG
private void SendDebugMessage(PlayerAttachSystemMessage message)
{

View File

@@ -5,6 +5,7 @@ using Content.Server.GameObjects.Components.Access;
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Pathfinders;
using Content.Server.GameObjects.EntitySystems.JobQueues;
using Content.Server.GameObjects.EntitySystems.JobQueues.Queues;
using Content.Shared.GameTicking;
using Content.Shared.Physics;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Transform;
@@ -28,7 +29,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
/// This system handles pathfinding graph updates as well as dispatches to the pathfinder
/// (90% of what it's doing is graph updates so not much point splitting the 2 roles)
/// </summary>
public class PathfindingSystem : EntitySystem
public class PathfindingSystem : EntitySystem, IResettingEntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
@@ -230,16 +231,6 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
node.UpdateTile(tile);
}
public void ResettingCleanup()
{
_graph.Clear();
_collidableUpdateQueue.Clear();
_moveUpdateQueue.Clear();
_accessReaderUpdateQueue.Clear();
_tileUpdateQueue.Clear();
_lastKnownPositions.Clear();
}
private void HandleGridRemoval(GridId gridId)
{
if (_graph.ContainsKey(gridId))
@@ -389,5 +380,15 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
return true;
}
public void Reset()
{
_graph.Clear();
_collidableUpdateQueue.Clear();
_moveUpdateQueue.Clear();
_accessReaderUpdateQueue.Clear();
_tileUpdateQueue.Clear();
_lastKnownPositions.Clear();
}
}
}

View File

@@ -6,6 +6,7 @@ using System.Runtime.CompilerServices;
using Content.Server.GameObjects.Components.Atmos;
using Content.Shared.Atmos;
using Content.Shared.GameObjects.EntitySystems.Atmos;
using Content.Shared.GameTicking;
using JetBrains.Annotations;
using Robust.Server.Interfaces.Player;
using Robust.Server.Player;
@@ -21,7 +22,7 @@ using Robust.Shared.Timing;
namespace Content.Server.GameObjects.EntitySystems.Atmos
{
[UsedImplicitly]
internal sealed class GasTileOverlaySystem : SharedGasTileOverlaySystem
internal sealed class GasTileOverlaySystem : SharedGasTileOverlaySystem, IResettingEntitySystem
{
[Robust.Shared.IoC.Dependency] private readonly IGameTiming _gameTiming = default!;
[Robust.Shared.IoC.Dependency] private readonly IPlayerManager _playerManager = default!;
@@ -113,17 +114,6 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
}
}
public void ResettingCleanup()
{
_invalidTiles.Clear();
_overlay.Clear();
foreach (var (_, data) in _knownPlayerChunks)
{
data.Reset();
}
}
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
{
if (e.NewStatus != SessionStatus.InGame)
@@ -483,5 +473,16 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
return new GasOverlayMessage(chunk.GridIndices, tileData);
}
}
public void Reset()
{
_invalidTiles.Clear();
_overlay.Clear();
foreach (var (_, data) in _knownPlayerChunks)
{
data.Reset();
}
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Text;
using Content.Server.GameTicking;
using Content.Server.Interfaces.GameTicking;
using Content.Server.StationEvents;
using Content.Shared.GameTicking;
using JetBrains.Annotations;
using Robust.Server.Console;
using Robust.Server.Interfaces.Player;
@@ -20,7 +21,7 @@ namespace Content.Server.GameObjects.EntitySystems.StationEvents
{
[UsedImplicitly]
// Somewhat based off of TG's implementation of events
public sealed class StationEventSystem : EntitySystem
public sealed class StationEventSystem : EntitySystem, IResettingEntitySystem
{
[Dependency] private readonly IServerNetManager _netManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
@@ -339,7 +340,13 @@ namespace Content.Server.GameObjects.EntitySystems.StationEvents
return true;
}
public void ResettingCleanup()
public override void Shutdown()
{
base.Shutdown();
CurrentEvent?.Shutdown();
}
public void Reset()
{
if (CurrentEvent != null && CurrentEvent.Running)
{
@@ -354,11 +361,5 @@ namespace Content.Server.GameObjects.EntitySystems.StationEvents
_timeUntilNextEvent = MinimumTimeUntilFirstEvent;
}
public override void Shutdown()
{
base.Shutdown();
CurrentEvent?.Shutdown();
}
}
}

View File

@@ -1,11 +1,12 @@
using System.Collections.Generic;
using Content.Shared.GameTicking;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.ViewVariables;
using static Content.Shared.GameObjects.Components.SharedWiresComponent;
namespace Content.Server.GameObjects.EntitySystems
{
public class WireHackingSystem : EntitySystem
public class WireHackingSystem : EntitySystem, IResettingEntitySystem
{
[ViewVariables] private readonly Dictionary<string, WireLayout> _layouts =
new Dictionary<string, WireLayout>();
@@ -20,7 +21,7 @@ namespace Content.Server.GameObjects.EntitySystems
_layouts.Add(id, layout);
}
public void ResetLayouts()
public void Reset()
{
_layouts.Clear();
}