Optimize vent/scrubber (#7473)
This commit is contained in:
@@ -926,7 +926,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
public IEnumerable<GasMixture> GetAdjacentTileMixtures(EntityCoordinates coordinates, bool includeBlocked = false, bool invalidate = false)
|
public IEnumerable<GasMixture> GetAdjacentTileMixtures(EntityCoordinates coordinates, bool includeBlocked = false, bool invalidate = false)
|
||||||
{
|
{
|
||||||
if (TryGetGridAndTile(coordinates, out var tuple))
|
if (TryGetGridAndTile(coordinates, out var tuple))
|
||||||
return GetAdjacentTileMixtures(tuple.Value.Grid, tuple.Value.Tile);
|
return GetAdjacentTileMixtures(tuple.Value.Grid, tuple.Value.Tile, includeBlocked, invalidate);
|
||||||
|
|
||||||
return Enumerable.Empty<GasMixture>();
|
return Enumerable.Empty<GasMixture>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
|
|
||||||
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceUpdateEvent>(OnGasVentPumpUpdated);
|
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceUpdateEvent>(OnGasVentPumpUpdated);
|
||||||
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceDisabledEvent>(OnGasVentPumpLeaveAtmosphere);
|
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceDisabledEvent>(OnGasVentPumpLeaveAtmosphere);
|
||||||
|
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceEnabledEvent>(OnGasVentPumpEnterAtmosphere);
|
||||||
SubscribeLocalEvent<GasVentPumpComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
|
SubscribeLocalEvent<GasVentPumpComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
|
||||||
SubscribeLocalEvent<GasVentPumpComponent, PowerChangedEvent>(OnPowerChanged);
|
SubscribeLocalEvent<GasVentPumpComponent, PowerChangedEvent>(OnPowerChanged);
|
||||||
SubscribeLocalEvent<GasVentPumpComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
SubscribeLocalEvent<GasVentPumpComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
||||||
@@ -40,11 +41,9 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
|
|
||||||
private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, AtmosDeviceUpdateEvent args)
|
private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, AtmosDeviceUpdateEvent args)
|
||||||
{
|
{
|
||||||
var appearance = EntityManager.GetComponentOrNull<AppearanceComponent>(vent.Owner); //Bingo waz here
|
//Bingo waz here
|
||||||
|
|
||||||
if (vent.Welded)
|
if (vent.Welded)
|
||||||
{
|
{
|
||||||
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Welded);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,8 +52,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
|| !TryComp(uid, out NodeContainerComponent? nodeContainer)
|
|| !TryComp(uid, out NodeContainerComponent? nodeContainer)
|
||||||
|| !nodeContainer.TryGetNode(vent.InletName, out PipeNode? pipe))
|
|| !nodeContainer.TryGetNode(vent.InletName, out PipeNode? pipe))
|
||||||
{
|
{
|
||||||
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off);
|
|
||||||
_ambientSoundSystem.SetAmbience(vent.Owner, false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,8 +60,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
// 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);
|
|
||||||
_ambientSoundSystem.SetAmbience(vent.Owner, false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,9 +68,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
|
|
||||||
if (vent.PumpDirection == VentPumpDirection.Releasing && pipe.Air.Pressure > 0)
|
if (vent.PumpDirection == VentPumpDirection.Releasing && pipe.Air.Pressure > 0)
|
||||||
{
|
{
|
||||||
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Out);
|
|
||||||
_ambientSoundSystem.SetAmbience(vent.Owner, true);
|
|
||||||
|
|
||||||
if (environment.Pressure > vent.MaxPressure)
|
if (environment.Pressure > vent.MaxPressure)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -105,8 +97,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
}
|
}
|
||||||
else if (vent.PumpDirection == VentPumpDirection.Siphoning && environment.Pressure > 0)
|
else if (vent.PumpDirection == VentPumpDirection.Siphoning && environment.Pressure > 0)
|
||||||
{
|
{
|
||||||
appearance?.SetData(VentPumpVisuals.State, VentPumpState.In);
|
|
||||||
|
|
||||||
if (pipe.Air.Pressure > vent.MaxPressure)
|
if (pipe.Air.Pressure > vent.MaxPressure)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -139,10 +129,12 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
|
|
||||||
private void OnGasVentPumpLeaveAtmosphere(EntityUid uid, GasVentPumpComponent component, AtmosDeviceDisabledEvent args)
|
private void OnGasVentPumpLeaveAtmosphere(EntityUid uid, GasVentPumpComponent component, AtmosDeviceDisabledEvent args)
|
||||||
{
|
{
|
||||||
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
|
UpdateState(uid, component);
|
||||||
{
|
}
|
||||||
appearance.SetData(VentPumpVisuals.State, VentPumpState.Off);
|
|
||||||
}
|
private void OnGasVentPumpEnterAtmosphere(EntityUid uid, GasVentPumpComponent component, AtmosDeviceEnabledEvent args)
|
||||||
|
{
|
||||||
|
UpdateState(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAtmosAlarm(EntityUid uid, GasVentPumpComponent component, AtmosMonitorAlarmEvent args)
|
private void OnAtmosAlarm(EntityUid uid, GasVentPumpComponent component, AtmosMonitorAlarmEvent args)
|
||||||
@@ -155,11 +147,14 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
{
|
{
|
||||||
component.Enabled = true;
|
component.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateState(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPowerChanged(EntityUid uid, GasVentPumpComponent component, PowerChangedEvent args)
|
private void OnPowerChanged(EntityUid uid, GasVentPumpComponent component, PowerChangedEvent args)
|
||||||
{
|
{
|
||||||
component.Enabled = args.Powered;
|
component.Enabled = args.Powered;
|
||||||
|
UpdateState(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPacketRecv(EntityUid uid, GasVentPumpComponent component, DeviceNetworkPacketEvent args)
|
private void OnPacketRecv(EntityUid uid, GasVentPumpComponent component, DeviceNetworkPacketEvent args)
|
||||||
@@ -185,6 +180,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
component.FromAirAlarmData(setData);
|
component.FromAirAlarmData(setData);
|
||||||
|
UpdateState(uid, component);
|
||||||
alarmable.IgnoreAlarms = setData.IgnoreAlarms;
|
alarmable.IgnoreAlarms = setData.IgnoreAlarms;
|
||||||
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSetDataStatus);
|
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSetDataStatus);
|
||||||
payload.Add(AirAlarmSystem.AirAlarmSetDataStatus, true);
|
payload.Add(AirAlarmSystem.AirAlarmSetDataStatus, true);
|
||||||
@@ -195,5 +191,30 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateState(EntityUid uid, GasVentPumpComponent vent, AppearanceComponent? appearance = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref appearance, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_ambientSoundSystem.SetAmbience(uid, true);
|
||||||
|
if (!vent.Enabled)
|
||||||
|
{
|
||||||
|
_ambientSoundSystem.SetAmbience(uid, false);
|
||||||
|
appearance.SetData(VentPumpVisuals.State, VentPumpState.Off);
|
||||||
|
}
|
||||||
|
else if (vent.PumpDirection == VentPumpDirection.Releasing)
|
||||||
|
{
|
||||||
|
appearance.SetData(VentPumpVisuals.State, VentPumpState.Out);
|
||||||
|
}
|
||||||
|
else if (vent.PumpDirection == VentPumpDirection.Siphoning)
|
||||||
|
{
|
||||||
|
appearance.SetData(VentPumpVisuals.State, VentPumpState.In);
|
||||||
|
}
|
||||||
|
else if (vent.Welded)
|
||||||
|
{
|
||||||
|
_ambientSoundSystem.SetAmbience(uid, false);
|
||||||
|
appearance.SetData(VentPumpVisuals.State, VentPumpState.Welded);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceUpdateEvent>(OnVentScrubberUpdated);
|
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceUpdateEvent>(OnVentScrubberUpdated);
|
||||||
|
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceEnabledEvent>(OnVentScrubberEnterAtmosphere);
|
||||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceDisabledEvent>(OnVentScrubberLeaveAtmosphere);
|
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceDisabledEvent>(OnVentScrubberLeaveAtmosphere);
|
||||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
|
SubscribeLocalEvent<GasVentScrubberComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
|
||||||
SubscribeLocalEvent<GasVentScrubberComponent, PowerChangedEvent>(OnPowerChanged);
|
SubscribeLocalEvent<GasVentScrubberComponent, PowerChangedEvent>(OnPowerChanged);
|
||||||
@@ -41,12 +42,8 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
|
|
||||||
private void OnVentScrubberUpdated(EntityUid uid, GasVentScrubberComponent scrubber, AtmosDeviceUpdateEvent args)
|
private void OnVentScrubberUpdated(EntityUid uid, GasVentScrubberComponent scrubber, AtmosDeviceUpdateEvent args)
|
||||||
{
|
{
|
||||||
var appearance = EntityManager.GetComponentOrNull<AppearanceComponent>(scrubber.Owner);
|
|
||||||
|
|
||||||
if (scrubber.Welded)
|
if (scrubber.Welded)
|
||||||
{
|
{
|
||||||
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Welded);
|
|
||||||
_ambientSoundSystem.SetAmbience(scrubber.Owner, false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,40 +56,35 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
|| !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|
|| !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|
||||||
|| !nodeContainer.TryGetNode(scrubber.OutletName, out PipeNode? outlet))
|
|| !nodeContainer.TryGetNode(scrubber.OutletName, out PipeNode? outlet))
|
||||||
{
|
{
|
||||||
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Off);
|
|
||||||
_ambientSoundSystem.SetAmbience(scrubber.Owner, false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ambientSoundSystem.SetAmbience(scrubber.Owner, true);
|
|
||||||
|
|
||||||
var environment = _atmosphereSystem.GetTileMixture(EntityManager.GetComponent<TransformComponent>(scrubber.Owner).Coordinates, true);
|
var xform = Transform(uid);
|
||||||
|
var environment = _atmosphereSystem.GetTileMixture(xform.Coordinates, true);
|
||||||
|
|
||||||
Scrub(timeDelta, scrubber, appearance, environment, outlet);
|
Scrub(timeDelta, scrubber, environment, outlet);
|
||||||
|
|
||||||
if (!scrubber.WideNet) return;
|
if (!scrubber.WideNet) return;
|
||||||
|
|
||||||
// Scrub adjacent tiles too.
|
// Scrub adjacent tiles too.
|
||||||
foreach (var adjacent in _atmosphereSystem.GetAdjacentTileMixtures(EntityManager.GetComponent<TransformComponent>(scrubber.Owner).Coordinates, false, true))
|
foreach (var adjacent in _atmosphereSystem.GetAdjacentTileMixtures(xform.Coordinates, false, true))
|
||||||
{
|
{
|
||||||
Scrub(timeDelta, scrubber, null, adjacent, outlet);
|
Scrub(timeDelta, scrubber, adjacent, outlet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnVentScrubberLeaveAtmosphere(EntityUid uid, GasVentScrubberComponent component, AtmosDeviceDisabledEvent args)
|
private void OnVentScrubberLeaveAtmosphere(EntityUid uid, GasVentScrubberComponent component,
|
||||||
{
|
AtmosDeviceDisabledEvent args) => UpdateState(uid, component);
|
||||||
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
|
|
||||||
{
|
|
||||||
appearance.SetData(ScrubberVisuals.State, ScrubberState.Off);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Scrub(float timeDelta, GasVentScrubberComponent scrubber, AppearanceComponent? appearance, GasMixture? tile, PipeNode outlet)
|
private void OnVentScrubberEnterAtmosphere(EntityUid uid, GasVentScrubberComponent component,
|
||||||
|
AtmosDeviceEnabledEvent args) => UpdateState(uid, component);
|
||||||
|
|
||||||
|
private void Scrub(float timeDelta, GasVentScrubberComponent scrubber, 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
|
||||||
|| outlet.Air.Pressure >= 50 * Atmospherics.OneAtmosphere) // Cannot scrub if pressure too high.
|
|| outlet.Air.Pressure >= 50 * Atmospherics.OneAtmosphere) // Cannot scrub if pressure too high.
|
||||||
{
|
{
|
||||||
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Off);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,8 +98,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
|
|
||||||
if (scrubber.PumpDirection == ScrubberPumpDirection.Scrubbing)
|
if (scrubber.PumpDirection == ScrubberPumpDirection.Scrubbing)
|
||||||
{
|
{
|
||||||
appearance?.SetData(ScrubberVisuals.State, scrubber.WideNet ? ScrubberState.WideScrub : ScrubberState.Scrub);
|
|
||||||
|
|
||||||
_atmosphereSystem.ScrubInto(removed, outlet.Air, scrubber.FilterGases);
|
_atmosphereSystem.ScrubInto(removed, outlet.Air, scrubber.FilterGases);
|
||||||
|
|
||||||
// Remix the gases.
|
// Remix the gases.
|
||||||
@@ -115,8 +105,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
}
|
}
|
||||||
else if (scrubber.PumpDirection == ScrubberPumpDirection.Siphoning)
|
else if (scrubber.PumpDirection == ScrubberPumpDirection.Siphoning)
|
||||||
{
|
{
|
||||||
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Siphon);
|
|
||||||
|
|
||||||
_atmosphereSystem.Merge(outlet.Air, removed);
|
_atmosphereSystem.Merge(outlet.Air, removed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,10 +119,15 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
{
|
{
|
||||||
component.Enabled = true;
|
component.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateState(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPowerChanged(EntityUid uid, GasVentScrubberComponent component, PowerChangedEvent args) =>
|
private void OnPowerChanged(EntityUid uid, GasVentScrubberComponent component, PowerChangedEvent args)
|
||||||
|
{
|
||||||
component.Enabled = args.Powered;
|
component.Enabled = args.Powered;
|
||||||
|
UpdateState(uid, component);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnPacketRecv(EntityUid uid, GasVentScrubberComponent component, DeviceNetworkPacketEvent args)
|
private void OnPacketRecv(EntityUid uid, GasVentScrubberComponent component, DeviceNetworkPacketEvent args)
|
||||||
{
|
{
|
||||||
@@ -159,6 +152,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
component.FromAirAlarmData(setData);
|
component.FromAirAlarmData(setData);
|
||||||
|
UpdateState(uid, component);
|
||||||
alarmable.IgnoreAlarms = setData.IgnoreAlarms;
|
alarmable.IgnoreAlarms = setData.IgnoreAlarms;
|
||||||
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSetDataStatus);
|
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSetDataStatus);
|
||||||
payload.Add(AirAlarmSystem.AirAlarmSetDataStatus, true);
|
payload.Add(AirAlarmSystem.AirAlarmSetDataStatus, true);
|
||||||
@@ -168,5 +162,35 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a scrubber's appearance and ambience state.
|
||||||
|
/// </summary>
|
||||||
|
private void UpdateState(EntityUid uid, GasVentScrubberComponent scrubber,
|
||||||
|
AppearanceComponent? appearance = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref appearance, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_ambientSoundSystem.SetAmbience(uid, true);
|
||||||
|
if (!scrubber.Enabled)
|
||||||
|
{
|
||||||
|
_ambientSoundSystem.SetAmbience(uid, false);
|
||||||
|
appearance.SetData(ScrubberVisuals.State, ScrubberState.Off);
|
||||||
|
}
|
||||||
|
else if (scrubber.PumpDirection == ScrubberPumpDirection.Scrubbing)
|
||||||
|
{
|
||||||
|
appearance.SetData(ScrubberVisuals.State, scrubber.WideNet ? ScrubberState.WideScrub : ScrubberState.Scrub);
|
||||||
|
}
|
||||||
|
else if (scrubber.PumpDirection == ScrubberPumpDirection.Siphoning)
|
||||||
|
{
|
||||||
|
appearance.SetData(ScrubberVisuals.State, ScrubberState.Siphon);
|
||||||
|
}
|
||||||
|
else if (scrubber.Welded)
|
||||||
|
{
|
||||||
|
_ambientSoundSystem.SetAmbience(uid, false);
|
||||||
|
appearance.SetData(ScrubberVisuals.State, ScrubberState.Welded);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user