Re-use atmos queues (#21803)

This commit is contained in:
Leon Friedrich
2023-11-20 23:40:26 +13:00
committed by GitHub
parent c46bad59fa
commit c5f9dfe7db
2 changed files with 55 additions and 16 deletions

View File

@@ -65,22 +65,22 @@ namespace Content.Server.Atmos.Components
public readonly HashSet<Entity<AtmosDeviceComponent>> AtmosDevices = new(); public readonly HashSet<Entity<AtmosDeviceComponent>> AtmosDevices = new();
[ViewVariables] [ViewVariables]
public Queue<TileAtmosphere> CurrentRunTiles = new(); public readonly Queue<TileAtmosphere> CurrentRunTiles = new();
[ViewVariables] [ViewVariables]
public Queue<ExcitedGroup> CurrentRunExcitedGroups = new(); public readonly Queue<ExcitedGroup> CurrentRunExcitedGroups = new();
[ViewVariables] [ViewVariables]
public Queue<IPipeNet> CurrentRunPipeNet = new(); public readonly Queue<IPipeNet> CurrentRunPipeNet = new();
[ViewVariables] [ViewVariables]
public Queue<Entity<AtmosDeviceComponent>> CurrentRunAtmosDevices = new(); public readonly Queue<Entity<AtmosDeviceComponent>> CurrentRunAtmosDevices = new();
[ViewVariables] [ViewVariables]
public readonly HashSet<Vector2i> InvalidatedCoords = new(1000); public readonly HashSet<Vector2i> InvalidatedCoords = new(1000);
[ViewVariables] [ViewVariables]
public Queue<Vector2i> CurrentRunInvalidatedCoordinates = new(); public readonly Queue<Vector2i> CurrentRunInvalidatedCoordinates = new();
[ViewVariables] [ViewVariables]
public int InvalidatedCoordsCount => InvalidatedCoords.Count; public int InvalidatedCoordsCount => InvalidatedCoords.Count;

View File

@@ -41,7 +41,12 @@ namespace Content.Server.Atmos.EntitySystems
var (owner, atmosphere) = ent; var (owner, atmosphere) = ent;
if (!atmosphere.ProcessingPaused) if (!atmosphere.ProcessingPaused)
{ {
atmosphere.CurrentRunInvalidatedCoordinates = new Queue<Vector2i>(atmosphere.InvalidatedCoords); atmosphere.CurrentRunInvalidatedCoordinates.Clear();
atmosphere.CurrentRunInvalidatedCoordinates.EnsureCapacity(atmosphere.InvalidatedCoords.Count);
foreach (var tile in atmosphere.InvalidatedCoords)
{
atmosphere.CurrentRunInvalidatedCoordinates.Enqueue(tile);
}
atmosphere.InvalidatedCoords.Clear(); atmosphere.InvalidatedCoords.Clear();
} }
@@ -151,11 +156,24 @@ namespace Content.Server.Atmos.EntitySystems
return true; return true;
} }
private void QueueRunTiles(
Queue<TileAtmosphere> queue,
HashSet<TileAtmosphere> tiles)
{
queue.Clear();
queue.EnsureCapacity(tiles.Count);
foreach (var tile in tiles)
{
queue.Enqueue(tile);
}
}
private bool ProcessTileEqualize(Entity<GridAtmosphereComponent> ent, GasTileOverlayComponent? visuals) private bool ProcessTileEqualize(Entity<GridAtmosphereComponent> ent, GasTileOverlayComponent? visuals)
{ {
var (uid, atmosphere) = ent; var (uid, atmosphere) = ent;
if (!atmosphere.ProcessingPaused) if (!atmosphere.ProcessingPaused)
atmosphere.CurrentRunTiles = new Queue<TileAtmosphere>(atmosphere.ActiveTiles); QueueRunTiles(atmosphere.CurrentRunTiles, atmosphere.ActiveTiles);
if (!TryComp(uid, out MapGridComponent? mapGridComp)) if (!TryComp(uid, out MapGridComponent? mapGridComp))
throw new Exception("Tried to process a grid atmosphere on an entity that isn't a grid!"); throw new Exception("Tried to process a grid atmosphere on an entity that isn't a grid!");
@@ -182,7 +200,7 @@ namespace Content.Server.Atmos.EntitySystems
private bool ProcessActiveTiles(GridAtmosphereComponent atmosphere, GasTileOverlayComponent? visuals) private bool ProcessActiveTiles(GridAtmosphereComponent atmosphere, GasTileOverlayComponent? visuals)
{ {
if(!atmosphere.ProcessingPaused) if(!atmosphere.ProcessingPaused)
atmosphere.CurrentRunTiles = new Queue<TileAtmosphere>(atmosphere.ActiveTiles); QueueRunTiles(atmosphere.CurrentRunTiles, atmosphere.ActiveTiles);
var number = 0; var number = 0;
while (atmosphere.CurrentRunTiles.TryDequeue(out var tile)) while (atmosphere.CurrentRunTiles.TryDequeue(out var tile))
@@ -205,8 +223,15 @@ namespace Content.Server.Atmos.EntitySystems
private bool ProcessExcitedGroups(GridAtmosphereComponent gridAtmosphere) private bool ProcessExcitedGroups(GridAtmosphereComponent gridAtmosphere)
{ {
if(!gridAtmosphere.ProcessingPaused) if (!gridAtmosphere.ProcessingPaused)
gridAtmosphere.CurrentRunExcitedGroups = new Queue<ExcitedGroup>(gridAtmosphere.ExcitedGroups); {
gridAtmosphere.CurrentRunExcitedGroups.Clear();
gridAtmosphere.CurrentRunExcitedGroups.EnsureCapacity(gridAtmosphere.ExcitedGroups.Count);
foreach (var group in gridAtmosphere.ExcitedGroups)
{
gridAtmosphere.CurrentRunExcitedGroups.Enqueue(group);
}
}
var number = 0; var number = 0;
while (gridAtmosphere.CurrentRunExcitedGroups.TryDequeue(out var excitedGroup)) while (gridAtmosphere.CurrentRunExcitedGroups.TryDequeue(out var excitedGroup))
@@ -238,7 +263,7 @@ namespace Content.Server.Atmos.EntitySystems
{ {
var atmosphere = ent.Comp; var atmosphere = ent.Comp;
if (!atmosphere.ProcessingPaused) if (!atmosphere.ProcessingPaused)
atmosphere.CurrentRunTiles = new Queue<TileAtmosphere>(atmosphere.HighPressureDelta); QueueRunTiles(atmosphere.CurrentRunTiles, atmosphere.HighPressureDelta);
// Note: This is still processed even if space wind is turned off since this handles playing the sounds. // Note: This is still processed even if space wind is turned off since this handles playing the sounds.
@@ -273,7 +298,7 @@ namespace Content.Server.Atmos.EntitySystems
private bool ProcessHotspots(GridAtmosphereComponent atmosphere) private bool ProcessHotspots(GridAtmosphereComponent atmosphere)
{ {
if(!atmosphere.ProcessingPaused) if(!atmosphere.ProcessingPaused)
atmosphere.CurrentRunTiles = new Queue<TileAtmosphere>(atmosphere.HotspotTiles); QueueRunTiles(atmosphere.CurrentRunTiles, atmosphere.HotspotTiles);
var number = 0; var number = 0;
while (atmosphere.CurrentRunTiles.TryDequeue(out var hotspot)) while (atmosphere.CurrentRunTiles.TryDequeue(out var hotspot))
@@ -297,7 +322,7 @@ namespace Content.Server.Atmos.EntitySystems
private bool ProcessSuperconductivity(GridAtmosphereComponent atmosphere) private bool ProcessSuperconductivity(GridAtmosphereComponent atmosphere)
{ {
if(!atmosphere.ProcessingPaused) if(!atmosphere.ProcessingPaused)
atmosphere.CurrentRunTiles = new Queue<TileAtmosphere>(atmosphere.SuperconductivityTiles); QueueRunTiles(atmosphere.CurrentRunTiles, atmosphere.SuperconductivityTiles);
var number = 0; var number = 0;
while (atmosphere.CurrentRunTiles.TryDequeue(out var superconductivity)) while (atmosphere.CurrentRunTiles.TryDequeue(out var superconductivity))
@@ -320,8 +345,15 @@ namespace Content.Server.Atmos.EntitySystems
private bool ProcessPipeNets(GridAtmosphereComponent atmosphere) private bool ProcessPipeNets(GridAtmosphereComponent atmosphere)
{ {
if(!atmosphere.ProcessingPaused) if (!atmosphere.ProcessingPaused)
atmosphere.CurrentRunPipeNet = new Queue<IPipeNet>(atmosphere.PipeNets); {
atmosphere.CurrentRunPipeNet.Clear();
atmosphere.CurrentRunPipeNet.EnsureCapacity(atmosphere.PipeNets.Count);
foreach (var net in atmosphere.PipeNets)
{
atmosphere.CurrentRunPipeNet.Enqueue(net);
}
}
var number = 0; var number = 0;
while (atmosphere.CurrentRunPipeNet.TryDequeue(out var pipenet)) while (atmosphere.CurrentRunPipeNet.TryDequeue(out var pipenet))
@@ -362,7 +394,14 @@ namespace Content.Server.Atmos.EntitySystems
private bool ProcessAtmosDevices(GridAtmosphereComponent atmosphere) private bool ProcessAtmosDevices(GridAtmosphereComponent atmosphere)
{ {
if (!atmosphere.ProcessingPaused) if (!atmosphere.ProcessingPaused)
atmosphere.CurrentRunAtmosDevices = new Queue<Entity<AtmosDeviceComponent>>(atmosphere.AtmosDevices); {
atmosphere.CurrentRunAtmosDevices.Clear();
atmosphere.CurrentRunAtmosDevices.EnsureCapacity(atmosphere.AtmosDevices.Count);
foreach (var device in atmosphere.AtmosDevices)
{
atmosphere.CurrentRunAtmosDevices.Enqueue(device);
}
}
var time = _gameTiming.CurTime; var time = _gameTiming.CurTime;
var number = 0; var number = 0;