AtmosphereSystem no longer creates a component manually. (#3839)

- Maps get SpaceGridAtmosphereComponent added automatically
This commit is contained in:
Vera Aguilera Puerto
2021-04-13 13:17:10 +02:00
committed by GitHub
parent 30d5b58319
commit c17426dfa7
21 changed files with 97 additions and 257 deletions

View File

@@ -1,172 +0,0 @@
using System.Threading.Tasks;
using Content.Server.Atmos;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests.Atmos
{
[TestFixture]
[TestOf(typeof(AtmosHelpersTest))]
public class AtmosHelpersTest : ContentIntegrationTest
{
[Test]
public async Task GetTileAtmosphereEntityCoordinatesNotNullTest()
{
var server = StartServerDummyTicker();
await server.WaitIdleAsync();
var entityManager = server.ResolveDependency<IEntityManager>();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var atmosphere1 = default(EntityCoordinates).GetTileAtmosphere();
var atmosphere2 = default(EntityCoordinates).GetTileAtmosphere(entityManager);
Assert.NotNull(atmosphere1);
Assert.NotNull(atmosphere2);
});
});
await server.WaitIdleAsync();
}
[Test]
public async Task GetTileAirEntityCoordinatesNotNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var air = default(EntityCoordinates).GetTileAir();
Assert.NotNull(air);
});
});
await server.WaitIdleAsync();
}
[Test]
public async Task TryGetTileAtmosphereEntityCoordinatesNotNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var hasAtmosphere = default(EntityCoordinates).TryGetTileAtmosphere(out var atmosphere);
Assert.True(hasAtmosphere);
Assert.NotNull(atmosphere);
});
});
await server.WaitIdleAsync();
}
[Test]
public async Task TryGetTileTileAirEntityCoordinatesNotNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var hasAir = default(EntityCoordinates).TryGetTileAir(out var air);
Assert.True(hasAir);
Assert.NotNull(air);
});
});
await server.WaitIdleAsync();
}
// ReSharper disable once InconsistentNaming
[Test]
public async Task GetTileAtmosphereVector2iNotNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var atmosphere = default(Vector2i).GetTileAtmosphere(default);
Assert.NotNull(atmosphere);
});
});
await server.WaitIdleAsync();
}
// ReSharper disable once InconsistentNaming
[Test]
public async Task GetTileAirVector2iNotNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var air = default(Vector2i).GetTileAir(default);
Assert.NotNull(air);
});
});
await server.WaitIdleAsync();
}
// ReSharper disable once InconsistentNaming
[Test]
public async Task TryGetTileAtmosphereVector2iNotNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var hasAtmosphere = default(Vector2i).TryGetTileAtmosphere(default, out var atmosphere);
Assert.True(hasAtmosphere);
Assert.NotNull(atmosphere);
});
});
await server.WaitIdleAsync();
}
// ReSharper disable once InconsistentNaming
[Test]
public async Task TryGetTileAirVector2iNotNullTest()
{
var server = StartServerDummyTicker();
server.Assert(() =>
{
Assert.DoesNotThrow(() =>
{
var hasAir = default(Vector2i).TryGetTileAir(default, out var air);
Assert.True(hasAir);
Assert.NotNull(air);
});
});
await server.WaitIdleAsync();
}
}
}

View File

