Skip to content

Scheduler

Defined in: src/scheduler.ts:173

The starting point of a game made with Toucan.

run(): this

Defined in: src/scheduler.ts:271

Synchronously builds all initially registered plugins (user-defined first), and then bootstraps the engine to run all systems on their respective phases.

Systems and plugins scheduled dynamically after the scheduler is already running will be picked up automatically on the next frame (with the exception of the STARTUP phase, which only fires once during this method call).

this


usePlugin<Args>(plugin, …args): this

Defined in: src/scheduler.ts:258

Schedules a plugin to be built, passing it the scheduler itself and the provided arguments.

Plugins are entities with the standard Plugin component, thus, they can be queried and manipulated like any other entity in Toucan.

Plugins scheduled within other plugins are automatically parented to the parent plugin.

Args extends defined[]

Plugin<Args>

Args

this

function updatePhysics(gravity: number) { ... }
function physicsPlugin(scheduler: Scheduler, gravity: number) {
scheduler.useSystem(updatePhysics, UPDATE, gravity)
}
scheduler()
.usePlugin(physicsPlugin, 196.2)
.run()

useSystem<Args>(system, phase, …args): this

Defined in: src/scheduler.ts:214

Schedules a system to run in the specified phase with the provided arguments.

The system’s label is inferred from the function name. If the function is anonymous, a default label is generated instead.

Args extends defined[]

System<Args>

Phase

Args

this

function fireGun(params: RaycastParams) { ... }
scheduler()
.useSystem(fireGun, UPDATE, new RaycastParams())
.run()

If multiple systems are registered in the same phase, they will be executed in the order they were registered in the codebase.

Phases should still be the main tool for controlling execution order, but this allows for more fine-grained control when creating an entire new phase would be overkill.

scheduler()
.useSystem(runsFirst, UPDATE)
.useSystem(runsSecond, UPDATE)
.run()

Systems are entities with the standard System component, thus, they can be queried and manipulated like any other entity in Toucan.

Systems scheduled within plugins are automatically parented to the plugin.


useSystemWithLabel<Args>(system, phase, label, …args): this

Defined in: src/scheduler.ts:223

Similar to useSystem, but allows you to specify a custom label for the system. Useful for anonymous functions.

Args extends defined[]

System<Args>

Phase

string

Args

this