Optimizes atmos further by using rented arrays where applicable
This commit is contained in:
@@ -332,32 +332,40 @@ namespace Content.Server.Atmos
|
|||||||
var tile = tiles[i];
|
var tile = tiles[i];
|
||||||
tile._tileAtmosInfo.FastDone = true;
|
tile._tileAtmosInfo.FastDone = true;
|
||||||
if (!(tile._tileAtmosInfo.MoleDelta > 0)) continue;
|
if (!(tile._tileAtmosInfo.MoleDelta > 0)) continue;
|
||||||
var eligibleDirections = new List<Direction>();
|
var eligibleDirections = ArrayPool<Direction>.Shared.Rent(4);
|
||||||
var amtEligibleAdj = 0;
|
var eligibleDirectionCount = 0;
|
||||||
foreach (var direction in Cardinal)
|
foreach (var direction in Cardinal)
|
||||||
{
|
{
|
||||||
if (!tile._adjacentTiles.TryGetValue(direction, out var tile2)) continue;
|
if (!tile._adjacentTiles.TryGetValue(direction, out var tile2)) continue;
|
||||||
|
|
||||||
// skip anything that isn't part of our current processing block. Original one didn't do this unfortunately, which probably cause some massive lag.
|
// skip anything that isn't part of our current processing block.
|
||||||
if (tile2._tileAtmosInfo.FastDone || tile2._tileAtmosInfo.LastQueueCycle != queueCycle)
|
if (tile2._tileAtmosInfo.FastDone || tile2._tileAtmosInfo.LastQueueCycle != queueCycle)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
eligibleDirections.Add(direction);
|
eligibleDirections[eligibleDirectionCount++] = direction;
|
||||||
amtEligibleAdj++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amtEligibleAdj <= 0)
|
if (eligibleDirectionCount <= 0)
|
||||||
continue; // Oof we've painted ourselves into a corner. Bad luck. Next part will handle this.
|
continue; // Oof we've painted ourselves into a corner. Bad luck. Next part will handle this.
|
||||||
|
|
||||||
var molesToMove = tile._tileAtmosInfo.MoleDelta / amtEligibleAdj;
|
var molesToMove = tile._tileAtmosInfo.MoleDelta / eligibleDirectionCount;
|
||||||
foreach (var direction in Cardinal)
|
foreach (var direction in Cardinal)
|
||||||
{
|
{
|
||||||
if (eligibleDirections.Contains(direction) ||
|
var hasDirection = false;
|
||||||
!tile._adjacentTiles.TryGetValue(direction, out var tile2)) continue;
|
for (var j = 0; j < eligibleDirectionCount; j++)
|
||||||
|
{
|
||||||
|
if (eligibleDirections[j] != direction) continue;
|
||||||
|
hasDirection = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasDirection || !tile._adjacentTiles.TryGetValue(direction, out var tile2)) continue;
|
||||||
tile.AdjustEqMovement(direction, molesToMove);
|
tile.AdjustEqMovement(direction, molesToMove);
|
||||||
tile._tileAtmosInfo.MoleDelta -= molesToMove;
|
tile._tileAtmosInfo.MoleDelta -= molesToMove;
|
||||||
tile2._tileAtmosInfo.MoleDelta += molesToMove;
|
tile2._tileAtmosInfo.MoleDelta += molesToMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayPool<Direction>.Shared.Return(eligibleDirections);
|
||||||
}
|
}
|
||||||
|
|
||||||
giverTilesLength = 0;
|
giverTilesLength = 0;
|
||||||
@@ -446,7 +454,7 @@ namespace Content.Server.Atmos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayPool<TileAtmosphere>.Shared.Return(queue, true);
|
ArrayPool<TileAtmosphere>.Shared.Return(queue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -516,7 +524,7 @@ namespace Content.Server.Atmos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayPool<TileAtmosphere>.Shared.Return(queue, true);
|
ArrayPool<TileAtmosphere>.Shared.Return(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < tileCount; i++)
|
for (var i = 0; i < tileCount; i++)
|
||||||
@@ -537,9 +545,9 @@ namespace Content.Server.Atmos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayPool<TileAtmosphere>.Shared.Return(tiles, true);
|
ArrayPool<TileAtmosphere>.Shared.Return(tiles);
|
||||||
ArrayPool<TileAtmosphere>.Shared.Return(giverTiles, true);
|
ArrayPool<TileAtmosphere>.Shared.Return(giverTiles);
|
||||||
ArrayPool<TileAtmosphere>.Shared.Return(takerTiles, true);
|
ArrayPool<TileAtmosphere>.Shared.Return(takerTiles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -925,16 +933,22 @@ namespace Content.Server.Atmos
|
|||||||
public void ExplosivelyDepressurize(int cycleNum)
|
public void ExplosivelyDepressurize(int cycleNum)
|
||||||
{
|
{
|
||||||
if (Air == null) return;
|
if (Air == null) return;
|
||||||
|
|
||||||
|
const int limit = Atmospherics.ZumosTileLimit;
|
||||||
|
|
||||||
var totalGasesRemoved = 0f;
|
var totalGasesRemoved = 0f;
|
||||||
var queueCycle = ++_gridAtmosphereComponent.EqualizationQueueCycleControl;
|
var queueCycle = ++_gridAtmosphereComponent.EqualizationQueueCycleControl;
|
||||||
var tiles = new List<TileAtmosphere>();
|
var tiles = ArrayPool<TileAtmosphere>.Shared.Rent(limit);
|
||||||
var spaceTiles = new List<TileAtmosphere>();
|
var spaceTiles = ArrayPool<TileAtmosphere>.Shared.Rent(limit);
|
||||||
tiles.Add(this);
|
|
||||||
|
var tileCount = 0;
|
||||||
|
var spaceTileCount = 0;
|
||||||
|
|
||||||
|
tiles[tileCount++] = this;
|
||||||
|
|
||||||
ResetTileAtmosInfo();
|
ResetTileAtmosInfo();
|
||||||
_tileAtmosInfo.LastQueueCycle = queueCycle;
|
_tileAtmosInfo.LastQueueCycle = queueCycle;
|
||||||
|
|
||||||
var tileCount = 1;
|
|
||||||
for (var i = 0; i < tileCount; i++)
|
for (var i = 0; i < tileCount; i++)
|
||||||
{
|
{
|
||||||
var tile = tiles[i];
|
var tile = tiles[i];
|
||||||
@@ -942,40 +956,44 @@ namespace Content.Server.Atmos
|
|||||||
tile._tileAtmosInfo.CurrentTransferDirection = Direction.Invalid;
|
tile._tileAtmosInfo.CurrentTransferDirection = Direction.Invalid;
|
||||||
if (tile.Air.Immutable)
|
if (tile.Air.Immutable)
|
||||||
{
|
{
|
||||||
spaceTiles.Add(tile);
|
spaceTiles[spaceTileCount++] = tile;
|
||||||
tile.PressureSpecificTarget = tile;
|
tile.PressureSpecificTarget = tile;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (i > Atmospherics.ZumosTileLimit) continue;
|
|
||||||
foreach (var direction in Cardinal)
|
foreach (var direction in Cardinal)
|
||||||
{
|
{
|
||||||
if (!tile._adjacentTiles.TryGetValue(direction, out var tile2)) continue;
|
if (!tile._adjacentTiles.TryGetValue(direction, out var tile2)) continue;
|
||||||
if (tile2?.Air == null) continue;
|
if (tile2.Air == null) continue;
|
||||||
if (tile2._tileAtmosInfo.LastQueueCycle == queueCycle) continue;
|
if (tile2._tileAtmosInfo.LastQueueCycle == queueCycle) continue;
|
||||||
|
|
||||||
tile.ConsiderFirelocks(tile2);
|
tile.ConsiderFirelocks(tile2);
|
||||||
if (tile._adjacentTiles[direction]?.Air != null)
|
|
||||||
{
|
// The firelocks might have closed on us.
|
||||||
tile2.ResetTileAtmosInfo();
|
if (tile._adjacentTiles[direction]?.Air == null) continue;
|
||||||
tile2._tileAtmosInfo.LastQueueCycle = queueCycle;
|
tile2.ResetTileAtmosInfo();
|
||||||
tiles.Add(tile2);
|
tile2._tileAtmosInfo.LastQueueCycle = queueCycle;
|
||||||
tileCount++;
|
tiles[tileCount++] = tile2;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tileCount >= limit || spaceTileCount >= limit)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var queueCycleSlow = ++_gridAtmosphereComponent.EqualizationQueueCycleControl;
|
var queueCycleSlow = ++_gridAtmosphereComponent.EqualizationQueueCycleControl;
|
||||||
var progressionOrder = new List<TileAtmosphere>();
|
var progressionOrder = ArrayPool<TileAtmosphere>.Shared.Rent(limit * 2);
|
||||||
foreach (var tile in spaceTiles)
|
var progressionCount = 0;
|
||||||
|
|
||||||
|
for (var i = 0; i < spaceTileCount; i++)
|
||||||
{
|
{
|
||||||
progressionOrder.Add(tile);
|
var tile = spaceTiles[i];
|
||||||
|
progressionOrder[progressionCount++] = tile;
|
||||||
tile._tileAtmosInfo.LastSlowQueueCycle = queueCycleSlow;
|
tile._tileAtmosInfo.LastSlowQueueCycle = queueCycleSlow;
|
||||||
tile._tileAtmosInfo.CurrentTransferDirection = Direction.Invalid;
|
tile._tileAtmosInfo.CurrentTransferDirection = Direction.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
var progressionCount = progressionOrder.Count;
|
for (var i = 0; i < progressionCount; i++)
|
||||||
for (int i = 0; i < progressionCount; i++)
|
|
||||||
{
|
{
|
||||||
var tile = progressionOrder[i];
|
var tile = progressionOrder[i];
|
||||||
foreach (var direction in Cardinal)
|
foreach (var direction in Cardinal)
|
||||||
@@ -988,8 +1006,7 @@ namespace Content.Server.Atmos
|
|||||||
tile2._tileAtmosInfo.CurrentTransferAmount = 0;
|
tile2._tileAtmosInfo.CurrentTransferAmount = 0;
|
||||||
tile2.PressureSpecificTarget = tile.PressureSpecificTarget;
|
tile2.PressureSpecificTarget = tile.PressureSpecificTarget;
|
||||||
tile2._tileAtmosInfo.LastSlowQueueCycle = queueCycleSlow;
|
tile2._tileAtmosInfo.LastSlowQueueCycle = queueCycleSlow;
|
||||||
progressionOrder.Add(tile2);
|
progressionOrder[progressionCount++] = tile2;
|
||||||
progressionCount++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1017,6 +1034,10 @@ namespace Content.Server.Atmos
|
|||||||
tile.UpdateVisuals();
|
tile.UpdateVisuals();
|
||||||
tile.HandleDecompressionFloorRip(sum);
|
tile.HandleDecompressionFloorRip(sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayPool<TileAtmosphere>.Shared.Return(tiles);
|
||||||
|
ArrayPool<TileAtmosphere>.Shared.Return(spaceTiles);
|
||||||
|
ArrayPool<TileAtmosphere>.Shared.Return(progressionOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleDecompressionFloorRip(float sum)
|
private void HandleDecompressionFloorRip(float sum)
|
||||||
@@ -1029,7 +1050,6 @@ namespace Content.Server.Atmos
|
|||||||
private void ConsiderFirelocks(TileAtmosphere other)
|
private void ConsiderFirelocks(TileAtmosphere other)
|
||||||
{
|
{
|
||||||
// TODO ATMOS firelocks!
|
// TODO ATMOS firelocks!
|
||||||
//throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void React()
|
private void React()
|
||||||
|
|||||||
@@ -51,6 +51,7 @@
|
|||||||
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue"><data><IncludeFilters /><ExcludeFilters><Filter ModuleMask="Lidgren.Network" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /></ExcludeFilters></data></s:String>
|
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue"><data><IncludeFilters /><ExcludeFilters><Filter ModuleMask="Lidgren.Network" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /></ExcludeFilters></data></s:String>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Collidable/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Collidable/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cooldowns/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cooldowns/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=firelocks/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=flashable/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=flashable/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Fluidsynth/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Fluidsynth/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=freepats/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=freepats/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
|||||||
Reference in New Issue
Block a user