Atmospherics Substepping (#40465)

* initial shitcode commit

* command boilerplate

* command flushed out and docs fixes

* missed one important thing in method extraction

* do loc properly

* rest later

* address review

* this worked on my laptop but not on my desktop but okay

* review comments

* address review
This commit is contained in:
ArtisticRoomba
2025-10-31 13:45:50 -07:00
committed by GitHub
parent d893cda971
commit 1f38a34217
6 changed files with 396 additions and 126 deletions

View File

@@ -0,0 +1,69 @@
using Content.Server.Administration;
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Atmos.Commands;
[AdminCommand(AdminFlags.Debug)]
public sealed class PauseAtmosCommand : LocalizedEntityCommands
{
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
public override string Command => "pauseatmos";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var grid = default(EntityUid);
switch (args.Length)
{
case 0:
if (!EntityManager.TryGetComponent<TransformComponent>(shell.Player?.AttachedEntity,
out var playerxform) ||
playerxform.GridUid == null)
{
shell.WriteError(Loc.GetString("cmd-error-no-grid-provided-or-invalid-grid"));
return;
}
grid = playerxform.GridUid.Value;
break;
case 1:
if (!EntityUid.TryParse(args[0], out var parsedGrid) || !EntityManager.EntityExists(parsedGrid))
{
shell.WriteError(Loc.GetString("cmd-error-couldnt-parse-entity"));
return;
}
grid = parsedGrid;
break;
}
if (!EntityManager.TryGetComponent<GridAtmosphereComponent>(grid, out var gridAtmos))
{
shell.WriteError(Loc.GetString("cmd-error-no-gridatmosphere"));
return;
}
var newEnt = new Entity<GridAtmosphereComponent>(grid, gridAtmos);
_atmosphereSystem.SetAtmosphereSimulation(newEnt, !newEnt.Comp.Simulated);
shell.WriteLine(Loc.GetString("cmd-pauseatmos-set-atmos-simulation",
("grid", EntityManager.ToPrettyString(grid)),
("state", newEnt.Comp.Simulated)));
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
return CompletionResult.FromHintOptions(
CompletionHelper.Components<GridAtmosphereComponent>(args[0], EntityManager),
Loc.GetString("cmd-pauseatmos-completion-grid-pause"));
}
return CompletionResult.Empty;
}
}

View File

@@ -0,0 +1,104 @@
using Content.Server.Administration;
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Shared.Administration;
using Content.Shared.Atmos.Components;
using Robust.Shared.Console;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
namespace Content.Server.Atmos.Commands;
[AdminCommand(AdminFlags.Debug)]
public sealed class SubstepAtmosCommand : LocalizedEntityCommands
{
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
public override string Command => "substepatmos";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var grid = default(EntityUid);
switch (args.Length)
{
case 0:
if (!EntityManager.TryGetComponent<TransformComponent>(shell.Player?.AttachedEntity,
out var playerxform) ||
playerxform.GridUid == null)
{
shell.WriteError(Loc.GetString("cmd-error-no-grid-provided-or-invalid-grid"));
return;
}
grid = playerxform.GridUid.Value;
break;
case 1:
if (!EntityUid.TryParse(args[0], out var parsedGrid) || !EntityManager.EntityExists(parsedGrid))
{
shell.WriteError(Loc.GetString("cmd-error-couldnt-parse-entity"));
return;
}
grid = parsedGrid;
break;
}
// i'm straight piratesoftwaremaxxing
if (!EntityManager.TryGetComponent<GridAtmosphereComponent>(grid, out var gridAtmos))
{
shell.WriteError(Loc.GetString("cmd-error-no-gridatmosphere"));
return;
}
if (!EntityManager.TryGetComponent<GasTileOverlayComponent>(grid, out var gasTile))
{
shell.WriteError(Loc.GetString("cmd-error-no-gastileoverlay"));
return;
}
if (!EntityManager.TryGetComponent<MapGridComponent>(grid, out var mapGrid))
{
shell.WriteError(Loc.GetString("cmd-error-no-mapgrid"));
return;
}
var xform = EntityManager.GetComponent<TransformComponent>(grid);
if (xform.MapUid == null || xform.MapID == MapId.Nullspace)
{
shell.WriteError(Loc.GetString("cmd-error-no-valid-map"));
return;
}
var newEnt =
new Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent>(grid,
gridAtmos,
gasTile,
mapGrid,
xform);
if (gridAtmos.Simulated)
{
shell.WriteLine(Loc.GetString("cmd-substepatmos-info-implicitly-paused-simulation",
("grid", EntityManager.ToPrettyString(grid))));
}
_atmosphereSystem.SetAtmosphereSimulation(newEnt, false);
_atmosphereSystem.RunProcessingFull(newEnt, xform.MapUid.Value, _atmosphereSystem.AtmosTickRate);
shell.WriteLine(Loc.GetString("cmd-substepatmos-info-substepped-grid", ("grid", EntityManager.ToPrettyString(grid))));
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
return CompletionResult.FromHintOptions(
CompletionHelper.Components<GridAtmosphereComponent>(args[0], EntityManager),
Loc.GetString("cmd-substepatmos-completion-grid-substep"));
}
return CompletionResult.Empty;
}
}

