Table of Contents

Class TickingThread

Namespace
Shard.Gameplay.Universe.World
Assembly
Shard.Gameplay.Universe.dll

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

threadName string

Fields

DefaultTicksPerSecond

Default tick rate used by world-style loops.

public const int DefaultTicksPerSecond = 30

Field Value

int

MaxTicksPerSecond

Highest supported runtime tick rate.

public const int MaxTicksPerSecond = 2048

Field Value

int

MinTicksPerSecond

Lowest supported runtime tick rate.

public const int MinTicksPerSecond = 1

Field Value

int

Properties

CurrentTick

Gets the number of completed ticks.

public long CurrentTick { get; }

Property Value

long

IsDisposed

Gets whether disposal has started.

protected bool IsDisposed { get; }

Property Value

bool

IsIdle

Allows derived loops to reduce spin timing while still processing tasks and ticks.

protected virtual bool IsIdle { get; }

Property Value

bool

IsOnTickThread

Gets whether the current caller is executing on the loop thread.

public bool IsOnTickThread { get; }

Property Value

bool

IsRunning

Gets whether the loop thread is running.

public bool IsRunning { get; }

Property Value

bool

TicksPerSecond

Gets the current target tick rate.

public int TicksPerSecond { get; }

Property Value

int

Methods

DisposeAsync()

Stops the loop, releases wait handles, and suppresses finalization for derived types.

public ValueTask DisposeAsync()

Returns

ValueTask

DisposeAsyncCore()

Performs disposal once for the task published by DisposeAsync().

protected virtual Task DisposeAsyncCore()

Returns

Task

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

ticksPerSecond int

StartAsync()

Starts the loop thread and completes after startup work finishes.

public Task StartAsync()

Returns

Task

StopAsync()

Requests the loop to stop and completes after shutdown work finishes.

public Task StopAsync()

Returns

Task

Tick(float)

Runs one measured tick on the loop thread.

protected abstract void Tick(float deltaSeconds)

Parameters

deltaSeconds float

ValidateTicksPerSecond(int)

Validates that a requested tick rate is supported.

protected static void ValidateTicksPerSecond(int ticksPerSecond)

Parameters

ticksPerSecond int

WakeTickThread()

Wakes the loop from a timed wait without advancing its fixed-rate schedule.

protected void WakeTickThread()