Skip to content
Popax21 edited this page Sep 3, 2022 · 11 revisions

Procedurline has some utility classes and functionality whose purpose is to make the code more clean and easier to write. Most of these are in the Misc code folder.

ColorUtils

Contains helper methods useful for dealing with colors and their manipulation. This is mostly achieved using color matrices, and this class contains methods to calculate / manipulate them.

VoidBox

An empty struct with equality operators which always return false. Used to NOP out generic type arguments.

DisposablePool

Keeps track of a list of IDisposables, which can then be disposed all at once. Disposables are disposed in the reverse order of their addition.

DisposablePoolComponent is a Monocle component which can be used to create a DisposablePool with the lifetime of a Monocle entity. It is disposed once the entity or component is removed, or when the scene ends.

AsyncRef<T>

A helper class which can be used to pass objects by reference when calling asynchronous methods.

AsyncUtils

Provides helper methods which make dealing with async methods easier:

  • .ContinueWithOrInvoke: adds a continuation handler to a task, but also immediately invokes the handler if the task already finished. Makes sure the handler is only called once
  • .OrCancelled: creates a new task which finishes either when the original task finishes, or when the given CancellationToken gets cancelled. This can be used to abort awaiting of a given long-running task.
  • .WrapResult: returns a new task which returns the result of the original task after applying a wrapper function.
  • .WrapAsync: returns an IAsyncDataProcessor<T, I, D> which wraps a synchronous IDataProcessor<T, I, D>. This creates an instance of AsyncProcessorWrapper<T, I, D>

GlobalManager

A GameComponent which deals with miscellaneous tasks, like invalidating default scopes. It can be accessed using ProcedurlineModule.GlobalManager.

  • GlobalManager.MainThreadTaskFactory/Scheduler: a task factory / scheduler which runs its tasks on the main thread. Scheduled tasks are run at the beginning of Engine.Update. When created with the GlobalManager.ForceQueue task creation flag, the task won't be immediately executed when the current thread is the main thread, and instead will be forcibly queued to run during the next task execution run.
  • GlobalManager.BlockEngineOnTask(): prevents the engine from updating or rendering as long as the given task hasn't finished execution yet. This effectively NOPs out both Engine.Update and Engine.Draw, resulting in something like a lag frame. The intended purpose is to replace Task.Wait for the main thread, as this prevents deadlocks because the MainThreadHelper and the MainThreadTaskScheduler will still execute tasks.

GCCallback

A helper class which calls a callback every time a garbage collector generation occurs.