View File

@@ -46,4 +46,27 @@ public sealed partial class AtmosphereSystem
return processingPaused;
}
/// <summary>
/// Fully runs one <see cref="GridAtmosphereComponent"/> entity through the entire Atmos processing loop.
/// </summary>
/// <param name="ent">The entity to simulate.</param>
/// <param name="mapAtmosphere">The <see cref="MapAtmosphereComponent"/> that belongs to the grid's map.</param>
/// <param name="frameTime">Elapsed time to simulate. Recommended value is <see cref="AtmosTickRate"/>.</param>
public void RunProcessingFull(Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent,
Entity<MapAtmosphereComponent?> mapAtmosphere,
float frameTime)
{
while (ProcessAtmosphere(ent, mapAtmosphere, frameTime) != AtmosphereProcessingCompletionState.Finished) { }
}
/// <summary>
/// Allows or disallows atmosphere simulation on a <see cref="GridAtmosphereComponent"/>.
/// </summary>
/// <param name="ent">The atmosphere to pause or unpause processing.</param>
/// <param name="simulate">The state to set. True means that the atmosphere is allowed to simulate, false otherwise.</param>
public void SetAtmosphereSimulation(Entity<GridAtmosphereComponent> ent, bool simulate)
{
ent.Comp.Simulated = simulate;
}
}

View File

