AtmosDevices can optionally process in space. (#4405)
Refactors some misc atmos things, too.
This commit is contained in:
committed by
GitHub
parent
e42acf2401
commit
009087863f
@@ -117,6 +117,10 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
/// <returns>All tile mixtures in a grid.</returns>
|
||||
public IEnumerable<GasMixture> GetAllTileMixtures(GridId grid, bool invalidate = false)
|
||||
{
|
||||
// Return an array with a single space gas mixture for invalid grids.
|
||||
if (!grid.IsValid())
|
||||
return new []{ GasMixture.SpaceGas };
|
||||
|
||||
if (!_mapManager.TryGetGrid(grid, out var mapGrid))
|
||||
return Enumerable.Empty<GasMixture>();
|
||||
|
||||
@@ -678,6 +682,10 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
/// <returns>The tile mixture, or null</returns>
|
||||
public GasMixture? GetTileMixture(GridId grid, Vector2i tile, bool invalidate = false)
|
||||
{
|
||||
// Always return space gas mixtures for invalid grids (grid 0)
|
||||
if (!grid.IsValid())
|
||||
return GasMixture.SpaceGas;
|
||||
|
||||
if (!_mapManager.TryGetGrid(grid, out var mapGrid))
|
||||
return null;
|
||||
|
||||
@@ -686,7 +694,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
return GetTileMixture(gridAtmosphere, tile, invalidate);
|
||||
}
|
||||
|
||||
if (ComponentManager.TryGetComponent(mapGrid.GridEntityId, out SpaceGridAtmosphereComponent? spaceAtmosphere))
|
||||
if (ComponentManager.TryGetComponent(mapGrid.GridEntityId, out SpaceAtmosphereComponent? _))
|
||||
{
|
||||
// Always return a new space gas mixture in this case.
|
||||
return GasMixture.SpaceGas;
|
||||
@@ -967,6 +975,10 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
/// <returns>All adjacent tile gas mixtures to the tile in question</returns>
|
||||
public IEnumerable<GasMixture> GetAdjacentTileMixtures(GridId grid, Vector2i tile, bool includeBlocked = false, bool invalidate = false)
|
||||
{
|
||||
// For invalid grids, return an array with a single space gas mixture in it.
|
||||
if (!grid.IsValid())
|
||||
return new []{ GasMixture.SpaceGas };
|
||||
|
||||
if (!_mapManager.TryGetGrid(grid, out var mapGrid))
|
||||
return Enumerable.Empty<GasMixture>();
|
||||
|
||||
@@ -1374,7 +1386,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
return false;
|
||||
|
||||
if (ComponentManager.TryGetComponent(mapGrid.GridEntityId, out GridAtmosphereComponent? gridAtmosphere)
|
||||
&& gridAtmosphere.AtmosDevices.Contains(atmosDevice))
|
||||
&& gridAtmosphere.AtmosDevices.Contains(atmosDevice))
|
||||
{
|
||||
atmosDevice.JoinedGrid = null;
|
||||
gridAtmosphere.AtmosDevices.Remove(atmosDevice);
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
private readonly AtmosDeviceUpdateEvent _updateEvent = new();
|
||||
private readonly Stopwatch _simulationStopwatch = new();
|
||||
|
||||
/// <summary>
|
||||
@@ -204,11 +205,10 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
atmosphere.CurrentRunAtmosDevices = new Queue<AtmosDeviceComponent>(atmosphere.AtmosDevices);
|
||||
|
||||
var time = _gameTiming.CurTime;
|
||||
var updateEvent = new AtmosDeviceUpdateEvent();
|
||||
var number = 0;
|
||||
while (atmosphere.CurrentRunAtmosDevices.TryDequeue(out var device))
|
||||
{
|
||||
EntityManager.EventBus.RaiseLocalEvent(device.Owner.Uid, updateEvent, false);
|
||||
RaiseLocalEvent(device.Owner.Uid, _updateEvent, false);
|
||||
device.LastProcess = time;
|
||||
|
||||
if (number++ < LagCheckIterations) continue;
|
||||
@@ -241,7 +241,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
var atmosphere = _currentRunAtmosphere[_currentRunAtmosphereIndex];
|
||||
|
||||
if (atmosphere.Paused || atmosphere.LifeStage >= ComponentLifeStage.Stopping)
|
||||
if (atmosphere.Paused || !atmosphere.Simulated || atmosphere.LifeStage >= ComponentLifeStage.Stopping)
|
||||
continue;
|
||||
|
||||
atmosphere.Timer += frameTime;
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
#region Events
|
||||
|
||||
// Map events.
|
||||
_mapManager.MapCreated += OnMapCreated;
|
||||
_mapManager.TileChanged += OnTileChanged;
|
||||
|
||||
#endregion
|
||||
@@ -39,7 +38,6 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
_mapManager.MapCreated -= OnMapCreated;
|
||||
_mapManager.TileChanged -= OnTileChanged;
|
||||
}
|
||||
|
||||
@@ -57,17 +55,6 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
InvalidateTile(eventArgs.NewTile.GridIndex, 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>();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
Reference in New Issue
Block a user