Game.UI.UIUpdateState
Assembly:
Namespace: Game.UI
Type: class
Base: System.Object
Summary:
Utility class that controls how often UI logic should update relative to the simulation frame index. It queries the SimulationSystem.frameIndex and tracks the last tick when the UI performed an update. Updates occur when the configured update interval elapses or when a force update is requested. Typically used by UI systems to limit work performed every frame and to sync UI updates with the simulation tick counter.
Fields
-
private readonly SimulationSystem m_SimulationSystem
Reference to the SimulationSystem instance from the provided World. Used to read the current simulation frame index (m_SimulationSystem.frameIndex) to decide whether an update should occur. -
private readonly uint m_UpdateInterval
Configured number of simulation frames between automatic UI updates (cast from the int updateInterval supplied at construction). If the difference between the current frame index and m_LastTickIndex is greater than or equal to this value, Advance() will return true. -
private bool m_ForceUpdate
Flag that, when true, causes Advance() to return true regardless of interval. Reset to false after producing an update. Create(...) initializes this to true so the UI gets an immediate first update. -
private uint m_LastTickIndex
Stores the simulation frameIndex at which the last UI update was performed. Updated to the current frameIndex when Advance() triggers an update.
Properties
This class exposes no public properties.
Constructors
-
private UIUpdateState(World world, int updateInterval)
Constructs a UIUpdateState bound to the given World. Fetches (or creates) the SimulationSystem from the world and stores the update interval (converted to uint). The m_ForceUpdate flag is set true so the first Advance() call will return true. -
public static UIUpdateState Create(World world, int updateInterval)
Factory method to create a UIUpdateState instance. Use this to create instances rather than calling the constructor directly (constructor is private).
Methods
public bool Advance()
Checks whether a UI update should occur at the current simulation frame. Returns true and updates internal state if either:- m_ForceUpdate is true (then m_ForceUpdate is cleared), or
-
the number of frames since the last update (m_SimulationSystem.frameIndex - m_LastTickIndex) is greater than or equal to m_UpdateInterval. If an update is triggered, m_LastTickIndex is set to the current frameIndex. Otherwise returns false.
-
public void ForceUpdate()
Sets the m_ForceUpdate flag so the next call to Advance() will return true regardless of the interval. Useful when external events require an immediate UI refresh.
Usage Example
// create with a World instance and an interval (e.g., update UI every 2 simulation frames)
UIUpdateState uiState = UIUpdateState.Create(world, 2);
// in your UI update loop:
if (uiState.Advance())
{
// perform UI update work (synchronizing with simulation)
}
// force an immediate update from elsewhere:
uiState.ForceUpdate();