-
Notifications
You must be signed in to change notification settings - Fork 13
Description
For many games, it's useful to have different schedulers for systems. For example a turn-based games needs a scheduler for looping logic, like rendering, but also needs to process turns whenever a player presses a button.
There are various ways to go about this problem, but I'd like to propose the following and implement it in the near future:
It should be possible to run logic on the same (game) world, in order to circumvent syncing or expensive queries. Also, scheduling should be handled similar to data. We can already define a system schedule easily! So why not take it to the next level and define schedules for all our needs and be able to execute a schedule when we need it from within another schedule? Basically, call a method on Actions which takes a ISyncPointPrefab and executes it.
Example:
const TurnProcessorSystem = createSystem({
actions: Actions,
schedules: ReadResource(SchedulesRecord), // SchedulesRecord is typed as Record<string, ISyncPointPrefab>
turnProcessingSignals: ReadEvents(TurnProcessingSignal), // may hold additional information
})
.withRunFunction(async ({actions, schedules, turnProcessingSignals}) => {
// If turn processing was requested - e.g. by clicking on a "End Turn" button ...
if (turnProcessingSignals.getOne()) {
// start processing the turn, e.g. run enemy AI
await actions.executeSchedule(schedules.turnProcessorPipeline);
}
})
.build();Using this example, I'm not 100% yet, though, if it's a good idea to inject the processing right there, or defer it using Commands, as in
actions.commands.executeSchedule(schedules.turnProcessorPipeline);Metadata
Metadata
Assignees
Labels
Type
Projects
Status