Refactor GasCanisterSystem to use Resolves, improves canister performance slightly.
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.CodeDom;
|
|
||||||
using Content.Server.Atmos.Components;
|
using Content.Server.Atmos.Components;
|
||||||
using Content.Server.Atmos.EntitySystems;
|
using Content.Server.Atmos.EntitySystems;
|
||||||
using Content.Server.Atmos.Piping.Binary.Components;
|
|
||||||
using Content.Server.Atmos.Piping.Components;
|
using Content.Server.Atmos.Piping.Components;
|
||||||
using Content.Server.Atmos.Piping.Unary.Components;
|
using Content.Server.Atmos.Piping.Unary.Components;
|
||||||
using Content.Server.Hands.Components;
|
using Content.Server.Hands.Components;
|
||||||
@@ -17,7 +15,6 @@ using Content.Shared.Interaction;
|
|||||||
using Content.Shared.Interaction.Helpers;
|
using Content.Shared.Interaction.Helpers;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Player;
|
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -74,19 +71,21 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DirtyUI(EntityUid uid)
|
private void DirtyUI(EntityUid uid,
|
||||||
|
GasCanisterComponent? canister = null, NodeContainerComponent? nodeContainer = null,
|
||||||
|
ContainerManagerComponent? containerManager = null, IMetaDataComponent? metadata = null)
|
||||||
{
|
{
|
||||||
if (!ComponentManager.TryGetComponent(uid, out IMetaDataComponent? metadata)
|
if (!Resolve(uid, ref metadata, ref canister, ref nodeContainer, ref containerManager))
|
||||||
|| !ComponentManager.TryGetComponent(uid, out GasCanisterComponent? canister)
|
|
||||||
|| !ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|
|
||||||
|| !nodeContainer.TryGetNode(canister.PortName, out PipeNode? portNode))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var portStatus = false;
|
||||||
string? tankLabel = null;
|
string? tankLabel = null;
|
||||||
var tankPressure = 0f;
|
var tankPressure = 0f;
|
||||||
|
|
||||||
if (ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager)
|
if (nodeContainer.TryGetNode(canister.PortName, out PipeNode? portNode) && portNode.NodeGroup?.Nodes.Count > 1)
|
||||||
&& containerManager.TryGetContainer(canister.ContainerName, out var tankContainer)
|
portStatus = true;
|
||||||
|
|
||||||
|
if (containerManager.TryGetContainer(canister.ContainerName, out var tankContainer)
|
||||||
&& tankContainer.ContainedEntities.Count > 0)
|
&& tankContainer.ContainedEntities.Count > 0)
|
||||||
{
|
{
|
||||||
var tank = tankContainer.ContainedEntities[0];
|
var tank = tankContainer.ContainedEntities[0];
|
||||||
@@ -95,10 +94,10 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
tankPressure = tankComponent.Air.Pressure;
|
tankPressure = tankComponent.Air.Pressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
_userInterfaceSystem.TrySetUiState(uid, GasCanisterUiKey.Key, new GasCanisterBoundUserInterfaceState(metadata.EntityName, canister.Air.Pressure,
|
_userInterfaceSystem.TrySetUiState(uid, GasCanisterUiKey.Key,
|
||||||
portNode.NodeGroup?.Nodes.Count > 1, tankLabel, tankPressure,
|
new GasCanisterBoundUserInterfaceState(metadata.EntityName,
|
||||||
canister.ReleasePressure, canister.ReleaseValve,
|
canister.Air.Pressure, portStatus, tankLabel, tankPressure, canister.ReleasePressure,
|
||||||
canister.MinReleasePressure, canister.MaxReleasePressure));
|
canister.ReleaseValve, canister.MinReleasePressure, canister.MaxReleasePressure));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnHoldingTankEjectMessage(EntityUid uid, GasCanisterComponent canister, GasCanisterHoldingTankEjectMessage args)
|
private void OnHoldingTankEjectMessage(EntityUid uid, GasCanisterComponent canister, GasCanisterHoldingTankEjectMessage args)
|
||||||
@@ -124,7 +123,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
var pressure = Math.Clamp(args.Pressure, canister.MinReleasePressure, canister.MaxReleasePressure);
|
var pressure = Math.Clamp(args.Pressure, canister.MinReleasePressure, canister.MaxReleasePressure);
|
||||||
|
|
||||||
canister.ReleasePressure = pressure;
|
canister.ReleasePressure = pressure;
|
||||||
DirtyUI(uid);
|
DirtyUI(uid, canister);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCanisterChangeReleaseValve(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleaseValveMessage args)
|
private void OnCanisterChangeReleaseValve(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleaseValveMessage args)
|
||||||
@@ -133,7 +132,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
canister.ReleaseValve = args.Valve;
|
canister.ReleaseValve = args.Valve;
|
||||||
DirtyUI(uid);
|
DirtyUI(uid, canister);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCanisterUpdated(EntityUid uid, GasCanisterComponent canister, AtmosDeviceUpdateEvent args)
|
private void OnCanisterUpdated(EntityUid uid, GasCanisterComponent canister, AtmosDeviceUpdateEvent args)
|
||||||
@@ -163,10 +162,12 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
canister.Air.Multiply(canister.Air.Volume / buffer.Volume);
|
canister.Air.Multiply(canister.Air.Volume / buffer.Volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ContainerManagerComponent? containerManager = null;
|
||||||
|
|
||||||
// Release valve is open, release gas.
|
// Release valve is open, release gas.
|
||||||
if (canister.ReleaseValve)
|
if (canister.ReleaseValve)
|
||||||
{
|
{
|
||||||
if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager)
|
if (!ComponentManager.TryGetComponent(uid, out containerManager)
|
||||||
|| !containerManager.TryGetContainer(canister.ContainerName, out var container))
|
|| !containerManager.TryGetContainer(canister.ContainerName, out var container))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -182,7 +183,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DirtyUI(uid);
|
DirtyUI(uid, canister, nodeContainer, containerManager);
|
||||||
|
|
||||||
// If last pressure is very close to the current pressure, do nothing.
|
// If last pressure is very close to the current pressure, do nothing.
|
||||||
if (MathHelper.CloseTo(canister.Air.Pressure, canister.LastPressure))
|
if (MathHelper.CloseTo(canister.Air.Pressure, canister.LastPressure))
|
||||||
@@ -258,7 +259,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
if (args.Container.ID != component.ContainerName)
|
if (args.Container.ID != component.ContainerName)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DirtyUI(uid);
|
DirtyUI(uid, component);
|
||||||
|
|
||||||
if (!ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance))
|
if (!ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance))
|
||||||
return;
|
return;
|
||||||
@@ -271,7 +272,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
if (args.Container.ID != component.ContainerName)
|
if (args.Container.ID != component.ContainerName)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DirtyUI(uid);
|
DirtyUI(uid, component);
|
||||||
|
|
||||||
if (!ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance))
|
if (!ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance))
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user