@@ -649,23 +649,56 @@ namespace Content.Server.Atmos.EntitySystems
if (atmosphere.LifeStage >= ComponentLifeStage.Stopping || Paused(owner) || !atmosphere.Simulated)
continue;
var map = new Entity<MapAtmosphereComponent?>(xform.MapUid.Value, _mapAtmosQuery.CompOrNull(xform.MapUid.Value));
var completionState = ProcessAtmosphere(ent, map, frameTime);
switch (completionState)
{
case AtmosphereProcessingCompletionState.Return:
return;
case AtmosphereProcessingCompletionState.Continue:
continue;
case AtmosphereProcessingCompletionState.Finished:
break;
}
}
// We finished processing all atmospheres successfully, therefore we won't be paused next tick.
_simulationPaused = false;
}
/// <summary>
/// Processes a <see cref="GridAtmosphereComponent"/> through its processing stages.
/// </summary>
/// <param name="ent">The entity to process.</param>
/// <param name="mapAtmosphere">The <see cref="MapAtmosphereComponent"/> belonging to the
/// <see cref="GridAtmosphereComponent"/>'s map.</param>
/// <param name="frameTime">The elapsed time since the last frame.</param>
/// <returns>An <see cref="AtmosphereProcessingCompletionState"/> that represents the completion state.</returns>
private AtmosphereProcessingCompletionState ProcessAtmosphere(Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent,
Entity<MapAtmosphereComponent?> mapAtmosphere,
float frameTime)
{
// They call me the deconstructor the way i be deconstructing it
// and by it, i mean... my entity
var (owner, atmosphere, visuals, grid, xform) = ent;
atmosphere.Timer += frameTime;
if (atmosphere.Timer < AtmosTime)
continue;
return AtmosphereProcessingCompletionState.Continue;
// We subtract it so it takes lost time into account.
atmosphere.Timer -= AtmosTime;
var map = new Entity<MapAtmosphereComponent?>(xform.MapUid.Value, _mapAtmosQuery.CompOrNull(xform.MapUid.Value));
switch (atmosphere.State)
{
case AtmosphereProcessingState.Revalidate:
if (!ProcessRevalidate(ent))
{
atmosphere.ProcessingPaused = true;
return;
return AtmosphereProcessingCompletionState.Return;
}
atmosphere.ProcessingPaused = false;
@@ -676,65 +709,65 @@ namespace Content.Server.Atmos.EntitySystems
atmosphere.State = MonstermosEqualization
? AtmosphereProcessingState.TileEqualize
: AtmosphereProcessingState.ActiveTiles;
continue;
return AtmosphereProcessingCompletionState.Continue;
case AtmosphereProcessingState.TileEqualize:
if (!ProcessTileEqualize(ent))
{
atmosphere.ProcessingPaused = true;
return;
return AtmosphereProcessingCompletionState.Return;
}
atmosphere.ProcessingPaused = false;
atmosphere.State = AtmosphereProcessingState.ActiveTiles;
continue;
return AtmosphereProcessingCompletionState.Continue;
case AtmosphereProcessingState.ActiveTiles:
if (!ProcessActiveTiles(ent))
{
atmosphere.ProcessingPaused = true;
return;
return AtmosphereProcessingCompletionState.Return;
}
atmosphere.ProcessingPaused = false;
// Next state depends on whether excited groups are enabled or not.
atmosphere.State = ExcitedGroups ? AtmosphereProcessingState.ExcitedGroups : AtmosphereProcessingState.HighPressureDelta;
continue;
return AtmosphereProcessingCompletionState.Continue;
case AtmosphereProcessingState.ExcitedGroups:
if (!ProcessExcitedGroups(ent))
{
atmosphere.ProcessingPaused = true;
return;
return AtmosphereProcessingCompletionState.Return;
}
atmosphere.ProcessingPaused = false;
atmosphere.State = AtmosphereProcessingState.HighPressureDelta;
continue;
return AtmosphereProcessingCompletionState.Continue;
case AtmosphereProcessingState.HighPressureDelta:
if (!ProcessHighPressureDelta((ent, ent)))
{
atmosphere.ProcessingPaused = true;
return;
return AtmosphereProcessingCompletionState.Return;
}
atmosphere.ProcessingPaused = false;
atmosphere.State = DeltaPressureDamage
? AtmosphereProcessingState.DeltaPressure
: AtmosphereProcessingState.Hotspots;
continue;
return AtmosphereProcessingCompletionState.Continue;
case AtmosphereProcessingState.DeltaPressure:
if (!ProcessDeltaPressure(ent))
{
atmosphere.ProcessingPaused = true;
return;
return AtmosphereProcessingCompletionState.Return;
}
atmosphere.ProcessingPaused = false;
atmosphere.State = AtmosphereProcessingState.Hotspots;
continue;
return AtmosphereProcessingCompletionState.Continue;
case AtmosphereProcessingState.Hotspots:
if (!ProcessHotspots(ent))
{
atmosphere.ProcessingPaused = true;
return;
return AtmosphereProcessingCompletionState.Return;
}
atmosphere.ProcessingPaused = false;
@@ -744,32 +777,32 @@ namespace Content.Server.Atmos.EntitySystems
atmosphere.State = Superconduction
? AtmosphereProcessingState.Superconductivity
: AtmosphereProcessingState.PipeNet;
continue;
return AtmosphereProcessingCompletionState.Continue;
case AtmosphereProcessingState.Superconductivity:
if (!ProcessSuperconductivity(atmosphere))
{
atmosphere.ProcessingPaused = true;
return;
return AtmosphereProcessingCompletionState.Return;
}
atmosphere.ProcessingPaused = false;
atmosphere.State = AtmosphereProcessingState.PipeNet;
continue;
return AtmosphereProcessingCompletionState.Continue;
case AtmosphereProcessingState.PipeNet:
if (!ProcessPipeNets(atmosphere))
{
atmosphere.ProcessingPaused = true;
return;
return AtmosphereProcessingCompletionState.Return;
}
atmosphere.ProcessingPaused = false;
atmosphere.State = AtmosphereProcessingState.AtmosDevices;
continue;
return AtmosphereProcessingCompletionState.Continue;
case AtmosphereProcessingState.AtmosDevices:
if (!ProcessAtmosDevices(ent, map))
if (!ProcessAtmosDevices(ent, mapAtmosphere))
{
atmosphere.ProcessingPaused = true;
return;
return AtmosphereProcessingCompletionState.Return;
}
atmosphere.ProcessingPaused = false;
@@ -779,13 +812,33 @@ namespace Content.Server.Atmos.EntitySystems
break;
}
// And increase the update counter.
atmosphere.UpdateCounter++;
return AtmosphereProcessingCompletionState.Finished;
}
}
// We finished processing all atmospheres successfully, therefore we won't be paused next tick.
_simulationPaused = false;
}
/// <summary>
/// An enum representing the completion state of a <see cref="GridAtmosphereComponent"/>'s processing steps.
/// The processing of a <see cref="GridAtmosphereComponent"/> spans over multiple stages and sticks,
/// with the method handling the processing having multiple return types.
/// </summary>
public enum AtmosphereProcessingCompletionState : byte
{
/// <summary>
/// Method is returning, ex. due to delegating processing to the next tick.
/// </summary>
Return,
/// <summary>
/// Method is continuing, ex. due to finishing a single processing stage.
/// </summary>
Continue,
/// <summary>
/// Method is finished with the GridAtmosphere.
/// </summary>
Finished,
}
public enum AtmosphereProcessingState : byte

