atmos more

This commit is contained in:
Vigers Ray 2025-06-03 19:13:36 +03:00
parent a32ca4d001
commit 4752a0a128
4 changed files with 63 additions and 8 deletions

View file

@ -0,0 +1,54 @@
using Content.Shared.Atmos;
namespace Content.Server.Atmos;
public static class AtmosDirectionExtensions
{
public static Vector2i ToVec(this AtmosDirection direction)
{
return direction switch
{
AtmosDirection.North => new Vector2i(0, 1),
AtmosDirection.South => new Vector2i(0, -1),
AtmosDirection.East => new Vector2i(1, 0),
AtmosDirection.West => new Vector2i(-1, 0),
_ => Vector2i.Zero
};
}
public static AtmosDirection GetOpposite(this AtmosDirection direction)
{
return direction switch
{
AtmosDirection.North => AtmosDirection.South,
AtmosDirection.South => AtmosDirection.North,
AtmosDirection.East => AtmosDirection.West,
AtmosDirection.West => AtmosDirection.East,
_ => AtmosDirection.Invalid
};
}
public static int ToIndex(this AtmosDirection direction)
{
return direction switch
{
AtmosDirection.North => 0,
AtmosDirection.South => 1,
AtmosDirection.East => 2,
AtmosDirection.West => 3,
_ => -1
};
}
public static int ToOppositeIndex(this int index)
{
return index switch
{
0 => 1,
1 => 0,
2 => 3,
3 => 2,
_ => -1
};
}
}

View file

@ -15,18 +15,21 @@ public sealed partial class AtmosphereSystem
private static readonly AtmosDirection[] CachedDirections;
private static readonly int[] CachedOppositeIndices;
private static readonly AtmosDirection[] CachedOppositeDirections;
private static readonly Vector2i[] CachedOffsets;
static AtmosphereSystem()
{
CachedDirections = new AtmosDirection[Atmospherics.Directions];
CachedOppositeIndices = new int[Atmospherics.Directions];
CachedOppositeDirections = new AtmosDirection[Atmospherics.Directions];
CachedOffsets = new Vector2i[Atmospherics.Directions];
for (var i = 0; i < Atmospherics.Directions; i++)
{
CachedDirections[i] = (AtmosDirection)(1 << i);
CachedOppositeIndices[i] = i.ToOppositeIndex();
CachedOppositeDirections[i] = (AtmosDirection)(1 << CachedOppositeIndices[i]);
CachedOffsets[i] = ((AtmosDirection)(1 << i)).ToVec();
}
}
@ -197,7 +200,7 @@ public sealed partial class AtmosphereSystem
for (var i = 0; i < Atmospherics.Directions; i++)
{
var direction = CachedDirections[i];
var adjacentIndices = tile.GridIndices.Offset(direction);
var adjacentIndices = tile.GridIndices + CachedOffsets[i];
TileAtmosphere? adjacent;
if (!tile.NoGridTile)

View file

@ -28,14 +28,13 @@ namespace Content.Server.Atmos.EntitySystems
for (var i = 0; i < Atmospherics.Directions; i++)
{
var direction = (AtmosDirection) (1 << i);
if(tile.AdjacentBits.IsFlagSet(direction))
if(tile.AdjacentBits.IsFlagSet(CachedDirections[i]))
adjacentTileLength++;
}
for(var i = 0; i < Atmospherics.Directions; i++)
{
var direction = (AtmosDirection) (1 << i);
var direction = CachedDirections[i];
if (!tile.AdjacentBits.IsFlagSet(direction)) continue;
var enemyTile = tile.AdjacentTiles[i];
@ -54,13 +53,13 @@ namespace Content.Server.Atmos.EntitySystems
}
shouldShareAir = true;
} else if (CompareExchange(tile, enemyTile) != GasCompareResult.NoExchange)
}
else if (CompareExchange(tile, enemyTile) != GasCompareResult.NoExchange)
{
AddActiveTile(gridAtmosphere, enemyTile);
if (ExcitedGroups)
{
var excitedGroup = tile.ExcitedGroup;
excitedGroup ??= enemyTile.ExcitedGroup;
var excitedGroup = tile.ExcitedGroup ?? enemyTile.ExcitedGroup;
if (excitedGroup == null)
{

View file

@ -255,7 +255,6 @@ namespace Content.Server.Atmos.EntitySystems
float volume)
{
var atmos = ent.Comp1;
var mapGrid = ent.Comp3;
if (tile.AirtightData.NoAirWhenBlocked && tile.AirtightData.BlockedDirections != AtmosDirection.Invalid)
{