Slight DisposalUnit optimisation (#1874)
UI was being updated every tick even when not necessary. Ideally you'd just update the UI based on events but this is fine for now. Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -117,6 +117,13 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
? boundUi
|
||||
: null;
|
||||
|
||||
private DisposalUnitBoundUserInterfaceState? _lastUiState;
|
||||
|
||||
/// <summary>
|
||||
/// Store the translated state.
|
||||
/// </summary>
|
||||
private (PressureState State, string Localized) _locState;
|
||||
|
||||
public bool CanInsert(IEntity entity)
|
||||
{
|
||||
if (!Anchored)
|
||||
@@ -286,13 +293,31 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
|
||||
private DisposalUnitBoundUserInterfaceState GetInterfaceState()
|
||||
{
|
||||
var state = Loc.GetString($"{State}");
|
||||
return new DisposalUnitBoundUserInterfaceState(Owner.Name, state, _pressure, Powered, Engaged);
|
||||
string stateString;
|
||||
|
||||
if (_locState.State != State)
|
||||
{
|
||||
stateString = Loc.GetString($"{State}");
|
||||
_locState = (State, stateString);
|
||||
}
|
||||
else
|
||||
{
|
||||
stateString = _locState.Localized;
|
||||
}
|
||||
|
||||
return new DisposalUnitBoundUserInterfaceState(Owner.Name, stateString, _pressure, Powered, Engaged);
|
||||
}
|
||||
|
||||
private void UpdateInterface()
|
||||
{
|
||||
var state = GetInterfaceState();
|
||||
|
||||
if (_lastUiState != null && _lastUiState.Equals(state))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_lastUiState = state;
|
||||
UserInterface?.SetState(state);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Content.Shared.GameObjects.Components.Disposal
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class DisposalUnitBoundUserInterfaceState : BoundUserInterfaceState
|
||||
public class DisposalUnitBoundUserInterfaceState : BoundUserInterfaceState, IEquatable<DisposalUnitBoundUserInterfaceState>
|
||||
{
|
||||
public readonly string UnitName;
|
||||
public readonly string UnitState;
|
||||
@@ -75,6 +75,17 @@ namespace Content.Shared.GameObjects.Components.Disposal
|
||||
Powered = powered;
|
||||
Engaged = engaged;
|
||||
}
|
||||
|
||||
public bool Equals(DisposalUnitBoundUserInterfaceState other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return UnitName == other.UnitName &&
|
||||
UnitState == other.UnitState &&
|
||||
Powered == other.Powered &&
|
||||
Engaged == other.Engaged &&
|
||||
Pressure.Equals(other.Pressure);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user