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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user