@@ -8,6 +8,7 @@ using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests.Body namespace Content.IntegrationTests.Tests.Body
{ {
@@ -40,11 +41,10 @@ namespace Content.IntegrationTests.Tests.Body
{ {
var mapManager = IoCManager.Resolve<IMapManager>(); var mapManager = IoCManager.Resolve<IMapManager>();
var mapId = new MapId(0); var mapId = mapManager.CreateMap();
mapManager.CreateNewMapEntity(mapId);
var entityManager = IoCManager.Resolve<IEntityManager>(); var entityManager = IoCManager.Resolve<IEntityManager>();
var human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy", MapCoordinates.Nullspace); var human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy", new MapCoordinates(Vector2.Zero, mapId));
Assert.That(human.TryGetComponent(out IBody body)); Assert.That(human.TryGetComponent(out IBody body));
Assert.That(human.TryGetComponent(out appearance)); Assert.That(human.TryGetComponent(out appearance));

View File

@@ -57,11 +57,11 @@ namespace Content.IntegrationTests.Tests.Body
{ {
var mapManager = IoCManager.Resolve<IMapManager>(); var mapManager = IoCManager.Resolve<IMapManager>();
mapManager.CreateNewMapEntity(MapId.Nullspace); var mapId = mapManager.CreateMap();
var entityManager = IoCManager.Resolve<IEntityManager>(); var entityManager = IoCManager.Resolve<IEntityManager>();
var human = entityManager.SpawnEntity("HumanBodyAndBloodstreamDummy", MapCoordinates.Nullspace); var human = entityManager.SpawnEntity("HumanBodyAndBloodstreamDummy", new MapCoordinates(Vector2.Zero, mapId));
Assert.That(human.TryGetComponent(out IBody body)); Assert.That(human.TryGetComponent(out IBody body));
Assert.That(body.TryGetMechanismBehaviors(out List<LungBehavior> lungs)); Assert.That(body.TryGetMechanismBehaviors(out List<LungBehavior> lungs));

View File

@@ -9,6 +9,7 @@ using NUnit.Framework;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests.Body namespace Content.IntegrationTests.Tests.Body
{ {
@@ -122,11 +123,10 @@ namespace Content.IntegrationTests.Tests.Body
{ {
var mapManager = IoCManager.Resolve<IMapManager>(); var mapManager = IoCManager.Resolve<IMapManager>();
var mapId = new MapId(0); var mapId = mapManager.CreateMap();
mapManager.CreateNewMapEntity(mapId);
var entityManager = IoCManager.Resolve<IEntityManager>(); var entityManager = IoCManager.Resolve<IEntityManager>();
var human = entityManager.SpawnEntity("HumanBodyDummy", MapCoordinates.Nullspace); var human = entityManager.SpawnEntity("HumanBodyDummy", new MapCoordinates(Vector2.Zero, mapId));
Assert.That(human.TryGetComponent(out IBody? body)); Assert.That(human.TryGetComponent(out IBody? body));
Assert.NotNull(body); Assert.NotNull(body);

View File

@@ -10,6 +10,7 @@ using Robust.Server.Console;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
{ {
@@ -52,15 +53,16 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
server.Assert(() => server.Assert(() =>
{ {
var mapManager = IoCManager.Resolve<IMapManager>(); var mapManager = IoCManager.Resolve<IMapManager>();
mapManager.CreateNewMapEntity(MapId.Nullspace); var mapId = mapManager.CreateMap();
var coordinates = new MapCoordinates(Vector2.Zero, mapId);
var entityManager = IoCManager.Resolve<IEntityManager>(); var entityManager = IoCManager.Resolve<IEntityManager>();
// Spawn the entities // Spawn the entities
human = entityManager.SpawnEntity("HumanDummy", MapCoordinates.Nullspace); human = entityManager.SpawnEntity("HumanDummy", coordinates);
otherHuman = entityManager.SpawnEntity("HumanDummy", MapCoordinates.Nullspace); otherHuman = entityManager.SpawnEntity("HumanDummy", coordinates);
cuffs = entityManager.SpawnEntity("HandcuffsDummy", MapCoordinates.Nullspace); cuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates);
secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", MapCoordinates.Nullspace); secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates);
human.Transform.WorldPosition = otherHuman.Transform.WorldPosition; human.Transform.WorldPosition = otherHuman.Transform.WorldPosition;

View File

@@ -6,6 +6,7 @@ using NUnit.Framework;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests.Interaction namespace Content.IntegrationTests.Tests.Interaction
{ {
@@ -44,8 +45,8 @@ namespace Content.IntegrationTests.Tests.Interaction
server.Assert(() => server.Assert(() =>
{ {
mapManager.CreateNewMapEntity(MapId.Nullspace); var mapId = mapManager.CreateMap();
var coordinates = MapCoordinates.Nullspace; var coordinates = new MapCoordinates(Vector2.Zero, mapId);
origin = entityManager.SpawnEntity(HumanId, coordinates); origin = entityManager.SpawnEntity(HumanId, coordinates);
other = entityManager.SpawnEntity(HumanId, coordinates); other = entityManager.SpawnEntity(HumanId, coordinates);

View File

@@ -3,26 +3,20 @@ using System.Diagnostics.CodeAnalysis;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.Server.Atmos namespace Content.Server.Atmos
{ {
public static class AtmosHelpers public static class AtmosHelpers
{ {
public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null) public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates)
{ {
entityManager ??= IoCManager.Resolve<IEntityManager>(); return EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(coordinates).GetTile(coordinates);
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(coordinates.GetGridId(entityManager));
return gridAtmos.GetTile(coordinates);
} }
public static GasMixture? GetTileAir(this EntityCoordinates coordinates, IEntityManager? entityManager = null) public static GasMixture? GetTileAir(this EntityCoordinates coordinates, IEntityManager? entityManager = null)
{ {
return coordinates.GetTileAtmosphere(entityManager)?.Air; return coordinates.GetTileAtmosphere()?.Air;
} }
public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [NotNullWhen(true)] out TileAtmosphere? atmosphere) public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [NotNullWhen(true)] out TileAtmosphere? atmosphere)
@@ -54,36 +48,6 @@ namespace Content.Server.Atmos
return true; return true;
} }
public static TileAtmosphere? GetTileAtmosphere(this Vector2i indices, GridId gridId)
{
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId);
return gridAtmos.GetTile(indices);
}
public static GasMixture? GetTileAir(this Vector2i indices, GridId gridId)
{
return indices.GetTileAtmosphere(gridId)?.Air;
}
public static bool TryGetTileAtmosphere(this Vector2i indices, GridId gridId,
[NotNullWhen(true)] out TileAtmosphere? atmosphere)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(atmosphere = indices.GetTileAtmosphere(gridId), default);
}
public static bool TryGetTileAir(this Vector2i indices, GridId gridId, [NotNullWhen(true)] out GasMixture? air)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(air = indices.GetTileAir(gridId), default);
}
public static bool InvalidateTileAir(this ITransformComponent transform, AtmosphereSystem? atmosSystem = null)
{
return InvalidateTileAir(transform.Coordinates);
}
public static bool InvalidateTileAir(this EntityCoordinates coordinates) public static bool InvalidateTileAir(this EntityCoordinates coordinates)
{ {
if (!coordinates.TryGetTileAtmosphere(out var tileAtmos)) if (!coordinates.TryGetTileAtmosphere(out var tileAtmos))

View File

@@ -157,6 +157,11 @@ namespace Content.Server.Atmos
void RepopulateTiles(); void RepopulateTiles();
/// <summary>
/// Returns a dictionary of adjacent TileAtmospheres.
/// </summary>
Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(EntityCoordinates coordinates, bool includeAirBlocked = false);
/// <summary> /// <summary>
/// Returns a dictionary of adjacent TileAtmospheres. /// Returns a dictionary of adjacent TileAtmospheres.
/// </summary> /// </summary>

View File

@@ -3,6 +3,7 @@ using Content.Server.Atmos;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
using Content.Shared.Interfaces.Chemistry; using Content.Shared.Interfaces.Chemistry;
using Content.Shared.Maps;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
@@ -18,7 +19,7 @@ namespace Content.Server.Chemistry.TileReactions
public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume)
{ {
if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty) return ReagentUnit.Zero; if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty) return ReagentUnit.Zero;
var tileAtmos = tile.GridIndices.GetTileAtmosphere(tile.GridIndex); var tileAtmos = tile.GridPosition().GetTileAtmosphere();
if (tileAtmos == null || !tileAtmos.Hotspot.Valid || tileAtmos.Air == null) return ReagentUnit.Zero; if (tileAtmos == null || !tileAtmos.Hotspot.Valid || tileAtmos.Air == null) return ReagentUnit.Zero;
tileAtmos.Air.Temperature = tileAtmos.Air.Temperature =
MathF.Max(MathF.Min(tileAtmos.Air.Temperature - (_coolingTemperature * 1000f), MathF.Max(MathF.Min(tileAtmos.Air.Temperature - (_coolingTemperature * 1000f),

View File

@@ -2,6 +2,7 @@
using Content.Server.Atmos; using Content.Server.Atmos;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
using Content.Shared.Interfaces.Chemistry; using Content.Shared.Interfaces.Chemistry;
using Content.Shared.Maps;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
@@ -17,7 +18,7 @@ namespace Content.Server.Chemistry.TileReactions
public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume)
{ {
if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty) return ReagentUnit.Zero; if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty) return ReagentUnit.Zero;
var tileAtmos = tile.GridIndices.GetTileAtmosphere(tile.GridIndex); var tileAtmos = tile.GridPosition().GetTileAtmosphere();
if (tileAtmos?.Air == null || !tileAtmos.Hotspot.Valid) return ReagentUnit.Zero; if (tileAtmos?.Air == null || !tileAtmos.Hotspot.Valid) return ReagentUnit.Zero;
tileAtmos.Air.Temperature *= MathF.Max(_temperatureMultiplier * reactVolume.Float(), 1f); tileAtmos.Air.Temperature *= MathF.Max(_temperatureMultiplier * reactVolume.Float(), 1f);
tileAtmos.Air.React(tileAtmos); tileAtmos.Air.React(tileAtmos);

View File

@@ -141,7 +141,9 @@ namespace Content.Server.GameObjects.Components.Atmos
UpdatePosition(_lastPosition.Item1, _lastPosition.Item2); UpdatePosition(_lastPosition.Item1, _lastPosition.Item2);
if (_fixVacuum) if (_fixVacuum)
_atmosphereSystem.GetGridAtmosphere(_lastPosition.Item1).FixVacuum(_lastPosition.Item2); {
_atmosphereSystem.GetGridAtmosphere(_lastPosition.Item1)?.FixVacuum(_lastPosition.Item2);
}
} }
private void OnTransformMove() private void OnTransformMove()
@@ -165,8 +167,8 @@ namespace Content.Server.GameObjects.Components.Atmos
{ {
var gridAtmos = _atmosphereSystem.GetGridAtmosphere(gridId); var gridAtmos = _atmosphereSystem.GetGridAtmosphere(gridId);
gridAtmos.UpdateAdjacentBits(pos); gridAtmos?.UpdateAdjacentBits(pos);
gridAtmos.Invalidate(pos); gridAtmos?.Invalidate(pos);
} }
} }
} }

View File

@@ -76,15 +76,12 @@ namespace Content.Server.GameObjects.Components.Atmos
{ {
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>(); var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
if (!Owner.Transform.Coordinates.TryGetTileAtmosphere(out var tileAtmos)) var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.Coordinates);
return false;
var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.GridID);
var minMoles = float.MaxValue; var minMoles = float.MaxValue;
var maxMoles = 0f; var maxMoles = 0f;
foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(tileAtmos.GridIndices)) foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(Owner.Transform.Coordinates))
{ {
// includeAirBlocked remains false, and therefore Air must be present // includeAirBlocked remains false, and therefore Air must be present
var moles = adjacent.Air!.TotalMoles; var moles = adjacent.Air!.TotalMoles;
@@ -107,7 +104,7 @@ namespace Content.Server.GameObjects.Components.Atmos
if (tileAtmos.Hotspot.Valid) if (tileAtmos.Hotspot.Valid)
return true; return true;
var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.GridID); var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.Coordinates);
foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(tileAtmos.GridIndices)) foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(tileAtmos.GridIndices))
{ {

View File

@@ -125,7 +125,7 @@ namespace Content.Server.GameObjects.Components.Atmos
{ {
// Already get the pressure before Dirty(), because we can't get the EntitySystem in that thread or smth // Already get the pressure before Dirty(), because we can't get the EntitySystem in that thread or smth
var pressure = 0f; var pressure = 0f;
var gam = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(Owner.Transform.GridID); var gam = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(Owner.Transform.Coordinates);
var tile = gam?.GetTile(Owner.Transform.Coordinates)?.Air; var tile = gam?.GetTile(Owner.Transform.Coordinates)?.Air;
if (tile != null) if (tile != null)
{ {
@@ -185,7 +185,7 @@ namespace Content.Server.GameObjects.Components.Atmos
} }
var atmosSystem = EntitySystem.Get<AtmosphereSystem>(); var atmosSystem = EntitySystem.Get<AtmosphereSystem>();
var gam = atmosSystem.GetGridAtmosphere(pos.GetGridId(Owner.EntityManager)); var gam = atmosSystem.GetGridAtmosphere(pos);
var tile = gam.GetTile(pos)?.Air; var tile = gam.GetTile(pos)?.Air;
if (tile == null) if (tile == null)
{ {

View File

@@ -514,6 +514,11 @@ namespace Content.Server.GameObjects.Components.Atmos
return _mapGridComponent.Grid.GetTileRef(indices).IsSpace(); return _mapGridComponent.Grid.GetTileRef(indices).IsSpace();
} }
public Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(EntityCoordinates coordinates, bool includeAirBlocked = false)
{
return GetAdjacentTiles(coordinates.ToVector2i(_serverEntityManager, _mapManager), includeAirBlocked);
}
public Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(Vector2i indices, bool includeAirBlocked = false) public Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(Vector2i indices, bool includeAirBlocked = false)
{ {
var sides = new Dictionary<AtmosDirection, TileAtmosphere>(); var sides = new Dictionary<AtmosDirection, TileAtmosphere>();

View File

@@ -38,7 +38,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
private void JoinGridAtmos() private void JoinGridAtmos()
{ {
var gridAtmos = EntitySystem.Get<AtmosphereSystem>() var gridAtmos = EntitySystem.Get<AtmosphereSystem>()
.GetGridAtmosphere(Owner.Transform.GridID); .GetGridAtmosphere(Owner.Transform.Coordinates);
JoinedGridAtmos = gridAtmos; JoinedGridAtmos = gridAtmos;
JoinedGridAtmos.AddPipeNetDevice(this); JoinedGridAtmos.AddPipeNetDevice(this);
} }

View File

@@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers
if (!SiphonEnabled) if (!SiphonEnabled)
return; return;
var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(Owner.EntityManager); var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere();
if (_scrubberOutlet == null || tileAtmos == null || tileAtmos.Air == null) if (_scrubberOutlet == null || tileAtmos == null || tileAtmos.Air == null)
return; return;

View File

@@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Vents
if (!VentEnabled) if (!VentEnabled)
return; return;
var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(Owner.EntityManager); var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere();
if (_ventInlet == null || tileAtmos == null || tileAtmos.Air == null) if (_ventInlet == null || tileAtmos == null || tileAtmos.Air == null)
return; return;

View File

@@ -2,11 +2,14 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Server.Atmos; using Content.Server.Atmos;
using Robust.Shared.GameObjects;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths; using Robust.Shared.Maths;
namespace Content.Server.GameObjects.Components.Atmos namespace Content.Server.GameObjects.Components.Atmos
{ {
[RegisterComponent]
[ComponentReference(typeof(IGridAtmosphereComponent))]
public class SpaceGridAtmosphereComponent : UnsimulatedGridAtmosphereComponent public class SpaceGridAtmosphereComponent : UnsimulatedGridAtmosphereComponent
{ {
public override string Name => "SpaceGridAtmosphere"; public override string Name => "SpaceGridAtmosphere";

View File

@@ -283,7 +283,7 @@ namespace Content.Server.GameObjects.Components.Disposal
var atmosSystem = EntitySystem.Get<AtmosphereSystem>(); var atmosSystem = EntitySystem.Get<AtmosphereSystem>();
atmosSystem atmosSystem
.GetGridAtmosphere(Owner.Transform.GridID)? .GetGridAtmosphere(Owner.Transform.Coordinates)?
.Invalidate(tileAtmos.GridIndices); .Invalidate(tileAtmos.GridIndices);
} }

View File

@@ -21,7 +21,7 @@ namespace Content.Server.GameObjects.EntitySystems
// creadth: everything exposable by atmos should be updated as well // creadth: everything exposable by atmos should be updated as well
foreach (var atmosExposedComponent in EntityManager.ComponentManager.EntityQuery<AtmosExposedComponent>(true)) foreach (var atmosExposedComponent in EntityManager.ComponentManager.EntityQuery<AtmosExposedComponent>(true))
{ {
var tile = atmosExposedComponent.Owner.Transform.Coordinates.GetTileAtmosphere(EntityManager); var tile = atmosExposedComponent.Owner.Transform.Coordinates.GetTileAtmosphere();
if (tile == null) continue; if (tile == null) continue;
atmosExposedComponent.Update(tile, _lastUpdate); atmosExposedComponent.Update(tile, _lastUpdate);
} }

View File

@@ -5,6 +5,7 @@ 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.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Shared; using Content.Shared;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.GameObjects.EntitySystems.Atmos; using Content.Shared.GameObjects.EntitySystems.Atmos;
@@ -31,7 +32,6 @@ namespace Content.Server.GameObjects.EntitySystems
private GasReactionPrototype[] _gasReactions = Array.Empty<GasReactionPrototype>(); private GasReactionPrototype[] _gasReactions = Array.Empty<GasReactionPrototype>();
private SpaceGridAtmosphereComponent _spaceAtmos = default!;
private GridTileLookupSystem? _gridTileLookup = null; private GridTileLookupSystem? _gridTileLookup = null;
/// <summary> /// <summary>
@@ -51,10 +51,7 @@ namespace Content.Server.GameObjects.EntitySystems
_gasReactions = _protoMan.EnumeratePrototypes<GasReactionPrototype>().ToArray(); _gasReactions = _protoMan.EnumeratePrototypes<GasReactionPrototype>().ToArray();
Array.Sort(_gasReactions, (a, b) => b.Priority.CompareTo(a.Priority)); Array.Sort(_gasReactions, (a, b) => b.Priority.CompareTo(a.Priority));
_spaceAtmos = new SpaceGridAtmosphereComponent(); _mapManager.MapCreated += OnMapCreated;
_spaceAtmos.Initialize();
IoCManager.InjectDependencies(_spaceAtmos);
_mapManager.TileChanged += OnTileChanged; _mapManager.TileChanged += OnTileChanged;
Array.Resize(ref _gasSpecificHeats, MathHelper.NextMultipleOf(Atmospherics.TotalNumberOfGases, 4)); Array.Resize(ref _gasSpecificHeats, MathHelper.NextMultipleOf(Atmospherics.TotalNumberOfGases, 4));
@@ -116,6 +113,8 @@ namespace Content.Server.GameObjects.EntitySystems
{ {
base.Shutdown(); base.Shutdown();
_mapManager.MapCreated -= OnMapCreated;
EntityManager.EventBus.UnsubscribeEvent<RotateEvent>(EventSource.Local, this); EntityManager.EventBus.UnsubscribeEvent<RotateEvent>(EventSource.Local, this);
} }
@@ -127,18 +126,39 @@ namespace Content.Server.GameObjects.EntitySystems
} }
} }
public IGridAtmosphereComponent GetGridAtmosphere(GridId gridId) public IGridAtmosphereComponent? GetGridAtmosphere(GridId gridId)
{ {
if (!gridId.IsValid()) if (!gridId.IsValid())
return null;
if (!_mapManager.TryGetGrid(gridId, out var grid))
return null;
return ComponentManager.TryGetComponent(grid.GridEntityId, out IGridAtmosphereComponent? gridAtmosphere)
? gridAtmosphere : null;
}
public IGridAtmosphereComponent GetGridAtmosphere(EntityCoordinates coordinates)
{
return GetGridAtmosphere(coordinates.ToMap(EntityManager));
}
public IGridAtmosphereComponent GetGridAtmosphere(MapCoordinates coordinates)
{
if (coordinates.MapId == MapId.Nullspace)
{ {
return _spaceAtmos; throw new ArgumentException($"Coordinates cannot be in nullspace!", nameof(coordinates));
} }
var grid = _mapManager.GetGrid(gridId); if (_mapManager.TryFindGridAt(coordinates, out var grid))
{
if (ComponentManager.TryGetComponent(grid.GridEntityId, out IGridAtmosphereComponent? atmos))
{
return atmos;
}
}
if (!EntityManager.TryGetEntity(grid.GridEntityId, out var gridEnt)) return _spaceAtmos; return _mapManager.GetMapEntity(coordinates.MapId).GetComponent<IGridAtmosphereComponent>();
return gridEnt.TryGetComponent(out IGridAtmosphereComponent? atmos) ? atmos : _spaceAtmos;
} }
public override void Update(float frameTime) public override void Update(float frameTime)
@@ -164,7 +184,18 @@ namespace Content.Server.GameObjects.EntitySystems
return; return;
} }
GetGridAtmosphere(eventArgs.NewTile.GridIndex)?.Invalidate(eventArgs.NewTile.GridIndices); GetGridAtmosphere(eventArgs.NewTile.GridPosition(_mapManager))?.Invalidate(eventArgs.NewTile.GridIndices);
}
private void OnMapCreated(object? sender, MapEventArgs e)
{
if (e.Map == MapId.Nullspace)
return;
var map = _mapManager.GetMapEntity(e.Map);
if (!map.HasComponent<IGridAtmosphereComponent>())
map.AddComponent<SpaceGridAtmosphereComponent>();
} }
} }
} }