SIMD-accelerated gas mixtures. (SIMD atmos) (#2479)
* SIMD atmos * Moles will always be a multiple of four. * Component dependencies for grid atmos. * Let's optimize allocations while we're at it! * Inline this * A bunch of atmos optimizations * Fix crimes against atmos * Microsoft moment * Remove nuget.config * do not reference Robust.UnitTests in Content.Benchmarks as it's unneeded. * Revert "Remove nuget.config" This reverts commit 872604ae6a51365af4075bb23687bd005befd8ac. * Gas overlay optimization and fixes * Lattice is now spess * minor atmos tweaks
This commit is contained in:
committed by
GitHub
parent
89f72c4cb2
commit
b18ee3ec49
@@ -23,6 +23,5 @@
|
|||||||
<ProjectReference Include="..\RobustToolbox\Robust.Server\Robust.Server.csproj" />
|
<ProjectReference Include="..\RobustToolbox\Robust.Server\Robust.Server.csproj" />
|
||||||
<ProjectReference Include="..\RobustToolbox\Robust.Shared.Maths\Robust.Shared.Maths.csproj" />
|
<ProjectReference Include="..\RobustToolbox\Robust.Shared.Maths\Robust.Shared.Maths.csproj" />
|
||||||
<ProjectReference Include="..\RobustToolbox\Robust.Shared\Robust.Shared.csproj" />
|
<ProjectReference Include="..\RobustToolbox\Robust.Shared\Robust.Shared.csproj" />
|
||||||
<ProjectReference Include="..\RobustToolbox\Robust.UnitTesting\Robust.UnitTesting.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Content.Server.Interfaces;
|
|||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos;
|
||||||
using Robust.Shared.GameObjects.Systems;
|
using Robust.Shared.GameObjects.Systems;
|
||||||
using Robust.Shared.Interfaces.Serialization;
|
using Robust.Shared.Interfaces.Serialization;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
@@ -24,11 +25,12 @@ namespace Content.Server.Atmos
|
|||||||
|
|
||||||
public static GasMixture SpaceGas => new GasMixture() {Volume = 2500f, Immutable = true, Temperature = Atmospherics.TCMB};
|
public static GasMixture SpaceGas => new GasMixture() {Volume = 2500f, Immutable = true, Temperature = Atmospherics.TCMB};
|
||||||
|
|
||||||
|
// This must always have a length that is a multiple of 4 for SIMD acceleration.
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private float[] _moles = new float[Atmospherics.TotalNumberOfGases];
|
private float[] _moles;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private float[] _molesArchived = new float[Atmospherics.TotalNumberOfGases];
|
private float[] _molesArchived;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private float _temperature = Atmospherics.TCMB;
|
private float _temperature = Atmospherics.TCMB;
|
||||||
@@ -54,46 +56,10 @@ namespace Content.Server.Atmos
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var capacity = 0f;
|
Span<float> tmp = stackalloc float[_moles.Length];
|
||||||
|
NumericsHelpers.Multiply(_moles, _atmosphereSystem.GasSpecificHeats, tmp);
|
||||||
|
|
||||||
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
return MathF.Max(NumericsHelpers.HorizontalAdd(tmp), Atmospherics.MinimumHeatCapacity);
|
||||||
{
|
|
||||||
capacity += _atmosphereSystem.GetGas(i).SpecificHeat * _moles[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return MathF.Max(capacity, Atmospherics.MinimumHeatCapacity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Heat capacity ratio of gas mixture
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables]
|
|
||||||
public float HeatCapacityRatio
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var delimiterSum = 0f;
|
|
||||||
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
|
||||||
{
|
|
||||||
delimiterSum += _moles[i] / (_atmosphereSystem.GetGas(i).HeatCapacityRatio - 1);
|
|
||||||
}
|
|
||||||
return 1 + TotalMoles / delimiterSum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float MolarMass
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var molarMass = 0f;
|
|
||||||
var totalMoles = TotalMoles;
|
|
||||||
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
|
||||||
{
|
|
||||||
molarMass += _atmosphereSystem.GetGas(i).MolarMass * (_moles[i] / totalMoles);
|
|
||||||
}
|
|
||||||
|
|
||||||
return molarMass;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,14 +69,10 @@ namespace Content.Server.Atmos
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var capacity = 0f;
|
Span<float> tmp = stackalloc float[_moles.Length];
|
||||||
|
NumericsHelpers.Multiply(_molesArchived, _atmosphereSystem.GasSpecificHeats, tmp);
|
||||||
|
|
||||||
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
return MathF.Max(NumericsHelpers.HorizontalAdd(tmp), Atmospherics.MinimumHeatCapacity);
|
||||||
{
|
|
||||||
capacity += _atmosphereSystem.GetGas(i).SpecificHeat * _molesArchived[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return MathF.Max(capacity, Atmospherics.MinimumHeatCapacity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,17 +80,7 @@ namespace Content.Server.Atmos
|
|||||||
public float TotalMoles
|
public float TotalMoles
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get
|
get => NumericsHelpers.HorizontalAdd(_moles);
|
||||||
{
|
|
||||||
var moles = 0f;
|
|
||||||
|
|
||||||
foreach (var gas in _moles)
|
|
||||||
{
|
|
||||||
moles += gas;
|
|
||||||
}
|
|
||||||
|
|
||||||
return moles;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
@@ -168,7 +120,7 @@ namespace Content.Server.Atmos
|
|||||||
public GasMixture(AtmosphereSystem? atmosphereSystem)
|
public GasMixture(AtmosphereSystem? atmosphereSystem)
|
||||||
{
|
{
|
||||||
_atmosphereSystem = atmosphereSystem ?? EntitySystem.Get<AtmosphereSystem>();
|
_atmosphereSystem = atmosphereSystem ?? EntitySystem.Get<AtmosphereSystem>();
|
||||||
_moles = new float[_atmosphereSystem.Gases.Count()];
|
_moles = new float[MathHelper.NextMultipleOf(Atmospherics.TotalNumberOfGases, 4)];
|
||||||
_molesArchived = new float[_moles.Length];
|
_molesArchived = new float[_moles.Length];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,10 +159,7 @@ namespace Content.Server.Atmos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
NumericsHelpers.Add(_moles, giver._moles);
|
||||||
{
|
|
||||||
_moles[i] += giver._moles[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@@ -268,19 +217,10 @@ namespace Content.Server.Atmos
|
|||||||
|
|
||||||
var removed = new GasMixture(_atmosphereSystem) {Volume = Volume, Temperature = Temperature};
|
var removed = new GasMixture(_atmosphereSystem) {Volume = Volume, Temperature = Temperature};
|
||||||
|
|
||||||
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
_moles.CopyTo(removed._moles.AsSpan());
|
||||||
{
|
NumericsHelpers.Multiply(removed._moles, ratio);
|
||||||
var moles = _moles[i];
|
|
||||||
if (moles < Atmospherics.GasMinMoles)
|
|
||||||
removed._moles[i] = 0f;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var removedMoles = moles * ratio;
|
|
||||||
removed._moles[i] = removedMoles;
|
|
||||||
if (!Immutable)
|
if (!Immutable)
|
||||||
_moles[i] -= removedMoles;
|
NumericsHelpers.Sub(_moles, removed._moles);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
@@ -563,25 +503,24 @@ namespace Content.Server.Atmos
|
|||||||
public void Multiply(float multiplier)
|
public void Multiply(float multiplier)
|
||||||
{
|
{
|
||||||
if (Immutable) return;
|
if (Immutable) return;
|
||||||
for(var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
NumericsHelpers.Multiply(_moles, multiplier);
|
||||||
{
|
|
||||||
_moles[i] *= multiplier;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExposeData(ObjectSerializer serializer)
|
public void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
|
var length = MathHelper.NextMultipleOf(Atmospherics.TotalNumberOfGases, 4);
|
||||||
|
|
||||||
serializer.DataField(this, x => Immutable, "immutable", false);
|
serializer.DataField(this, x => Immutable, "immutable", false);
|
||||||
serializer.DataField(this, x => Volume, "volume", 0f);
|
serializer.DataField(this, x => Volume, "volume", 0f);
|
||||||
serializer.DataField(this, x => LastShare, "lastShare", 0f);
|
serializer.DataField(this, x => LastShare, "lastShare", 0f);
|
||||||
serializer.DataField(this, x => TemperatureArchived, "temperatureArchived", 0f);
|
serializer.DataField(this, x => TemperatureArchived, "temperatureArchived", 0f);
|
||||||
serializer.DataField(ref _moles, "moles", new float[Atmospherics.TotalNumberOfGases]);
|
serializer.DataField(ref _moles, "moles", new float[length]);
|
||||||
serializer.DataField(ref _molesArchived, "molesArchived", new float[Atmospherics.TotalNumberOfGases]);
|
serializer.DataField(ref _molesArchived, "molesArchived", new float[length]);
|
||||||
serializer.DataField(ref _temperature, "temperature", Atmospherics.TCMB);
|
serializer.DataField(ref _temperature, "temperature", Atmospherics.TCMB);
|
||||||
|
|
||||||
// The arrays MUST have a specific length.
|
// The arrays MUST have a specific length.
|
||||||
Array.Resize(ref _moles, Atmospherics.TotalNumberOfGases);
|
Array.Resize(ref _moles, length);
|
||||||
Array.Resize(ref _molesArchived, Atmospherics.TotalNumberOfGases);
|
Array.Resize(ref _molesArchived, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object? obj)
|
public override bool Equals(object? obj)
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ namespace Content.Server.Atmos
|
|||||||
for (var i = 0; i < Atmospherics.Directions; i++)
|
for (var i = 0; i < Atmospherics.Directions; i++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << i);
|
var direction = (AtmosDirection) (1 << i);
|
||||||
if (!_adjacentBits.HasFlag(direction)) continue;
|
if (!_adjacentBits.IsFlagSet(direction)) continue;
|
||||||
var other = _adjacentTiles[i];
|
var other = _adjacentTiles[i];
|
||||||
if (other?.Air == null) continue;
|
if (other?.Air == null) continue;
|
||||||
var comparisonMoles = other.Air.TotalMoles;
|
var comparisonMoles = other.Air.TotalMoles;
|
||||||
@@ -288,7 +288,7 @@ namespace Content.Server.Atmos
|
|||||||
for (var j = 0; j < Atmospherics.Directions; j++)
|
for (var j = 0; j < Atmospherics.Directions; j++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << j);
|
var direction = (AtmosDirection) (1 << j);
|
||||||
if (!exploring._adjacentBits.HasFlag(direction)) continue;
|
if (!exploring._adjacentBits.IsFlagSet(direction)) continue;
|
||||||
var adj = exploring._adjacentTiles[j];
|
var adj = exploring._adjacentTiles[j];
|
||||||
if (adj?.Air == null) continue;
|
if (adj?.Air == null) continue;
|
||||||
if(adj._tileAtmosInfo.LastQueueCycle == queueCycle) continue;
|
if(adj._tileAtmosInfo.LastQueueCycle == queueCycle) continue;
|
||||||
@@ -360,7 +360,7 @@ namespace Content.Server.Atmos
|
|||||||
for (var j = 0; j < Atmospherics.Directions; j++)
|
for (var j = 0; j < Atmospherics.Directions; j++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << j);
|
var direction = (AtmosDirection) (1 << j);
|
||||||
if (!tile._adjacentBits.HasFlag(direction)) continue;
|
if (!tile._adjacentBits.IsFlagSet(direction)) continue;
|
||||||
var tile2 = tile._adjacentTiles[j];
|
var tile2 = tile._adjacentTiles[j];
|
||||||
|
|
||||||
// skip anything that isn't part of our current processing block.
|
// skip anything that isn't part of our current processing block.
|
||||||
@@ -378,7 +378,7 @@ namespace Content.Server.Atmos
|
|||||||
for (var j = 0; j < Atmospherics.Directions; j++)
|
for (var j = 0; j < Atmospherics.Directions; j++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << j);
|
var direction = (AtmosDirection) (1 << j);
|
||||||
if (!eligibleDirections.HasFlag(direction)) continue;
|
if (!eligibleDirections.IsFlagSet(direction)) continue;
|
||||||
|
|
||||||
tile.AdjustEqMovement(direction, molesToMove);
|
tile.AdjustEqMovement(direction, molesToMove);
|
||||||
tile._tileAtmosInfo.MoleDelta -= molesToMove;
|
tile._tileAtmosInfo.MoleDelta -= molesToMove;
|
||||||
@@ -425,7 +425,7 @@ namespace Content.Server.Atmos
|
|||||||
for (var k = 0; k < Atmospherics.Directions; k++)
|
for (var k = 0; k < Atmospherics.Directions; k++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << k);
|
var direction = (AtmosDirection) (1 << k);
|
||||||
if (!tile._adjacentBits.HasFlag(direction)) continue;
|
if (!tile._adjacentBits.IsFlagSet(direction)) continue;
|
||||||
var tile2 = tile._adjacentTiles[k];
|
var tile2 = tile._adjacentTiles[k];
|
||||||
if (giver._tileAtmosInfo.MoleDelta <= 0) break; // We're done here now. Let's not do more work than needed.
|
if (giver._tileAtmosInfo.MoleDelta <= 0) break; // We're done here now. Let's not do more work than needed.
|
||||||
if (tile2._tileAtmosInfo.LastQueueCycle != queueCycle) continue;
|
if (tile2._tileAtmosInfo.LastQueueCycle != queueCycle) continue;
|
||||||
@@ -493,7 +493,7 @@ namespace Content.Server.Atmos
|
|||||||
for (var k = 0; k < Atmospherics.Directions; k++)
|
for (var k = 0; k < Atmospherics.Directions; k++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << k);
|
var direction = (AtmosDirection) (1 << k);
|
||||||
if (!tile._adjacentBits.HasFlag(direction)) continue;
|
if (!tile._adjacentBits.IsFlagSet(direction)) continue;
|
||||||
var tile2 = tile._adjacentTiles[k];
|
var tile2 = tile._adjacentTiles[k];
|
||||||
|
|
||||||
if (taker._tileAtmosInfo.MoleDelta >= 0) break; // We're done here now. Let's not do more work than needed.
|
if (taker._tileAtmosInfo.MoleDelta >= 0) break; // We're done here now. Let's not do more work than needed.
|
||||||
@@ -554,7 +554,7 @@ namespace Content.Server.Atmos
|
|||||||
for (var j = 0; j < Atmospherics.Directions; j++)
|
for (var j = 0; j < Atmospherics.Directions; j++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << j);
|
var direction = (AtmosDirection) (1 << j);
|
||||||
if (!tile._adjacentBits.HasFlag(direction)) continue;
|
if (!tile._adjacentBits.IsFlagSet(direction)) continue;
|
||||||
var tile2 = tile._adjacentTiles[j];
|
var tile2 = tile._adjacentTiles[j];
|
||||||
if (tile2?.Air?.Compare(Air) == GasMixture.GasCompareResult.NoExchange) continue;
|
if (tile2?.Air?.Compare(Air) == GasMixture.GasCompareResult.NoExchange) continue;
|
||||||
_gridAtmosphereComponent.AddActiveTile(tile2);
|
_gridAtmosphereComponent.AddActiveTile(tile2);
|
||||||
@@ -587,7 +587,7 @@ namespace Content.Server.Atmos
|
|||||||
for(var i = 0; i < Atmospherics.Directions; i++)
|
for(var i = 0; i < Atmospherics.Directions; i++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << i);
|
var direction = (AtmosDirection) (1 << i);
|
||||||
if (!_adjacentBits.HasFlag(direction)) continue;
|
if (!_adjacentBits.IsFlagSet(direction)) continue;
|
||||||
var amount = transferDirections[i];
|
var amount = transferDirections[i];
|
||||||
var tile = _adjacentTiles[i];
|
var tile = _adjacentTiles[i];
|
||||||
if (tile?.Air == null) continue;
|
if (tile?.Air == null) continue;
|
||||||
@@ -612,7 +612,7 @@ namespace Content.Server.Atmos
|
|||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << i);
|
var direction = (AtmosDirection) (1 << i);
|
||||||
var amount = transferDirs[i];
|
var amount = transferDirs[i];
|
||||||
if(amount < 0 && _adjacentBits.HasFlag(direction))
|
if(amount < 0 && _adjacentBits.IsFlagSet(direction))
|
||||||
_adjacentTiles[i].FinalizeEq(); // A bit of recursion if needed.
|
_adjacentTiles[i].FinalizeEq(); // A bit of recursion if needed.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -654,14 +654,14 @@ namespace Content.Server.Atmos
|
|||||||
for (var i = 0; i < Atmospherics.Directions; i++)
|
for (var i = 0; i < Atmospherics.Directions; i++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << i);
|
var direction = (AtmosDirection) (1 << i);
|
||||||
if(_adjacentBits.HasFlag(direction))
|
if(_adjacentBits.IsFlagSet(direction))
|
||||||
adjacentTileLength++;
|
adjacentTileLength++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var i = 0; i < Atmospherics.Directions; i++)
|
for(var i = 0; i < Atmospherics.Directions; i++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << i);
|
var direction = (AtmosDirection) (1 << i);
|
||||||
if (!_adjacentBits.HasFlag(direction)) continue;
|
if (!_adjacentBits.IsFlagSet(direction)) continue;
|
||||||
var enemyTile = _adjacentTiles[i];
|
var enemyTile = _adjacentTiles[i];
|
||||||
|
|
||||||
// If the tile is null or has no air, we don't do anything for it.
|
// If the tile is null or has no air, we don't do anything for it.
|
||||||
@@ -848,7 +848,7 @@ namespace Content.Server.Atmos
|
|||||||
for(var i = 0; i < Atmospherics.Directions; i++)
|
for(var i = 0; i < Atmospherics.Directions; i++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << i);
|
var direction = (AtmosDirection) (1 << i);
|
||||||
if (!directions.HasFlag(direction)) continue;
|
if (!directions.IsFlagSet(direction)) continue;
|
||||||
|
|
||||||
var adjacent = _adjacentTiles[direction.ToIndex()];
|
var adjacent = _adjacentTiles[direction.ToIndex()];
|
||||||
|
|
||||||
@@ -1002,7 +1002,7 @@ namespace Content.Server.Atmos
|
|||||||
for (var j = 0; j < Atmospherics.Directions; j++)
|
for (var j = 0; j < Atmospherics.Directions; j++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << j);
|
var direction = (AtmosDirection) (1 << j);
|
||||||
if (!tile._adjacentBits.HasFlag(direction)) continue;
|
if (!tile._adjacentBits.IsFlagSet(direction)) continue;
|
||||||
var tile2 = tile._adjacentTiles[j];
|
var tile2 = tile._adjacentTiles[j];
|
||||||
if (tile2.Air == null) continue;
|
if (tile2.Air == null) continue;
|
||||||
if (tile2._tileAtmosInfo.LastQueueCycle == queueCycle) continue;
|
if (tile2._tileAtmosInfo.LastQueueCycle == queueCycle) continue;
|
||||||
@@ -1010,7 +1010,7 @@ namespace Content.Server.Atmos
|
|||||||
tile.ConsiderFirelocks(tile2);
|
tile.ConsiderFirelocks(tile2);
|
||||||
|
|
||||||
// The firelocks might have closed on us.
|
// The firelocks might have closed on us.
|
||||||
if (!tile._adjacentBits.HasFlag(direction)) continue;
|
if (!tile._adjacentBits.IsFlagSet(direction)) continue;
|
||||||
tile2._tileAtmosInfo = new TileAtmosInfo {LastQueueCycle = queueCycle};
|
tile2._tileAtmosInfo = new TileAtmosInfo {LastQueueCycle = queueCycle};
|
||||||
tiles[tileCount++] = tile2;
|
tiles[tileCount++] = tile2;
|
||||||
}
|
}
|
||||||
@@ -1039,7 +1039,7 @@ namespace Content.Server.Atmos
|
|||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << j);
|
var direction = (AtmosDirection) (1 << j);
|
||||||
// TODO ATMOS This is a terrible hack that accounts for the mess that are space TileAtmospheres.
|
// TODO ATMOS This is a terrible hack that accounts for the mess that are space TileAtmospheres.
|
||||||
if (!tile._adjacentBits.HasFlag(direction) && !tile.Air.Immutable) continue;
|
if (!tile._adjacentBits.IsFlagSet(direction) && !tile.Air.Immutable) continue;
|
||||||
var tile2 = tile._adjacentTiles[j];
|
var tile2 = tile._adjacentTiles[j];
|
||||||
if (tile2?._tileAtmosInfo.LastQueueCycle != queueCycle) continue;
|
if (tile2?._tileAtmosInfo.LastQueueCycle != queueCycle) continue;
|
||||||
if (tile2._tileAtmosInfo.LastSlowQueueCycle == queueCycleSlow) continue;
|
if (tile2._tileAtmosInfo.LastSlowQueueCycle == queueCycleSlow) continue;
|
||||||
@@ -1156,7 +1156,7 @@ namespace Content.Server.Atmos
|
|||||||
_adjacentTiles[direction.ToIndex()] = adjacent;
|
_adjacentTiles[direction.ToIndex()] = adjacent;
|
||||||
adjacent?.UpdateAdjacent(direction.GetOpposite());
|
adjacent?.UpdateAdjacent(direction.GetOpposite());
|
||||||
|
|
||||||
if (adjacent != null && !BlockedAirflow.HasFlag(direction) && !_gridAtmosphereComponent.IsAirBlocked(adjacent.GridIndices, direction.GetOpposite()))
|
if (adjacent != null && !BlockedAirflow.IsFlagSet(direction) && !_gridAtmosphereComponent.IsAirBlocked(adjacent.GridIndices, direction.GetOpposite()))
|
||||||
{
|
{
|
||||||
_adjacentBits |= direction;
|
_adjacentBits |= direction;
|
||||||
}
|
}
|
||||||
@@ -1167,7 +1167,7 @@ namespace Content.Server.Atmos
|
|||||||
{
|
{
|
||||||
_adjacentTiles[direction.ToIndex()] = _gridAtmosphereComponent.GetTile(GridIndices.Offset(direction.ToDirection()));
|
_adjacentTiles[direction.ToIndex()] = _gridAtmosphereComponent.GetTile(GridIndices.Offset(direction.ToDirection()));
|
||||||
|
|
||||||
if (!BlockedAirflow.HasFlag(direction) && !_gridAtmosphereComponent.IsAirBlocked(GridIndices.Offset(direction.ToDirection()), direction.GetOpposite()))
|
if (!BlockedAirflow.IsFlagSet(direction) && !_gridAtmosphereComponent.IsAirBlocked(GridIndices.Offset(direction.ToDirection()), direction.GetOpposite()))
|
||||||
{
|
{
|
||||||
_adjacentBits |= direction;
|
_adjacentBits |= direction;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
for (var i = 0; i < Atmospherics.Directions; i++)
|
for (var i = 0; i < Atmospherics.Directions; i++)
|
||||||
{
|
{
|
||||||
var direction = (AtmosDirection) (1 << i);
|
var direction = (AtmosDirection) (1 << i);
|
||||||
if (!myDirection.HasFlag(direction)) continue;
|
if (!myDirection.IsFlagSet(direction)) continue;
|
||||||
var angle = direction.ToAngle();
|
var angle = direction.ToAngle();
|
||||||
angle += myAngle;
|
angle += myAngle;
|
||||||
newAirBlockedDirs |= angle.ToAtmosDirectionCardinal();
|
newAirBlockedDirs |= angle.ToAtmosDirectionCardinal();
|
||||||
|
|||||||
@@ -233,6 +233,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
|
|
||||||
private InternalsComponent? GetInternalsComponent(IEntity? owner = null)
|
private InternalsComponent? GetInternalsComponent(IEntity? owner = null)
|
||||||
{
|
{
|
||||||
|
if (Owner.Deleted) return null;
|
||||||
if (owner != null) return owner.GetComponentOrNull<InternalsComponent>();
|
if (owner != null) return owner.GetComponentOrNull<InternalsComponent>();
|
||||||
return Owner.TryGetContainer(out var container)
|
return Owner.TryGetContainer(out var container)
|
||||||
? container.Owner.GetComponentOrNull<InternalsComponent>()
|
? container.Owner.GetComponentOrNull<InternalsComponent>()
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using Content.Shared.Maps;
|
|||||||
using Robust.Server.GameObjects.EntitySystems.TileLookup;
|
using Robust.Server.GameObjects.EntitySystems.TileLookup;
|
||||||
using Robust.Server.Interfaces.GameObjects;
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.GameObjects.ComponentDependencies;
|
||||||
using Robust.Shared.GameObjects.Components.Map;
|
using Robust.Shared.GameObjects.Components.Map;
|
||||||
using Robust.Shared.GameObjects.Components.Transform;
|
using Robust.Shared.GameObjects.Components.Transform;
|
||||||
using Robust.Shared.GameObjects.Systems;
|
using Robust.Shared.GameObjects.Systems;
|
||||||
@@ -65,6 +66,8 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
private Stopwatch _stopwatch = new Stopwatch();
|
private Stopwatch _stopwatch = new Stopwatch();
|
||||||
private GridId _gridId;
|
private GridId _gridId;
|
||||||
|
|
||||||
|
[ComponentDependency] private IMapGridComponent? _mapGridComponent = default!;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public int UpdateCounter { get; private set; } = 0;
|
public int UpdateCounter { get; private set; } = 0;
|
||||||
|
|
||||||
@@ -217,7 +220,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
|
|
||||||
protected virtual void Revalidate()
|
protected virtual void Revalidate()
|
||||||
{
|
{
|
||||||
foreach (var indices in _invalidatedCoords.ToArray())
|
foreach (var indices in _invalidatedCoords)
|
||||||
{
|
{
|
||||||
var tile = GetTile(indices);
|
var tile = GetTile(indices);
|
||||||
|
|
||||||
@@ -259,7 +262,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
// TODO ATMOS: Query all the contents of this tile (like walls) and calculate the correct thermal conductivity
|
// TODO ATMOS: Query all the contents of this tile (like walls) and calculate the correct thermal conductivity
|
||||||
tile.ThermalConductivity = tile.Tile?.Tile.GetContentTileDefinition().ThermalConductivity ?? 0.5f;
|
tile.ThermalConductivity = tile.Tile?.Tile.GetContentTileDefinition().ThermalConductivity ?? 0.5f;
|
||||||
tile.UpdateAdjacent();
|
tile.UpdateAdjacent();
|
||||||
tile.UpdateVisuals();
|
GasTileOverlaySystem.Invalidate(_gridId, indices);
|
||||||
|
|
||||||
for (var i = 0; i < Atmospherics.Directions; i++)
|
for (var i = 0; i < Atmospherics.Directions; i++)
|
||||||
{
|
{
|
||||||
@@ -420,12 +423,18 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsAirBlocked(Vector2i indices, AtmosDirection direction = AtmosDirection.All)
|
public bool IsAirBlocked(Vector2i indices, AtmosDirection direction = AtmosDirection.All)
|
||||||
{
|
{
|
||||||
|
var directions = AtmosDirection.Invalid;
|
||||||
|
|
||||||
foreach (var obstructingComponent in GetObstructingComponents(indices))
|
foreach (var obstructingComponent in GetObstructingComponents(indices))
|
||||||
{
|
{
|
||||||
if (!obstructingComponent.AirBlocked)
|
if (!obstructingComponent.AirBlocked)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (obstructingComponent.AirBlockedDirection.HasFlag(direction))
|
// We set the directions that are air-blocked so far,
|
||||||
|
// as you could have a full obstruction with only 4 directional air blockers.
|
||||||
|
directions |= obstructingComponent.AirBlockedDirection;
|
||||||
|
|
||||||
|
if (directions.IsFlagSet(direction))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,10 +444,9 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual bool IsSpace(Vector2i indices)
|
public virtual bool IsSpace(Vector2i indices)
|
||||||
{
|
{
|
||||||
// TODO ATMOS use ContentTileDefinition to define in YAML whether or not a tile is considered space
|
if (_mapGridComponent == null) return default;
|
||||||
if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return default;
|
|
||||||
|
|
||||||
return mapGrid.Grid.GetTileRef(indices).Tile.IsEmpty;
|
return _mapGridComponent.Grid.GetTileRef(indices).IsSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(Vector2i indices, bool includeAirBlocked = false)
|
public Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(Vector2i indices, bool includeAirBlocked = false)
|
||||||
@@ -461,9 +469,9 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public float GetVolumeForCells(int cellCount)
|
public float GetVolumeForCells(int cellCount)
|
||||||
{
|
{
|
||||||
if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return default;
|
if (_mapGridComponent == null) return default;
|
||||||
|
|
||||||
return mapGrid.Grid.TileSize * cellCount * Atmospherics.CellVolume;
|
return _mapGridComponent.Grid.TileSize * cellCount * Atmospherics.CellVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -797,15 +805,11 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
{
|
{
|
||||||
var gridLookup = EntitySystem.Get<GridTileLookupSystem>();
|
var gridLookup = EntitySystem.Get<GridTileLookupSystem>();
|
||||||
|
|
||||||
var list = new List<AirtightComponent>();
|
|
||||||
|
|
||||||
foreach (var v in gridLookup.GetEntitiesIntersecting(_gridId, indices))
|
foreach (var v in gridLookup.GetEntitiesIntersecting(_gridId, indices))
|
||||||
{
|
{
|
||||||
if (v.TryGetComponent<AirtightComponent>(out var ac))
|
if (v.TryGetComponent<AirtightComponent>(out var ac))
|
||||||
list.Add(ac);
|
yield return ac;
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool NeedsVacuumFixing(Vector2i indices)
|
private bool NeedsVacuumFixing(Vector2i indices)
|
||||||
@@ -841,8 +845,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
public override void ExposeData(ObjectSerializer serializer)
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
if (serializer.Reading &&
|
if (serializer.Reading && Owner.TryGetComponent(out IMapGridComponent? mapGrid))
|
||||||
Owner.TryGetComponent(out IMapGridComponent? mapGrid))
|
|
||||||
{
|
{
|
||||||
var gridId = mapGrid.Grid.Index;
|
var gridId = mapGrid.Grid.Index;
|
||||||
|
|
||||||
|
|||||||
@@ -243,6 +243,7 @@ namespace Content.Server.GameObjects.Components.Medical
|
|||||||
public void EjectBody()
|
public void EjectBody()
|
||||||
{
|
{
|
||||||
var containedEntity = _bodyContainer.ContainedEntity;
|
var containedEntity = _bodyContainer.ContainedEntity;
|
||||||
|
if (containedEntity == null) return;
|
||||||
_bodyContainer.Remove(containedEntity);
|
_bodyContainer.Remove(containedEntity);
|
||||||
containedEntity.Transform.WorldPosition += _ejectOffset;
|
containedEntity.Transform.WorldPosition += _ejectOffset;
|
||||||
UpdateUserInterface();
|
UpdateUserInterface();
|
||||||
|
|||||||
@@ -156,11 +156,12 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
|
|||||||
|
|
||||||
var tileData = new List<GasData>();
|
var tileData = new List<GasData>();
|
||||||
|
|
||||||
|
if(tile.Air != null)
|
||||||
for (byte i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
for (byte i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
||||||
{
|
{
|
||||||
var gas = _atmosphereSystem.GetGas(i);
|
var gas = _atmosphereSystem.GetGas(i);
|
||||||
var overlay = _atmosphereSystem.GetOverlay(i);
|
var overlay = _atmosphereSystem.GetOverlay(i);
|
||||||
if (overlay == null || tile?.Air == null) continue;
|
if (overlay == null) continue;
|
||||||
|
|
||||||
var moles = tile.Air.Gases[i];
|
var moles = tile.Air.Gases[i];
|
||||||
|
|
||||||
@@ -170,7 +171,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
|
|||||||
tileData.Add(data);
|
tileData.Add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
overlayData = new GasOverlayData(tile!.Hotspot.State, tile.Hotspot.Temperature, tileData.Count == 0 ? null : tileData.ToArray());
|
overlayData = new GasOverlayData(tile!.Hotspot.State, tile.Hotspot.Temperature, tileData.Count == 0 ? Array.Empty<GasData>() : tileData.ToArray());
|
||||||
|
|
||||||
if (overlayData.Equals(oldTile))
|
if (overlayData.Equals(oldTile))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ using System.Linq;
|
|||||||
using Content.Server.Atmos;
|
using Content.Server.Atmos;
|
||||||
using Content.Server.Atmos.Reactions;
|
using Content.Server.Atmos.Reactions;
|
||||||
using Content.Server.GameObjects.Components.Atmos;
|
using Content.Server.GameObjects.Components.Atmos;
|
||||||
|
using Content.Shared.Atmos;
|
||||||
using Content.Shared.GameObjects.EntitySystems.Atmos;
|
using Content.Shared.GameObjects.EntitySystems.Atmos;
|
||||||
|
using Content.Shared.Maps;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects.EntitySystems.TileLookup;
|
using Robust.Server.GameObjects.EntitySystems.TileLookup;
|
||||||
using Robust.Server.Interfaces.Timing;
|
using Robust.Server.Interfaces.Timing;
|
||||||
@@ -17,6 +19,7 @@ using Robust.Shared.Interfaces.GameObjects;
|
|||||||
using Robust.Shared.Interfaces.Map;
|
using Robust.Shared.Interfaces.Map;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.EntitySystems
|
namespace Content.Server.GameObjects.EntitySystems
|
||||||
@@ -38,6 +41,9 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<GasReactionPrototype> GasReactions => _gasReactions!;
|
public IEnumerable<GasReactionPrototype> GasReactions => _gasReactions!;
|
||||||
|
|
||||||
|
private float[] _gasSpecificHeats = new float[Atmospherics.TotalNumberOfGases];
|
||||||
|
public float[] GasSpecificHeats => _gasSpecificHeats;
|
||||||
|
|
||||||
public GridTileLookupSystem GridTileLookupSystem => _gridTileLookup ??= Get<GridTileLookupSystem>();
|
public GridTileLookupSystem GridTileLookupSystem => _gridTileLookup ??= Get<GridTileLookupSystem>();
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -53,6 +59,13 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
|
|
||||||
_mapManager.TileChanged += OnTileChanged;
|
_mapManager.TileChanged += OnTileChanged;
|
||||||
|
|
||||||
|
Array.Resize(ref _gasSpecificHeats, MathHelper.NextMultipleOf(Atmospherics.TotalNumberOfGases, 4));
|
||||||
|
|
||||||
|
for (var i = 0; i < GasPrototypes.Length; i++)
|
||||||
|
{
|
||||||
|
_gasSpecificHeats[i] = GasPrototypes[i].SpecificHeat;
|
||||||
|
}
|
||||||
|
|
||||||
// Required for airtight components.
|
// Required for airtight components.
|
||||||
EntityManager.EventBus.SubscribeEvent<RotateEvent>(EventSource.Local, this, RotateEvent);
|
EntityManager.EventBus.SubscribeEvent<RotateEvent>(EventSource.Local, this, RotateEvent);
|
||||||
}
|
}
|
||||||
@@ -104,7 +117,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
// space -> not space or vice versa. So if the old tile is the
|
// space -> not space or vice versa. So if the old tile is the
|
||||||
// same as the new tile in terms of space-ness, ignore the change
|
// same as the new tile in terms of space-ness, ignore the change
|
||||||
|
|
||||||
if (eventArgs.NewTile.Tile.IsEmpty == eventArgs.OldTile.IsEmpty)
|
if (eventArgs.NewTile.IsSpace() == eventArgs.OldTile.IsSpace())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
@@ -135,6 +136,12 @@ namespace Content.Shared.Atmos
|
|||||||
{
|
{
|
||||||
return direction & ~other;
|
return direction & ~other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool IsFlagSet(this AtmosDirection direction, AtmosDirection other)
|
||||||
|
{
|
||||||
|
return (direction & other) != 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class AtmosDirectionFlags { }
|
public sealed class AtmosDirectionFlags { }
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Content.Shared.Construction.ConstructionConditions
|
|||||||
if (tileFound == null)
|
if (tileFound == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var tile = TurfHelpers.GetContentTileDefinition(tileFound.Value.Tile);
|
var tile = tileFound.Value.Tile.GetContentTileDefinition();
|
||||||
foreach (var targetTile in TargetTiles)
|
foreach (var targetTile in TargetTiles)
|
||||||
{
|
{
|
||||||
if (tile.Name == targetTile) {
|
if (tile.Name == targetTile) {
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
|
||||||
private readonly GasPrototype[] GasPrototypes = new GasPrototype[Atmospherics.TotalNumberOfGases];
|
protected readonly GasPrototype[] GasPrototypes = new GasPrototype[Atmospherics.TotalNumberOfGases];
|
||||||
|
|
||||||
private readonly SpriteSpecifier[] GasOverlays = new SpriteSpecifier[Atmospherics.TotalNumberOfGases];
|
private readonly SpriteSpecifier[] _gasOverlays = new SpriteSpecifier[Atmospherics.TotalNumberOfGases];
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -25,10 +25,10 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
|||||||
GasPrototypes[i] = gasPrototype;
|
GasPrototypes[i] = gasPrototype;
|
||||||
|
|
||||||
if(string.IsNullOrEmpty(gasPrototype.GasOverlaySprite) && !string.IsNullOrEmpty(gasPrototype.GasOverlayTexture))
|
if(string.IsNullOrEmpty(gasPrototype.GasOverlaySprite) && !string.IsNullOrEmpty(gasPrototype.GasOverlayTexture))
|
||||||
GasOverlays[i] = new SpriteSpecifier.Texture(new ResourcePath(gasPrototype.GasOverlayTexture));
|
_gasOverlays[i] = new SpriteSpecifier.Texture(new ResourcePath(gasPrototype.GasOverlayTexture));
|
||||||
|
|
||||||
if(!string.IsNullOrEmpty(gasPrototype.GasOverlaySprite) && !string.IsNullOrEmpty(gasPrototype.GasOverlayState))
|
if(!string.IsNullOrEmpty(gasPrototype.GasOverlaySprite) && !string.IsNullOrEmpty(gasPrototype.GasOverlayState))
|
||||||
GasOverlays[i] = new SpriteSpecifier.Rsi(new ResourcePath(gasPrototype.GasOverlaySprite), gasPrototype.GasOverlayState);
|
_gasOverlays[i] = new SpriteSpecifier.Rsi(new ResourcePath(gasPrototype.GasOverlaySprite), gasPrototype.GasOverlayState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +38,6 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
|||||||
|
|
||||||
public IEnumerable<GasPrototype> Gases => GasPrototypes;
|
public IEnumerable<GasPrototype> Gases => GasPrototypes;
|
||||||
|
|
||||||
public SpriteSpecifier GetOverlay(int overlayId) => GasOverlays[overlayId];
|
public SpriteSpecifier GetOverlay(int overlayId) => _gasOverlays[overlayId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,16 +20,26 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public struct GasData
|
public readonly struct GasData : IEquatable<GasData>
|
||||||
{
|
{
|
||||||
public byte Index { get; set; }
|
public readonly byte Index;
|
||||||
public byte Opacity { get; set; }
|
public readonly byte Opacity;
|
||||||
|
|
||||||
public GasData(byte gasId, byte opacity)
|
public GasData(byte gasId, byte opacity)
|
||||||
{
|
{
|
||||||
Index = gasId;
|
Index = gasId;
|
||||||
Opacity = opacity;
|
Opacity = opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return HashCode.Combine(Index, Opacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(GasData other)
|
||||||
|
{
|
||||||
|
return other.Index == Index && other.Opacity == Opacity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
@@ -38,40 +48,49 @@ namespace Content.Shared.GameObjects.EntitySystems.Atmos
|
|||||||
public readonly byte FireState;
|
public readonly byte FireState;
|
||||||
public readonly float FireTemperature;
|
public readonly float FireTemperature;
|
||||||
public readonly GasData[] Gas;
|
public readonly GasData[] Gas;
|
||||||
|
public readonly int HashCode;
|
||||||
|
|
||||||
public GasOverlayData(byte fireState, float fireTemperature, GasData[] gas)
|
public GasOverlayData(byte fireState, float fireTemperature, GasData[] gas)
|
||||||
{
|
{
|
||||||
FireState = fireState;
|
FireState = fireState;
|
||||||
FireTemperature = fireTemperature;
|
FireTemperature = fireTemperature;
|
||||||
Gas = gas;
|
Gas = gas ?? Array.Empty<GasData>();
|
||||||
|
|
||||||
|
Array.Sort(Gas, (a, b) => a.Index.CompareTo(b.Index));
|
||||||
|
|
||||||
|
var hash = new HashCode();
|
||||||
|
hash.Add(FireState);
|
||||||
|
hash.Add(FireTemperature);
|
||||||
|
|
||||||
|
foreach (var gasData in Gas)
|
||||||
|
{
|
||||||
|
hash.Add(gasData);
|
||||||
|
}
|
||||||
|
|
||||||
|
HashCode = hash.ToHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return HashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(GasOverlayData other)
|
public bool Equals(GasOverlayData other)
|
||||||
{
|
{
|
||||||
// TODO: Moony had a suggestion on how to do this faster with the hash
|
|
||||||
// https://discordapp.com/channels/310555209753690112/310555209753690112/744080145219846204
|
if (HashCode != other.HashCode) return false;
|
||||||
// Aside from that I can't really see any low-hanging fruit CPU perf wise.
|
if (Gas.Length != other.Gas.Length) return false;
|
||||||
if (Gas?.Length != other.Gas?.Length) return false;
|
|
||||||
if (FireState != other.FireState) return false;
|
if (FireState != other.FireState) return false;
|
||||||
if (FireTemperature != other.FireTemperature) return false;
|
if (MathHelper.CloseTo(FireTemperature, FireTemperature)) return false;
|
||||||
|
if (Gas.GetHashCode() != other.Gas.GetHashCode()) return false;
|
||||||
if (Gas == null)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
DebugTools.Assert(other.Gas != null);
|
|
||||||
|
|
||||||
for (var i = 0; i < Gas.Length; i++)
|
for (var i = 0; i < Gas.Length; i++)
|
||||||
{
|
{
|
||||||
var thisGas = Gas[i];
|
var gas = Gas[i];
|
||||||
var otherGas = other.Gas[i];
|
var otherGas = other.Gas[i];
|
||||||
|
if (!gas.Equals(otherGas))
|
||||||
if (!thisGas.Equals(otherGas))
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace Content.Shared.Maps
|
|||||||
public float Friction { get; set; }
|
public float Friction { get; set; }
|
||||||
public float ThermalConductivity { get; set; }
|
public float ThermalConductivity { get; set; }
|
||||||
public string ItemDropPrototypeName { get; private set; }
|
public string ItemDropPrototypeName { get; private set; }
|
||||||
|
public bool IsSpace { get; private set; }
|
||||||
|
|
||||||
public void AssignTileId(ushort id)
|
public void AssignTileId(ushort id)
|
||||||
{
|
{
|
||||||
@@ -47,6 +48,11 @@ namespace Content.Shared.Maps
|
|||||||
else
|
else
|
||||||
BaseTurfs = new List<string>();
|
BaseTurfs = new List<string>();
|
||||||
|
|
||||||
|
if (mapping.TryGetNode("is_space", out node))
|
||||||
|
{
|
||||||
|
IsSpace = node.AsBool();
|
||||||
|
}
|
||||||
|
|
||||||
if (mapping.TryGetNode("can_crowbar", out node))
|
if (mapping.TryGetNode("can_crowbar", out node))
|
||||||
{
|
{
|
||||||
CanCrowbar = node.AsBool();
|
CanCrowbar = node.AsBool();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Robust.Shared.Interfaces.GameObjects;
|
|||||||
using Robust.Shared.Interfaces.Map;
|
using Robust.Shared.Interfaces.Map;
|
||||||
using Robust.Shared.Interfaces.Physics;
|
using Robust.Shared.Interfaces.Physics;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Log;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
|
|
||||||
@@ -16,15 +17,6 @@ namespace Content.Shared.Maps
|
|||||||
{
|
{
|
||||||
public static class TurfHelpers
|
public static class TurfHelpers
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Returns the content tile definition for a tile.
|
|
||||||
/// </summary>
|
|
||||||
public static ContentTileDefinition GetContentTileDefinition(this Tile tile)
|
|
||||||
{
|
|
||||||
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
|
|
||||||
return (ContentTileDefinition)tileDefinitionManager[tile.TypeId];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to get the turf at map indices with grid id or null if no such turf is found.
|
/// Attempts to get the turf at map indices with grid id or null if no such turf is found.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -72,6 +64,39 @@ namespace Content.Shared.Maps
|
|||||||
return (turf = coordinates.GetTileRef()) != null;
|
return (turf = coordinates.GetTileRef()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the content tile definition for a tile.
|
||||||
|
/// </summary>
|
||||||
|
public static ContentTileDefinition GetContentTileDefinition(this Tile tile, ITileDefinitionManager? tileDefinitionManager = null)
|
||||||
|
{
|
||||||
|
tileDefinitionManager ??= IoCManager.Resolve<ITileDefinitionManager>();
|
||||||
|
return (ContentTileDefinition)tileDefinitionManager[tile.TypeId];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns whether a tile is considered space.
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsSpace(this Tile tile, ITileDefinitionManager? tileDefinitionManager = null)
|
||||||
|
{
|
||||||
|
return tile.GetContentTileDefinition(tileDefinitionManager).IsSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the content tile definition for a tile ref.
|
||||||
|
/// </summary>
|
||||||
|
public static ContentTileDefinition GetContentTileDefinition(this TileRef tile, ITileDefinitionManager? tileDefinitionManager = null)
|
||||||
|
{
|
||||||
|
return tile.Tile.GetContentTileDefinition(tileDefinitionManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns whether a tile ref is considered space.
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsSpace(this TileRef tile, ITileDefinitionManager? tileDefinitionManager = null)
|
||||||
|
{
|
||||||
|
return tile.Tile.IsSpace(tileDefinitionManager);
|
||||||
|
}
|
||||||
|
|
||||||
public static bool PryTile(this EntityCoordinates coordinates, IEntityManager? entityManager = null,
|
public static bool PryTile(this EntityCoordinates coordinates, IEntityManager? entityManager = null,
|
||||||
IMapManager? mapManager = null)
|
IMapManager? mapManager = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
is_subfloor: true
|
is_subfloor: true
|
||||||
footstep_sounds: footstep_plating
|
footstep_sounds: footstep_plating
|
||||||
friction: 0.5
|
friction: 0.5
|
||||||
|
is_space: true
|
||||||
|
|
||||||
- type: tile
|
- type: tile
|
||||||
name: underplating
|
name: underplating
|
||||||
|
|||||||
@@ -4,3 +4,4 @@
|
|||||||
texture: ""
|
texture: ""
|
||||||
friction: 0
|
friction: 0
|
||||||
is_subfloor: true
|
is_subfloor: true
|
||||||
|
is_space: true
|
||||||
|
|||||||
6
nuget.config
Normal file
6
nuget.config
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
|
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
|
||||||
|
</packageSources>
|
||||||
|
</configuration>
|
||||||
Reference in New Issue
Block a user