View File

@@ -0,0 +1,6 @@
cmd-pauseatmos-desc = Pauses or unpauses the atmosphere simulation for the provided grid entity.
cmd-pauseatmos-help = Usage: {$command} <EntityUid>
cmd-pauseatmos-set-atmos-simulation = Set atmospherics simulation on {$grid} to state {$state}.
cmd-pauseatmos-completion-grid-pause = EntityUid of the grid you want to pause/unpause. Automatically uses the grid you're standing on if empty.

View File

@@ -0,0 +1,15 @@
cmd-substepatmos-desc = Substeps the atmosphere simulation by a single atmostick for the provided grid entity. Implicitly pauses atmospherics simulation.
cmd-substepatmos-help = Usage: {$command} <EntityUid>
cmd-error-no-grid-provided-or-invalid-grid = You must either provide a grid entity or be standing on a grid to substep.
cmd-error-couldnt-parse-entity = Entity provided could not be parsed or does not exist. Try standing on a grid you want to substep.
cmd-error-no-gridatmosphere = Entity provided doesn't have a GridAtmosphereComponent.
cmd-error-no-gastileoverlay = Entity provided doesn't have a GasTileOverlayComponent.
cmd-error-no-mapgrid = Entity provided doesn't have a MapGridComponent.
cmd-error-no-xform = Entity provided doesn't have a TransformComponent?
cmd-error-no-valid-map = The grid provided is not on a valid map?
cmd-substepatmos-info-implicitly-paused-simulation = Implicitly paused atmospherics simulation on {$grid}.
cmd-substepatmos-info-substepped-grid = Substepped atmospherics simulation by one atmostick on {$grid}.
cmd-substepatmos-completion-grid-substep = EntityUid of the grid you want to substep. Automatically uses the grid you're standing on if empty.