using Content.Server.Atmos.Components;
using Content.Shared.Atmos.Components;
using Robust.Shared.Map.Components;
namespace Content.Server.Atmos.EntitySystems;
public sealed partial class AtmosphereSystem
{
/*
Helper methods to assist in getting very low overhead profiling of individual stages of the atmospherics simulation.
Ideal for benchmarking and performance testing.
These methods obviously aren't to be used in production code. Don't call them. They know my voice.
*/
///
/// Runs the grid entity through a single processing stage of the atmosphere simulation.
/// Ideal for benchmarking single stages of the simulation.
///
/// The entity to profile Atmospherics with.
/// The state to profile on the entity.
/// The optional mapEntity to provide when benchmarking ProcessAtmosDevices.
/// True if the processing stage completed, false if the processing stage had to pause processing due to time constraints.
public bool RunProcessingStage(
Entity ent,
AtmosphereProcessingState state,
Entity? mapEnt = null)
{
var processingPaused = state switch
{
AtmosphereProcessingState.Revalidate => ProcessRevalidate(ent),
AtmosphereProcessingState.TileEqualize => ProcessTileEqualize(ent),
AtmosphereProcessingState.ActiveTiles => ProcessActiveTiles(ent),
AtmosphereProcessingState.ExcitedGroups => ProcessExcitedGroups(ent),
AtmosphereProcessingState.HighPressureDelta => ProcessHighPressureDelta(ent),
AtmosphereProcessingState.DeltaPressure => ProcessDeltaPressure(ent),
AtmosphereProcessingState.Hotspots => ProcessHotspots(ent),
AtmosphereProcessingState.Superconductivity => ProcessSuperconductivity(ent),
AtmosphereProcessingState.PipeNet => ProcessPipeNets(ent),
AtmosphereProcessingState.AtmosDevices => mapEnt is not null
? ProcessAtmosDevices(ent, mapEnt.Value)
: throw new ArgumentException(
"An Entity must be provided when benchmarking ProcessAtmosDevices."),
_ => throw new ArgumentOutOfRangeException(),
};
ent.Comp1.ProcessingPaused = !processingPaused;
return processingPaused;
}
///
/// Fully runs one entity through the entire Atmos processing loop.
///
/// The entity to simulate.
/// The that belongs to the grid's map.
/// Elapsed time to simulate. Recommended value is .
public void RunProcessingFull(Entity ent,
Entity mapAtmosphere,
float frameTime)
{
while (ProcessAtmosphere(ent, mapAtmosphere, frameTime) != AtmosphereProcessingCompletionState.Finished) { }
}
///
/// Allows or disallows atmosphere simulation on a .
///
/// The atmosphere to pause or unpause processing.
/// The state to set. True means that the atmosphere is allowed to simulate, false otherwise.
public void SetAtmosphereSimulation(Entity ent, bool simulate)
{
ent.Comp.Simulated = simulate;
}
}