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:
metalgearsloth
2020-08-24 21:16:23 +10:00
committed by GitHub
parent 56ebde7f45
commit 501c8a9f6a
2 changed files with 39 additions and 3 deletions

View File

@@ -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);
}