Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ export class App {
* @param {{label: string, delay?: number, repeat?: boolean, errorHandler?: (error: Error, world: World) => void, defaultSystemGroup?: import('../type/index.js').Constructor}} config
*/
createSchedule(config) {
return this.scheduler.set(new Executable(config))
this.scheduler.set(new Executable(config))

return this
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/core/core/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './schedules.js'
export * from './runner.js'
export * from './entity.js'
export * from './systemgroups.js'
35 changes: 35 additions & 0 deletions src/core/core/systemgroups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Core scheduling phases used by startup and update schedules.
*/
class Start {}

/**
* Systems that should run before the main phase.
*/
class PreMain {}

/**
* The default core phase for startup and update schedules.
*/
class Main {}

/**
* Systems that should run after the main phase.
*/
class PostMain {}

/**
* Final core scheduling phase.
*/
class End {}

/**
* @enum {import('../../type/index.js').Constructor}
*/
export const CoreSystems = Object.freeze({
Start,
PreMain,
Main,
PostMain,
End
})
75 changes: 66 additions & 9 deletions src/core/plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App, Plugin } from '../app/index.js'
import { AppSchedule, defaultRunner } from './core/index.js'
import { AppSchedule, CoreSystems, defaultRunner } from './core/index.js'
import { registerCoreTypes } from './systems/index.js'

export class CorePlugin extends Plugin {
Expand All @@ -8,13 +8,70 @@ export class CorePlugin extends Plugin {
* @param {App} app
*/
register(app) {
app.setRunner(defaultRunner)
app.createSchedule(
{ label: AppSchedule.Startup, repeat: false }
)
app.createSchedule(
{ label: AppSchedule.Update, repeat: true }
)
app.registerSystem({ schedule: AppSchedule.Startup, system: registerCoreTypes })
app
.setRunner(defaultRunner)
.createSchedule({
label: AppSchedule.Startup,
repeat: false,
defaultSystemGroup: CoreSystems.Main
})
.createSchedule({
label: AppSchedule.Update,
repeat: true,
defaultSystemGroup: CoreSystems.Main
})
.registerSystemGroup({
label: CoreSystems.Start,
schedule: AppSchedule.Startup,
before: [CoreSystems.PreMain]
})
.registerSystemGroup({
label: CoreSystems.PreMain,
schedule: AppSchedule.Startup,
before: [CoreSystems.Main]
})
.registerSystemGroup({
label: CoreSystems.Main,
schedule: AppSchedule.Startup,
before: [CoreSystems.PostMain]
})
.registerSystemGroup({
label: CoreSystems.PostMain,
schedule: AppSchedule.Startup,
before: [CoreSystems.End]
})
.registerSystemGroup({
label: CoreSystems.End,
schedule: AppSchedule.Startup
})

.registerSystemGroup({
label: CoreSystems.Start,
schedule: AppSchedule.Update,
before: [CoreSystems.PreMain]
})
.registerSystemGroup({
label: CoreSystems.PreMain,
schedule: AppSchedule.Update,
before: [CoreSystems.Main]
})
.registerSystemGroup({
label: CoreSystems.Main,
schedule: AppSchedule.Update,
before: [CoreSystems.PostMain]
})
.registerSystemGroup({
label: CoreSystems.PostMain,
schedule: AppSchedule.Update,
before: [CoreSystems.End]
})
.registerSystemGroup({
label: CoreSystems.End,
schedule: AppSchedule.Update
})
.registerSystem({
schedule: AppSchedule.Startup,
system: registerCoreTypes
})
}
}
Loading