From 4752a0a128b790933bd2f76191094f65a690342d Mon Sep 17 00:00:00 2001 From: Vigers Ray Date: Tue, 3 Jun 2025 19:13:36 +0300 Subject: [PATCH] atmos more --- .../Atmos/AtmosDirectionExtensions.cs | 54 +++++++++++++++++++ .../AtmosphereSystem.GridAtmosphere.cs | 5 +- .../EntitySystems/AtmosphereSystem.LINDA.cs | 11 ++-- .../AtmosphereSystem.Processing.cs | 1 - 4 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 Content.Server/Atmos/AtmosDirectionExtensions.cs diff --git a/Content.Server/Atmos/AtmosDirectionExtensions.cs b/Content.Server/Atmos/AtmosDirectionExtensions.cs new file mode 100644 index 0000000000..32470055c5 --- /dev/null +++ b/Content.Server/Atmos/AtmosDirectionExtensions.cs @@ -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 + }; + } +} diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.GridAtmosphere.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.GridAtmosphere.cs index 30c4b55740..9f7c42ebed 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.GridAtmosphere.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.GridAtmosphere.cs @@ -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) diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.LINDA.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.LINDA.cs index 55b38924c0..6e6f2c2702 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.LINDA.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.LINDA.cs @@ -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) { diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Processing.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Processing.cs index 6f44b7726b..577bd286a1 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Processing.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Processing.cs @@ -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) {