Scheduler
Defined in: scheduler/scheduler.ts:103
The type for the scheduler created with scheduler.
Methods
Section titled “Methods”configureSet()
Section titled “configureSet()”configureSet(
schedule,set,config):this
Defined in: scheduler/scheduler.ts:213
Configures a SystemSet for the specified schedule with the given config.
Parameters
Section titled “Parameters”schedule
Section titled “schedule”config
Section titled “config”Returns
Section titled “Returns”this
Remarks
Section titled “Remarks”System set configuration is per schedule, meaning the same system set can be configured differently for each schedule.
Example
Section titled “Example”const sense = new SystemSet('sense')const think = new SystemSet('think')const act = new SystemSet('act')
scheduler() // System sets that don't need configuration don't need to be configured. .configureSet('update', think, { after: sense }) .configureSet('update', act, { after: think }) .run()run():
void
Defined in: scheduler/scheduler.ts:282
Builds all plugins and then initializes every schedule.
Returns
Section titled “Returns”void
Remarks
Section titled “Remarks”Throws if run is called while the scheduler is already running.
When a schedule is initialized, an entity representing it is spawned and all related systems are made children of it.
usePlugin()
Section titled “usePlugin()”usePlugin<
Args>(pluginFn, …args):this
Defined in: scheduler/scheduler.ts:245
Registers a plugin function to be run before the scheduler starts. This function is
given the scheduler and anything else passed in ...args.
Type Parameters
Section titled “Type Parameters”Args extends unknown[]
Parameters
Section titled “Parameters”pluginFn
Section titled “pluginFn”PluginFn<Args>
…Args
Returns
Section titled “Returns”this
Remarks
Section titled “Remarks”Throws when given an arrow function, as plugins strictly require an inferable name.
Example
Section titled “Example”function physics(scheduler: Scheduler, gravity: number) { scheduler.useSystem('update', updatePhysics, { args: gravity })}
scheduler() .usePlugin(physics, 196.2) .run()Introspection
Section titled “Introspection”After a plugin is built, it becomes an entity with the Plugin component.
This allows you to inspect metadata about the plugin and manipulate it.
Additionally, every entity spawned within a plugin is automatically given
the pair(AddedByPlugin, pluginEntity) relationship.
useSystem()
Section titled “useSystem()”useSystem<
Args>(schedule,systemFn,config?):this
Defined in: scheduler/scheduler.ts:160
Schedules a system to run in the specified schedule with the provided arguments.
Optionally, a SystemConfig can be passed to configure the system, such as specifying when it should run or
in which system set it should belong.
Type Parameters
Section titled “Type Parameters”Args extends unknown[]
Parameters
Section titled “Parameters”schedule
Section titled “schedule”systemFn
Section titled “systemFn”SystemFn<Args>
config?
Section titled “config?”SystemConfig<Args>
Returns
Section titled “Returns”this
Remarks
Section titled “Remarks”It cannot be assumed that two systems scheduled in the same phase will run in the order they were registered.
Instead, consider using useSystemChain.
Example
Section titled “Example”scheduler() .useSystem('update', runsFirst) .useSystem('update', runsSecond, { after: runsFirst }) .run()Introspection
Section titled “Introspection”After a system is scheduled, it becomes an entity with the System component.
This allows you to inspect metadata about the system and manipulate it.
Additionally, the system is automatically made a child of its schedule
(i.e. pair(ChildOf, scheduleEntity)).
useSystemChain()
Section titled “useSystemChain()”useSystemChain(
schedule, …systemFns):this
Defined in: scheduler/scheduler.ts:184
Schedules a chain of systems to run in order in the specified schedule,
with an optional SystemConfig for each system.
Parameters
Section titled “Parameters”schedule
Section titled “schedule”systemFns
Section titled “systemFns”…(SystemFn | [SystemFn, SystemConfig<unknown[]>])[]
Returns
Section titled “Returns”this
Example
Section titled “Example”scheduler() .useSystemChain('update', [ gatherInput, // Implicitly runs before `drawUI`. [drawUI, { runIf: !inCinematicMode }], ]) .run()