Remove byte[] allocations for GasTileOverlaySystem.UpdateChunkTile (#12617)
This commit is contained in:
@@ -2,7 +2,6 @@ using Content.Shared.Atmos.EntitySystems;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using static Content.Shared.Atmos.EntitySystems.SharedGasTileOverlaySystem;
|
||||
|
||||
namespace Content.Shared.Atmos
|
||||
@@ -17,7 +16,7 @@ namespace Content.Shared.Atmos
|
||||
public readonly Vector2i Index;
|
||||
public readonly Vector2i Origin;
|
||||
|
||||
public GasOverlayData?[][] TileData = new GasOverlayData?[ChunkSize][];
|
||||
public GasOverlayData[][] TileData = new GasOverlayData[ChunkSize][];
|
||||
|
||||
[NonSerialized]
|
||||
public GameTick LastUpdate;
|
||||
@@ -30,20 +29,14 @@ namespace Content.Shared.Atmos
|
||||
// For whatever reason, net serialize does not like multi_D arrays. So Jagged it is.
|
||||
for (var i = 0; i < ChunkSize; i++)
|
||||
{
|
||||
TileData[i] = new GasOverlayData?[ChunkSize];
|
||||
TileData[i] = new GasOverlayData[ChunkSize];
|
||||
}
|
||||
}
|
||||
|
||||
public GasOverlayData? GetData(Vector2i gridIndices)
|
||||
public ref GasOverlayData GetData(Vector2i gridIndices)
|
||||
{
|
||||
DebugTools.Assert(InBounds(gridIndices));
|
||||
return TileData[gridIndices.X - Origin.X][gridIndices.Y - Origin.Y];
|
||||
}
|
||||
|
||||
public GasOverlayData? SetData(Vector2i gridIndices, GasOverlayData? data)
|
||||
{
|
||||
DebugTools.Assert(InBounds(gridIndices));
|
||||
return TileData[gridIndices.X - Origin.X][gridIndices.Y - Origin.Y] = data;
|
||||
return ref TileData[gridIndices.X - Origin.X][gridIndices.Y - Origin.Y];
|
||||
}
|
||||
|
||||
private bool InBounds(Vector2i gridIndices)
|
||||
@@ -60,7 +53,7 @@ namespace Content.Shared.Atmos
|
||||
private GasOverlayChunk _chunk;
|
||||
public int X = 0;
|
||||
public int Y = -1;
|
||||
private GasOverlayData?[] _column;
|
||||
private GasOverlayData[] _column;
|
||||
|
||||
|
||||
public GasChunkEnumerator(GasOverlayChunk chunk)
|
||||
@@ -69,18 +62,18 @@ namespace Content.Shared.Atmos
|
||||
_column = _chunk.TileData[0];
|
||||
}
|
||||
|
||||
public bool MoveNext([NotNullWhen(true)] out GasOverlayData? gas)
|
||||
public bool MoveNext(out GasOverlayData gas)
|
||||
{
|
||||
while (X < ChunkSize)
|
||||
{
|
||||
// We want to increment Y before returning, but we also want it to match the current Y coordinate for
|
||||
// the returned gas, so using a slightly different logic for the Y loop.
|
||||
while (Y < ChunkSize - 1)
|
||||
while (Y < ChunkSize - 1)
|
||||
{
|
||||
Y++;
|
||||
gas = _column[Y];
|
||||
|
||||
if (gas != null)
|
||||
if (!gas.Equals(default))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -90,7 +83,7 @@ namespace Content.Shared.Atmos
|
||||
Y = -1;
|
||||
}
|
||||
|
||||
gas = null;
|
||||
gas = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user