LayerProcGen v0.1.0
Layer-based infinite procedural generation
Loading...
Searching...
No Matches
MainThreadActionQueue

Enqueue actions from generation threads to be processed on the main thread. More...

Static Public Member Functions

static void Enqueue (Action action)
 Enqueue a System.Action on the regular queue, to be performed on the main thread.
 
static void Enqueue (IQueuedAction action)
 Enqueue an IQueuedAction on the regular queue, to be performed on the main thread.
 
static void EnqueueFastTrack (Action action)
 Enqueue a System.Action on the fast track queue, to be performed on the main thread prior to actions in the regular queue.
 
static void EnqueueFastTrack (IQueuedAction action)
 Enqueue an IQueuedAction on the fast track queue, to be performed on the main thread prior to actions in the regular queue.
 
static void EnqueueNextFrame (Action action)
 Enqueue a System.Action to be performed on the main thread next frame.
 
static void EnqueueNextFrame (IQueuedAction action)
 Enqueue an IQueuedAction to be performed on the main thread next frame.
 
static void ProcessQueue ()
 ProcessQueue must be called once per frame on the main thread, typically handled by the engine-specific part of the framework.
 

Static Public Attributes

static readonly Stopwatch watch = new Stopwatch()
 Timer that measures time spent on main thread actions. Reset at the end of ProcessQueue.
 

Properties

static int budgetPerFrame = 1 [get, set]
 The available budget per frame in milliseconds for main thread actions. Additional actions are processed as long as there is remaining budget, so the last action processed will likely exceed the budget slightly.
 
static bool idle [get]
 Are all the queues currently empty?
 
static int queueCount [get]
 The current total amount of queued actions in all queue types.
 

Detailed Description

Enqueue actions from generation threads to be processed on the main thread.

Actions can be scheduled in the regular queue, in the fast track queue or for immediate processing next frame. Actions scheduled for next frame are always processed in that frame. If there is remaining budget after that, fast track actions are processed, and if further remaining budget, actions from the regular queue. Actions not processed remain in their respective queues for consideration in the following frame.

Member Data Documentation

◆ watch

readonly Stopwatch watch = new Stopwatch()
static

Timer that measures time spent on main thread actions. Reset at the end of ProcessQueue.

If you perform other work on the main thread that you want to make use of the same per-frame buget as the main thread action queue actions, you can call Start and Stop on this timer before and after that work is performed, respectively. This will reduce the available budget for the queued main thread actions, possibly postponing them to later, except for the ones scheduled for next frame.