Class TickingThread
Base class for single-threaded fixed-rate simulation loops.
public abstract class TickingThread : IAsyncDisposable
- Inheritance
-
TickingThread
- Implements
- Derived
- Inherited Members
Remarks
Derived types own their loop thread. Start completes after OnStart() finishes, and shutdown always runs on the loop thread before the stop task completes.
Constructors
TickingThread(string)
protected TickingThread(string threadName)
Parameters
threadNamestring
Fields
DefaultTicksPerSecond
Default tick rate used by world-style loops.
public const int DefaultTicksPerSecond = 30
Field Value
MaxTicksPerSecond
Highest supported runtime tick rate.
public const int MaxTicksPerSecond = 2048
Field Value
MinTicksPerSecond
Lowest supported runtime tick rate.
public const int MinTicksPerSecond = 1
Field Value
Properties
CurrentTick
Gets the number of completed ticks.
public long CurrentTick { get; }
Property Value
IsDisposed
Gets whether disposal has started.
protected bool IsDisposed { get; }
Property Value
IsIdle
Allows derived loops to reduce spin timing while still processing tasks and ticks.
protected virtual bool IsIdle { get; }
Property Value
IsOnTickThread
Gets whether the current caller is executing on the loop thread.
public bool IsOnTickThread { get; }
Property Value
IsRunning
Gets whether the loop thread is running.
public bool IsRunning { get; }
Property Value
TicksPerSecond
Gets the current target tick rate.
public int TicksPerSecond { get; }
Property Value
Methods
DisposeAsync()
Stops the loop, releases wait handles, and suppresses finalization for derived types.
public ValueTask DisposeAsync()
Returns
DisposeAsyncCore()
Performs disposal once for the task published by DisposeAsync().
protected virtual Task DisposeAsyncCore()
Returns
Remarks
Overrides must await this implementation and release derived resources in a finally block so every caller observes the same completion.
OnShutdown()
Runs once on the loop thread after the tick loop exits.
protected virtual void OnShutdown()
OnStart()
Runs once on the loop thread before the start task completes.
protected virtual void OnStart()
SetTicksPerSecond(int)
Changes the target tick rate from the loop thread.
protected void SetTicksPerSecond(int ticksPerSecond)
Parameters
ticksPerSecondint
StartAsync()
Starts the loop thread and completes after startup work finishes.
public Task StartAsync()
Returns
StopAsync()
Requests the loop to stop and completes after shutdown work finishes.
public Task StopAsync()
Returns
Tick(float)
Runs one measured tick on the loop thread.
protected abstract void Tick(float deltaSeconds)
Parameters
deltaSecondsfloat
ValidateTicksPerSecond(int)
Validates that a requested tick rate is supported.
protected static void ValidateTicksPerSecond(int ticksPerSecond)
Parameters
ticksPerSecondint
WakeTickThread()
Wakes the loop from a timed wait without advancing its fixed-rate schedule.
protected void WakeTickThread()