docs
Systems
Infrastructure
UpdateSystem
Public API Reference

All types are in the SaffronLibrary.Prime.Systems.Update namespace, except the interfaces, which are in SaffronLibrary.Prime.Systems.Update.Interfaces.

IUpdateable

Implemented by any object that should receive a call every frame.

public interface IUpdateable
{
    void OnUpdate();
}
  • OnUpdate: called once per tick, during Unity's Update phase, while the object is registered.

IUpdateAdapter

Implemented by adapters that connect an engine's heartbeat to the UpdateManager.

public interface IUpdateAdapter
{
    void Initialize(Action onTick);
}
  • Initialize: receives the callback to invoke on every tick.

UpdateAdapter

Abstract base for adapters. Implements IUpdateAdapter.

public abstract class UpdateAdapter : IUpdateAdapter
{
    public void Initialize(Action onTick);
    public abstract void OnInitialized(Action onTick);
}
  • Initialize: ignores a null callback. Otherwise calls OnInitialized.
  • OnInitialized: implemented by each adapter to connect the callback to its engine.

UnityUpdateAdapter

The Unity adapter. Extends UpdateAdapter.

public class UnityUpdateAdapter : UpdateAdapter
{
    public override void OnInitialized(Action onTick);
}
  • OnInitialized: injects the callback into Unity's PlayerLoop Update phase through UpdateService.

UpdateManager

Plain C# class that holds the registered objects and ticks them.

public class UpdateManager
{
    public IUpdateAdapter UpdateAdapter;
    public List<IUpdateable> updateables;
 
    public void SetUpdateAdapter(IUpdateAdapter updateAdapter);
    public void ProcessCommand(ICommand cmd);
    public void AddUpdateable(IUpdateable updateable);
}
  • UpdateAdapter: the adapter currently connected to the manager.
  • updateables: every registered object, in registration order.
  • SetUpdateAdapter: stores the adapter and passes it the manager's tick. Null is ignored.
  • ProcessCommand: handles Register commands by reading UpdateKeys.UpdateableObject and calling AddUpdateable. Other verbs are ignored.
  • AddUpdateable: adds the object. Null and duplicate references are ignored.

The tick itself is private. On each tick, OnUpdate is called on every registered object in order.

UpdateFlowController

The flow controller for Domain.Update. Extends FlowController.

public class UpdateFlowController : FlowController
{
    protected override Domain Domain { get; }
    public override void Init();
    protected override void HandleCommand(ICommand cmd);
}
  • Domain: returns Domain.Update.
  • Init: calls base.Init(), then creates the UpdateManager, and connects it to a UnityUpdateAdapter.
  • HandleCommand: forwards commands that carry UpdateKeys.UpdateableObject to the manager.

UpdateCommandFactory

Builds and sends Update-domain commands.

public static class UpdateCommandFactory
{
    public static void RegisterUpdatable(IUpdateable updateable);
}
  • RegisterUpdatable: sends a Register command carrying the object under UpdateKeys.UpdateableObject.

UpdateCommandVerb

public enum UpdateCommandVerb
{
    Register,
}
  • Register: registers an IUpdateable to receive a call every tick.

UpdateKeys

public static class UpdateKeys
{
    public static readonly ParamKey<IUpdateable> UpdateableObject;
}
  • UpdateableObject: carries the object to register in an Update command's params.

UpdateKeyNames

public static class UpdateKeyNames
{
    public const string UpdateableObject;
}
  • UpdateableObject: the key name core.update.updateable.object.

UpdateService

Injects actions into Unity's PlayerLoop.

public static class UpdateService
{
    public static void InjectToPlayerLoop<TSystem, TPhase>(Action tickAction) where TPhase : struct;
}
  • InjectToPlayerLoop: wraps tickAction in a PlayerLoop system identified by TSystem, and adds it to the TPhase phase. The change applies to the global PlayerLoop until it is reset or the application restarts.

UpdateUtility

Helpers for modifying the PlayerLoop tree.

public static class UpdateUtility
{
    public static bool TryInsertSystem<TTargetPhase>(ref PlayerLoopSystem currentRoot, PlayerLoopSystem nodeToInsert);
}
  • TryInsertSystem: searches the tree for the TTargetPhase phase, and appends nodeToInsert to it. Returns true if the phase was found.