Optimize atmos devices' appearance updating.

This commit is contained in:
Vera Aguilera Puerto
2021-07-30 14:00:14 +02:00
parent f4769c00d7
commit e256cb7bb0
5 changed files with 44 additions and 48 deletions

View File

@@ -37,23 +37,23 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
return; return;
} }
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off); if (!vent.Enabled
|| !ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
if (!vent.Enabled) || !nodeContainer.TryGetNode(vent.InletName, out PipeNode? inlet)
return;
if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
return;
if (!nodeContainer.TryGetNode(vent.InletName, out PipeNode? inlet)
|| !nodeContainer.TryGetNode(vent.OutletName, out PipeNode? outlet)) || !nodeContainer.TryGetNode(vent.OutletName, out PipeNode? outlet))
{
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off);
return; return;
}
var environment = _atmosphereSystem.GetTileMixture(vent.Owner.Transform.Coordinates, true); var environment = _atmosphereSystem.GetTileMixture(vent.Owner.Transform.Coordinates, true);
// We're in an air-blocked tile... Do nothing. // We're in an air-blocked tile... Do nothing.
if (environment == null) if (environment == null)
{
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off);
return; return;
}
if (vent.PumpDirection == VentPumpDirection.Releasing) if (vent.PumpDirection == VentPumpDirection.Releasing)
{ {

View File

@@ -25,22 +25,23 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
private void OnPumpUpdated(EntityUid uid, GasPressurePumpComponent pump, AtmosDeviceUpdateEvent args) private void OnPumpUpdated(EntityUid uid, GasPressurePumpComponent pump, AtmosDeviceUpdateEvent args)
{ {
var appearance = pump.Owner.GetComponentOrNull<AppearanceComponent>(); var appearance = pump.Owner.GetComponentOrNull<AppearanceComponent>();
appearance?.SetData(PressurePumpVisuals.Enabled, false);
if (!pump.Enabled) if (!pump.Enabled
return; || !ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|| !nodeContainer.TryGetNode(pump.InletName, out PipeNode? inlet)
if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
return;
if (!nodeContainer.TryGetNode(pump.InletName, out PipeNode? inlet)
|| !nodeContainer.TryGetNode(pump.OutletName, out PipeNode? outlet)) || !nodeContainer.TryGetNode(pump.OutletName, out PipeNode? outlet))
{
appearance?.SetData(PressurePumpVisuals.Enabled, false);
return; return;
}
var outputStartingPressure = outlet.Air.Pressure; var outputStartingPressure = outlet.Air.Pressure;
if (MathHelper.CloseTo(pump.TargetPressure, outputStartingPressure)) if (MathHelper.CloseTo(pump.TargetPressure, outputStartingPressure))
{
appearance?.SetData(PressurePumpVisuals.Enabled, false);
return; // No need to pump gas if target has been reached. return; // No need to pump gas if target has been reached.
}
if (inlet.Air.TotalMoles > 0 && inlet.Air.Temperature > 0) if (inlet.Air.TotalMoles > 0 && inlet.Air.Temperature > 0)
{ {

View File

@@ -27,16 +27,14 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, AtmosDeviceUpdateEvent args) private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, AtmosDeviceUpdateEvent args)
{ {
var appearance = thermoMachine.Owner.GetComponentOrNull<AppearanceComponent>(); var appearance = thermoMachine.Owner.GetComponentOrNull<AppearanceComponent>();
appearance?.SetData(ThermoMachineVisuals.Enabled, false);
if (!thermoMachine.Enabled) if (!thermoMachine.Enabled
return; || !ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|| !nodeContainer.TryGetNode(thermoMachine.InletName, out PipeNode? inlet))
if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)) {
return; appearance?.SetData(ThermoMachineVisuals.Enabled, false);
if (!nodeContainer.TryGetNode(thermoMachine.InletName, out PipeNode? inlet))
return; return;
}
var airHeatCapacity = _atmosphereSystem.GetHeatCapacity(inlet.Air); var airHeatCapacity = _atmosphereSystem.GetHeatCapacity(inlet.Air);
var combinedHeatCapacity = airHeatCapacity + thermoMachine.HeatCapacity; var combinedHeatCapacity = airHeatCapacity + thermoMachine.HeatCapacity;

View File

@@ -36,22 +36,22 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
return; return;
} }
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off); if (!vent.Enabled
|| !ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
if (!vent.Enabled) || !nodeContainer.TryGetNode(vent.InletName, out PipeNode? pipe))
return; {
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off);
if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
return;
if (!nodeContainer.TryGetNode(vent.InletName, out PipeNode? pipe))
return; return;
}
var environment = _atmosphereSystem.GetTileMixture(vent.Owner.Transform.Coordinates, true); var environment = _atmosphereSystem.GetTileMixture(vent.Owner.Transform.Coordinates, true);
// We're in an air-blocked tile... Do nothing. // We're in an air-blocked tile... Do nothing.
if (environment == null) if (environment == null)
{
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off);
return; return;
}
if (vent.PumpDirection == VentPumpDirection.Releasing) if (vent.PumpDirection == VentPumpDirection.Releasing)
{ {

View File

@@ -37,16 +37,13 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
return; return;
} }
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Off); if (!scrubber.Enabled
|| !ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
if (!scrubber.Enabled) || !nodeContainer.TryGetNode(scrubber.OutletName, out PipeNode? outlet))
return; {
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Off);
if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
return;
if (!nodeContainer.TryGetNode(scrubber.OutletName, out PipeNode? outlet))
return; return;
}
var environment = _atmosphereSystem.GetTileMixture(scrubber.Owner.Transform.Coordinates, true); var environment = _atmosphereSystem.GetTileMixture(scrubber.Owner.Transform.Coordinates, true);
@@ -72,12 +69,12 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void Scrub(AtmosphereSystem atmosphereSystem, GasVentScrubberComponent scrubber, AppearanceComponent? appearance, GasMixture? tile, PipeNode outlet) private void Scrub(AtmosphereSystem atmosphereSystem, GasVentScrubberComponent scrubber, AppearanceComponent? appearance, GasMixture? tile, PipeNode outlet)
{ {
// Cannot scrub if tile is null or air-blocked. // Cannot scrub if tile is null or air-blocked.
if (tile == null) if (tile == null
return; || outlet.Air.Pressure >= 50 * Atmospherics.OneAtmosphere) // Cannot scrub if pressure too high.
{
// Cannot scrub if pressure too high. appearance?.SetData(ScrubberVisuals.State, ScrubberState.Off);
if (outlet.Air.Pressure >= 50 * Atmospherics.OneAtmosphere)
return; return;
}
if (scrubber.PumpDirection == ScrubberPumpDirection.Scrubbing) if (scrubber.PumpDirection == ScrubberPumpDirection.Scrubbing)
{ {