constructor(label: ConstructorFn)
View sourceCreates build state for a schedule label.
Class
Collects callback registrations, callback groups, and ordering rules for one normal schedule label.
SchedulerBuilder uses this context to build the matching
Schedule. Add callbacks and groups, resolve group relationships,
assign callbacks, then sort the callbacks before running the schedule.
import { ScheduleContext } from '@wimaengine/schedule'
class Update {}
class MainPhase {}
function input() {}
function render() {}
const context = new ScheduleContext(Update)
context.addGroup({ label: MainPhase, schedule: Update })
context.addSystem({ schedule: Update, systemGroup: MainPhase, system: input })
context.addSystem({ schedule: Update, after: ['input'], system: render })
context.resolveGroupParents()
context.assignSystemsToGroups()
const orderedSystems = context.sortSystems()Default: []
Default: []
Default: ...
Default: ...
Default: undefined
Default: undefined
addGroup(config: object): SystemGroupRegistrationRegisters a callback group in this context.
The group receives the next zero-based ID and starts with no callbacks.
Its parent and ordering references remain in config; parent IDs are
filled by ScheduleContext#resolveGroupParents and callbacks are
assigned by ScheduleContext#assignSystemsToGroups. A non-empty
config.label.name is also registered as an ordering label. An empty name
still registers the group but cannot be used in a name-based ordering
reference.
import { ScheduleContext } from '@wimaengine/schedule'
class Update {}
class MainPhase {}
function input() {}
const context = new ScheduleContext(Update)
const group = context.addGroup({ label: MainPhase, schedule: Update })
context.addSystem({ schedule: Update, systemGroup: MainPhase, system: input })
// group.id is 0; the callback is assigned after the context resolves groups.
context.resolveGroupParents()
context.assignSystemsToGroups()addSystem(config: object): SystemRegistrationRegisters a callback in this context.
The callback receives the next zero-based ID. A truthy config.label is
used as its ordering label; otherwise the callback function’s name is
used. A non-empty label is added to the ordering nodes, so before and
after references can resolve it later. Ordering references remain in
config until ScheduleContext#sortSystems runs. An empty label
still registers the callback but cannot be resolved by name.
import { ScheduleContext } from '@wimaengine/schedule'
class Update {}
function input() {}
function render() {}
const context = new ScheduleContext(Update)
context.addSystem({ schedule: Update, system: input })
context.addSystem({ schedule: Update, after: [input], system: render })
const orderedSystems = context.sortSystems()setDefaultSystemGroup(defaultSystemGroup: ConstructorFn): voidSets the fallback group for callbacks without an explicit systemGroup.
This stores only the group label. It does not assign callbacks or check
that the group is registered. Lookup and validation are deferred until
ScheduleContext#assignSystemsToGroups runs. An explicit
systemGroup takes precedence there; undefined leaves callbacks without
a group unassigned.
import { ScheduleContext } from '@wimaengine/schedule'
class Update {}
class MainPhase {}
function tick() {}
const context = new ScheduleContext(Update)
context.setDefaultSystemGroup(MainPhase)
context.addGroup({ label: MainPhase, schedule: Update })
context.addSystem({ schedule: Update, system: tick })
context.resolveGroupParents()
context.assignSystemsToGroups()resolveGroupParents(): voidResolves callback-group parents and validates the hierarchy.
Each configured parent constructor must already be registered in this
context. The matching zero-based group ID is stored as parentId, and
cyclic nesting is rejected before group ordering is expanded.
import { ScheduleContext } from '@wimaengine/schedule'
class Update {}
class MainPhase {}
class RenderPhase {}
const context = new ScheduleContext(Update)
context.addGroup({ label: MainPhase, schedule: Update })
context.addGroup({ label: RenderPhase, parent: MainPhase, schedule: Update })
context.resolveGroupParents()assignSystemsToGroups(): voidAssigns registered callbacks to explicit or default groups.
For each callback, systemGroup takes precedence over the fallback set
with ScheduleContext#setDefaultSystemGroup. Callbacks with
neither remain outside all groups. The selected group must already be
registered, and its ID is appended to that group’s callback list. This
method does not order callbacks.
import { ScheduleContext } from '@wimaengine/schedule'
class Update {}
class DefaultPhase {}
class ExplicitPhase {}
function update() {}
function render() {}
const context = new ScheduleContext(Update)
context.addGroup({ label: DefaultPhase, schedule: Update })
context.addGroup({ label: ExplicitPhase, schedule: Update })
context.setDefaultSystemGroup(DefaultPhase)
context.addSystem({ schedule: Update, system: update })
context.addSystem({ schedule: Update, systemGroup: ExplicitPhase, system: render })
context.assignSystemsToGroups()sortSystems(): SystemRegistration[]Resolves ordering constraints and returns callbacks in execution order.
The context expands nested group membership into a directed graph, applies
each callback and group before/after constraint, and topologically
sorts the graph. Empty groups remain ordering nodes; groups with callbacks
expand their constraints to those callbacks. The returned array contains
callback registrations only; group nodes are not returned. The normal build
sequence calls ScheduleContext#resolveGroupParents and
ScheduleContext#assignSystemsToGroups before this method.
expandScheduleGraph(): objectaddNodeOrdering(graph: Graph<SystemRegistration | SystemGroupRegistration, undefined>, graphIdsBySystemId: Map<number, number>, edges: Set<string>, source: ScheduleNodeRef, before: (string | ConstructorFn | SystemFunc)[], after: (string | ConstructorFn | SystemFunc)[], groupSystemsCache: Map<number, number[]>): voidresolveNode(label: string): ScheduleNodeRefaddExpandedEdge(graph: Graph<SystemRegistration | SystemGroupRegistration, undefined>, graphIdsBySystemId: Map<number, number>, edges: Set<string>, from: ScheduleNodeRef, to: ScheduleNodeRef, targetLabel: string | ConstructorFn | SystemFunc, groupSystemsCache: Map<number, number[]>): voidexpandNodeToOrderingNodes(node: ScheduleNodeRef, graphIdsBySystemId: Map<number, number>, groupSystemsCache: Map<number, number[]>): number[]expandGroupToGraphNode(groupId: number): numberexpandNodeToSystems(node: ScheduleNodeRef, groupSystemsCache: Map<number, number[]>): number[]expandGroupToSystems(groupId: number, cache: Map<number, number[]>, visiting: Set<number>): number[]assertNoGroupCycles(): voidValidates that group nesting is acyclic.
visitGroupHierarchy(groupId: number, state: number[]): void