mani-game-engine 1.0.0-pre.57 → 1.0.0-pre.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,8 +44,9 @@ export declare class GameEngine {
44
44
  private readonly onAddEntitySet;
45
45
  private readonly onRemoveEntitySet;
46
46
  private readonly entitySystemMap;
47
- private readonly serviceClasses;
47
+ private readonly registeredServices;
48
48
  private readonly services;
49
+ private readonly systemChildInjectors;
49
50
  private framePromise;
50
51
  private resolveFrame;
51
52
  private addQueue;
@@ -60,7 +61,9 @@ export declare class GameEngine {
60
61
  constructor(injector: EcsInjector<Class<System>>, clock: Clock);
61
62
  static createDefault(options?: GameEngineOptions): GameEngine;
62
63
  static createDefaultWithInjector(injector: EcsInjector<Class<System>>, options?: GameEngineOptions): GameEngine;
63
- addService(service: Service): void;
64
+ addServiceClass(serviceClass: Class<Service>, mapping?: (injector: EcsInjector) => void): Service;
65
+ private addService;
66
+ removeService(service: Service): void;
64
67
  installPlugins(plugins: GameEnginePlugin[]): void;
65
68
  registerSystem(systemClass: Class<System>): void;
66
69
  registerService(serviceClass: Class<Service>): void;
package/lib/gameEngine.js CHANGED
@@ -32,8 +32,9 @@ class GameEngine {
32
32
  this.onAddEntitySet = new Set();
33
33
  this.onRemoveEntitySet = new Set();
34
34
  this.entitySystemMap = new Map();
35
- this.serviceClasses = new Set();
35
+ this.registeredServices = new Set();
36
36
  this.services = [];
37
+ this.systemChildInjectors = new Map();
37
38
  this.resolveFrame = () => undefined;
38
39
  this.addQueue = [];
39
40
  this.removeQueue = [];
@@ -81,6 +82,20 @@ class GameEngine {
81
82
  engine.installPlugins(opts.plugins);
82
83
  return engine;
83
84
  }
85
+ addServiceClass(serviceClass, mapping) {
86
+ let childInjector;
87
+ if (mapping) {
88
+ childInjector = this.injector.createChild();
89
+ mapping(childInjector);
90
+ }
91
+ this.mapStaticAnnotatedSignals(serviceClass);
92
+ const service = (childInjector === null || childInjector === void 0 ? void 0 : childInjector.get(serviceClass)) || this.injector.get(serviceClass);
93
+ this.addService(service);
94
+ if (childInjector) {
95
+ this.systemChildInjectors.set(service, childInjector);
96
+ }
97
+ return service;
98
+ }
84
99
  addService(service) {
85
100
  this.mapAnnotatedSignals(service);
86
101
  service.onStart && service.onStart();
@@ -97,6 +112,30 @@ class GameEngine {
97
112
  service.onRemoveEntity && this.onRemoveEntitySet.add(service);
98
113
  this.services.push(service);
99
114
  }
115
+ removeService(service) {
116
+ const index = this.services.indexOf(service);
117
+ if (index === -1)
118
+ return;
119
+ this.services.splice(index, 1);
120
+ this.unmapAnnotatedSignals(service);
121
+ service.onPreFixedUpdate && this.onPreFixedUpdateSet.delete(service);
122
+ service.onFixedUpdate && this.onFixedUpdateSet.delete(service);
123
+ service.onUpdate && this.onUpdateSet.delete(service);
124
+ service.onLateUpdate && this.onLateUpdateSet.delete(service);
125
+ service.onPrePhysicsUpdate && this.onPrePhysicsUpdateSet.delete(service);
126
+ service.onPhysicsUpdate && this.onPhysicsUpdateSet.delete(service);
127
+ service.onPostPhysicsUpdate && this.onPostPhysicsUpdateSet.delete(service);
128
+ service.onLateFixedUpdate && this.onLateFixedUpdateSet.delete(service);
129
+ service.onRender && this.onRenderUpdateSet.delete(service);
130
+ service.onAddEntity && this.onAddEntitySet.delete(service);
131
+ service.onRemoveEntity && this.onRemoveEntitySet.delete(service);
132
+ service.onEnd && service.onEnd();
133
+ const childInjector = this.systemChildInjectors.get(service);
134
+ if (childInjector) {
135
+ childInjector.dispose();
136
+ this.systemChildInjectors.delete(service);
137
+ }
138
+ }
100
139
  installPlugins(plugins) {
101
140
  plugins.forEach(plugin => {
102
141
  plugin.onPrepare && plugin.onPrepare(this);
@@ -116,14 +155,14 @@ class GameEngine {
116
155
  if (this._started)
117
156
  throw new Error('Register Services before engine is started');
118
157
  this.injector.map(serviceClass).toSingleton();
119
- this.serviceClasses.add(serviceClass);
158
+ this.registeredServices.add(serviceClass);
120
159
  }
121
160
  getService(serviceClass) {
122
161
  return this.injector.get(serviceClass);
123
162
  }
124
163
  start() {
125
164
  this._started = true;
126
- for (const serviceClass of this.serviceClasses) {
165
+ for (const serviceClass of this.registeredServices) {
127
166
  const service = this.injector.get(serviceClass);
128
167
  this.addService(service);
129
168
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gameEngine.js","sourceRoot":"","sources":["../src/gameEngine.ts"],"names":[],"mappings":";;;AAAA,mCAA6H;AAG7H,+CAAgF;AAChF,mCAAyC;AAEzC,yCAA2C;AAK3C,MAAM,cAAc,GAAG;IACnB,cAAc,EAAE,CAAC,GAAG,EAAE;IACtB,OAAO,EAAE,EAAwB;CACpC,CAAC;AAYF,IAAI,EAAE,GAAG,CAAC,CAAC;AACX,MAAa,UAAU;IA2CnB,IAAI,OAAO,KAAc,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAGhD,IAAI,UAAU,KAAa,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAGrD,IAAI,eAAe,KAAa,OAAO,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAE/D,IAAI,WAAW,KAAa,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA,CAAC;IAK9D,YACa,QAAoC,EACpC,KAAY;QADZ,aAAQ,GAAR,QAAQ,CAA4B;QACpC,UAAK,GAAL,KAAK,CAAO;QAzDhB,OAAE,GAAG,EAAE,EAAE,CAAC;QAeF,qBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;QACrC,gBAAW,GAAG,IAAI,GAAG,EAAU,CAAC;QAChC,qBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;QACrC,wBAAmB,GAAG,IAAI,GAAG,EAAU,CAAC;QACxC,uBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;QACvC,0BAAqB,GAAG,IAAI,GAAG,EAAU,CAAC;QAC1C,2BAAsB,GAAG,IAAI,GAAG,EAAU,CAAC;QAC3C,yBAAoB,GAAG,IAAI,GAAG,EAAU,C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AC7D,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,CAAC,YAAY,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3D,MAAM,CAAC,eAAe,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACjE,MAAM,CAAC,kBAAkB,IAAI,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACvE,MAAM,CAAC,mBAAmB,IAAI,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACzE,MAAM,CAAC,iBAAiB,IAAI,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACrE,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3D,CAAC;CACF;AA1dD,gCA0dC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mani-game-engine",
3
3
  "author": "Jan Mankopf",
4
- "version": "1.0.0-pre.57",
4
+ "version": "1.0.0-pre.59",
5
5
  "description": "entity component system game engine for typescript",
6
6
  "private": false,
7
7
  "scripts": {
package/src/gameEngine.ts CHANGED
@@ -10,15 +10,15 @@ type AddEntry = [Entity, () => void];
10
10
  type RemoveEntry = [Entity, () => void];
11
11
 
12
12
  const defaultOptions = {
13
- fixedDeltaTime: 1 / 60,
14
- plugins: [] as GameEnginePlugin[],
13
+ fixedDeltaTime: 1 / 60,
14
+ plugins: [] as GameEnginePlugin[],
15
15
  };
16
16
 
17
17
  export type GameEngineOptions = Partial<typeof defaultOptions>;
18
18
  declare global {
19
- interface GameEngineActions {
20
- 'testAction': string;
21
- }
19
+ interface GameEngineActions {
20
+ 'testAction': string;
21
+ }
22
22
  }
23
23
 
24
24
  type GameEngineActionParams<K extends keyof GameEngineActions> = GameEngineActions[K];
@@ -26,436 +26,479 @@ type GameAction<K extends keyof GameEngineActions> = (engine: GameEngine, params
26
26
 
27
27
  let id = 0;
28
28
  export class GameEngine {
29
- readonly id = id++;
30
- readonly onPrepare: Signal;
31
- readonly onStart: Signal;
32
- readonly onEnd: Signal;
33
- readonly onRender: Signal<OnUpdateParams>;
34
- readonly onUpdate: Signal<OnUpdateParams>;
35
- readonly onFixedUpdate: Signal<OnFixedUpdateParams>;
36
- readonly onPrePhysicsUpdate: Signal<OnFixedUpdateParams>;
37
- readonly onPhysicsUpdate: Signal<OnFixedUpdateParams>;
38
- readonly onPostPhysicsUpdate: Signal<OnFixedUpdateParams>;
39
- readonly onLateFixedUpdate: Signal<OnFixedUpdateParams>;
40
- readonly onLateUpdate: Signal<OnUpdateParams>;
41
- readonly onAddEntity: Signal<Entity>;
42
- readonly onRemoveEntity: Signal<Entity>;
43
-
44
- private readonly onEarlyUpdateSet = new Set<System>();
45
- private readonly onUpdateSet = new Set<System>();
46
- private readonly onFixedUpdateSet = new Set<System>();
47
- private readonly onPreFixedUpdateSet = new Set<System>();
48
- private readonly onPhysicsUpdateSet = new Set<System>();
49
- private readonly onPrePhysicsUpdateSet = new Set<System>();
50
- private readonly onPostPhysicsUpdateSet = new Set<System>();
51
- private readonly onLateFixedUpdateSet = new Set<System>();
52
- private readonly onLateUpdateSet = new Set<System>();
53
- private readonly onRenderUpdateSet = new Set<System>();
54
- private readonly onAddEntitySet = new Set<System>();
55
- private readonly onRemoveEntitySet = new Set<System>();
56
-
57
- // TODO: for performance, we could store the systems directly in the entity
58
- private readonly entitySystemMap = new Map<Entity, Set<SystemContext>>();
59
-
60
- private readonly serviceClasses = new Set<Class<Service>>();
61
- private readonly services: Service[] = [];
62
-
63
- private framePromise!: Promise<any>;
64
- private resolveFrame: () => void = () => undefined;
65
-
66
- private addQueue: AddEntry[] = [];
67
- private removeQueue: RemoveEntry[] = [];
68
-
69
- private _started = false;
70
-
71
- get started(): boolean { return this._started; }
72
-
73
- private _frameCount = 0;
74
- get frameCount(): number { return this._frameCount; }
75
-
76
- private _fixedFrameCount = 0;
77
- get fixedFrameCount(): number { return this._fixedFrameCount; }
78
-
79
- get numEntities(): number { return this.entitySystemMap.size;}
29
+ readonly id = id++;
30
+ readonly onPrepare: Signal;
31
+ readonly onStart: Signal;
32
+ readonly onEnd: Signal;
33
+ readonly onRender: Signal<OnUpdateParams>;
34
+ readonly onUpdate: Signal<OnUpdateParams>;
35
+ readonly onFixedUpdate: Signal<OnFixedUpdateParams>;
36
+ readonly onPrePhysicsUpdate: Signal<OnFixedUpdateParams>;
37
+ readonly onPhysicsUpdate: Signal<OnFixedUpdateParams>;
38
+ readonly onPostPhysicsUpdate: Signal<OnFixedUpdateParams>;
39
+ readonly onLateFixedUpdate: Signal<OnFixedUpdateParams>;
40
+ readonly onLateUpdate: Signal<OnUpdateParams>;
41
+ readonly onAddEntity: Signal<Entity>;
42
+ readonly onRemoveEntity: Signal<Entity>;
80
43
 
81
- // TODO inject clock into game engine
82
- // TODO inject space into game engine
44
+ private readonly onEarlyUpdateSet = new Set<System>();
45
+ private readonly onUpdateSet = new Set<System>();
46
+ private readonly onFixedUpdateSet = new Set<System>();
47
+ private readonly onPreFixedUpdateSet = new Set<System>();
48
+ private readonly onPhysicsUpdateSet = new Set<System>();
49
+ private readonly onPrePhysicsUpdateSet = new Set<System>();
50
+ private readonly onPostPhysicsUpdateSet = new Set<System>();
51
+ private readonly onLateFixedUpdateSet = new Set<System>();
52
+ private readonly onLateUpdateSet = new Set<System>();
53
+ private readonly onRenderUpdateSet = new Set<System>();
54
+ private readonly onAddEntitySet = new Set<System>();
55
+ private readonly onRemoveEntitySet = new Set<System>();
83
56
 
84
- constructor(
85
- readonly injector: EcsInjector<Class<System>>,
86
- readonly clock: Clock,
87
- ) {
88
- this.injector.map(GameEngine).toValue(this);
89
-
90
- this.onPrepare = this.injector.getSignal(EngineSignals.OnPrepare);
91
- this.onStart = this.injector.getSignal(EngineSignals.OnStart);
92
- this.onEnd = this.injector.getSignal(EngineSignals.OnEnd);
93
- this.onRender = this.injector.getSignal(EngineSignals.OnRender);
94
- this.onFixedUpdate = this.injector.getSignal(EngineSignals.OnFixedUpdate);
95
- this.onUpdate = this.injector.getSignal(EngineSignals.OnUpdate);
96
- this.onLateUpdate = this.injector.getSignal(EngineSignals.OnLateUpdate);
97
- this.onPrePhysicsUpdate = this.injector.getSignal(EngineSignals.OnPrePhysicsUpdate);
98
- this.onPhysicsUpdate = this.injector.getSignal(EngineSignals.OnPhysicsUpdate);
99
- this.onPostPhysicsUpdate = this.injector.getSignal(EngineSignals.OnPostPhysicsUpdate);
100
- this.onLateFixedUpdate = this.injector.getSignal(EngineSignals.onLateFixedUpdate);
101
-
102
- this.onAddEntity = this.injector.getSignal(EngineSignals.OnAddEntity);
103
- this.onRemoveEntity = this.injector.getSignal(EngineSignals.OnRemoveEntity);
104
-
105
- this.setupClock();
106
- this.prepareFrame();
107
- }
57
+ // TODO: for performance, we could store the systems directly in the entity
58
+ private readonly entitySystemMap = new Map<Entity, Set<SystemContext>>();
108
59
 
109
- static createDefault(options?: GameEngineOptions) {
110
- const opts = {...defaultOptions, ...options};
111
- const clock = new GameClock({
112
- fixedDeltaTime: opts.fixedDeltaTime,
113
- autoStart: false,
114
- });
115
- const injector = new EcsInjector<Class<System>>();
116
- const engine = new GameEngine(injector, clock);
117
- engine.installPlugins(opts.plugins);
118
- return engine;
119
- }
60
+ private readonly registeredServices = new Set<Class<Service>>();
61
+ private readonly services: Service[] = [];
62
+ private readonly systemChildInjectors = new Map<object, EcsInjector>();
120
63
 
121
- static createDefaultWithInjector(injector: EcsInjector<Class<System>>, options?: GameEngineOptions) {
122
- const opts = {...defaultOptions, ...options};
123
- const clock = new GameClock({
124
- fixedDeltaTime: opts.fixedDeltaTime,
125
- autoStart: false,
126
- });
127
- const engine = new GameEngine(injector, clock);
128
- engine.installPlugins(opts.plugins);
129
- return engine;
130
- }
64
+ private framePromise!: Promise<any>;
65
+ private resolveFrame: () => void = () => undefined;
131
66
 
132
- addService(service: Service): void {
133
- this.mapAnnotatedSignals(service);
134
- service.onStart && service.onStart();
135
- service.onPreFixedUpdate && this.onPreFixedUpdateSet.add(service);
136
- service.onFixedUpdate && this.onFixedUpdateSet.add(service);
137
- service.onUpdate && this.onUpdateSet.add(service);
138
- service.onLateUpdate && this.onLateUpdateSet.add(service);
139
- service.onPrePhysicsUpdate && this.onPrePhysicsUpdateSet.add(service);
140
- service.onPhysicsUpdate && this.onPhysicsUpdateSet.add(service);
141
- service.onPostPhysicsUpdate && this.onPostPhysicsUpdateSet.add(service);
142
- service.onLateFixedUpdate && this.onLateFixedUpdateSet.add(service);
143
- service.onRender && this.onRenderUpdateSet.add(service);
144
- service.onAddEntity && this.onAddEntitySet.add(service);
145
- service.onRemoveEntity && this.onRemoveEntitySet.add(service);
146
- this.services.push(service);
147
- }
67
+ private addQueue: AddEntry[] = [];
68
+ private removeQueue: RemoveEntry[] = [];
148
69
 
149
- installPlugins(plugins: GameEnginePlugin[]) {
150
- plugins.forEach(plugin => {
151
- plugin.onPrepare && plugin.onPrepare(this);
152
- });
153
- plugins.forEach(plugin => {
154
- plugin.onStart && plugin.onStart(this);
155
- });
156
- }
70
+ private _started = false;
157
71
 
158
- registerSystem(systemClass: Class<System>): void {
159
- this.mapStaticAnnotatedSignals(systemClass);
160
- if (this._started) throw new Error('Register Systems before engine is started');
161
- this.injector.registerSystem(systemClass);
162
- }
72
+ get started(): boolean { return this._started; }
163
73
 
164
- registerService(serviceClass: Class<Service>): void {
165
- this.mapStaticAnnotatedSignals(serviceClass);
166
- if (this._started) throw new Error('Register Services before engine is started');
167
- this.injector.map(serviceClass).toSingleton();
168
- this.serviceClasses.add(serviceClass);
169
- }
74
+ private _frameCount = 0;
75
+ get frameCount(): number { return this._frameCount; }
170
76
 
171
- getService<T extends Class<Service>>(serviceClass: T): InstanceType<T> {
172
- return this.injector.get(serviceClass);
173
- }
77
+ private _fixedFrameCount = 0;
78
+ get fixedFrameCount(): number { return this._fixedFrameCount; }
174
79
 
175
- start() {
176
- this._started = true;
177
- //TODO: throw when registering services or systems when engine is running
178
- for (const serviceClass of this.serviceClasses) {
179
- const service = this.injector.get(serviceClass);
180
- this.addService(service);
181
- }
182
- this.clock.start();
183
- this.onStart.dispatch();
184
- }
80
+ get numEntities(): number { return this.entitySystemMap.size;}
185
81
 
186
- private setupClock() {
187
- this.clock.onPrepare.add(this.prepareFrame, this);
188
-
189
- this.clock.onEarlyUpdate.add(({time, deltaTime}) => {
190
- for (const system of this.onEarlyUpdateSet) {
191
- system.onEarlyUpdate!(time, deltaTime);
192
- }
193
- });
194
-
195
- this.clock.onFixedUpdate.add((params) => {
196
- const {time, deltaTime} = params;
197
- for (const system of this.onPreFixedUpdateSet) {
198
- system.onPreFixedUpdate!(time, deltaTime);
199
- }
200
- for (const system of this.onFixedUpdateSet) {
201
- system.onFixedUpdate!(time, deltaTime);
202
- }
203
- this.onFixedUpdate.dispatch(params);
204
- for (const system of this.onPhysicsUpdateSet) {
205
- system.onPhysicsUpdate!(time, deltaTime);
206
- }
207
- this.onPhysicsUpdate.dispatch(params);
208
- this.onPostPhysicsUpdate.dispatch(params);
209
- for (const system of this.onPostPhysicsUpdateSet) {
210
- system.onPostPhysicsUpdate!(time, deltaTime);
211
- }
212
- this.onLateFixedUpdate.dispatch(params);
213
- for (const system of this.onLateFixedUpdateSet) {
214
- system.onLateFixedUpdate!(time, deltaTime);
215
- }
216
- this._fixedFrameCount++;
217
- });
218
-
219
- // TODO: update from outside
220
- this.clock.onUpdate.add(onUpdateParams => {
221
- const {time, deltaTime, alpha} = onUpdateParams;
222
- for (const system of this.onUpdateSet) {
223
- system.onUpdate!(time, deltaTime, alpha);
224
- }
225
- //TODO: merge with framerate to single signal?
226
-
227
- this.onUpdate.dispatch(onUpdateParams);
228
- for (const system of this.onLateUpdateSet) {
229
- system.onLateUpdate!(time, deltaTime, alpha);
230
- }
231
- this.onLateUpdate.dispatch(onUpdateParams);
232
-
233
- for (const system of this.onRenderUpdateSet) {
234
- system.onRender!(time, deltaTime, alpha);
235
- }
236
- this.onRender.dispatch(onUpdateParams);
237
- this._frameCount++;
238
- });
239
- }
240
82
 
241
- add(entity: Entity) {
242
- return new Promise<void>(resolve => this.addQueue.push([entity, resolve]));
243
- }
244
83
 
245
- waitFrame() {
246
- return this.framePromise;
247
- }
84
+ // TODO inject clock into game engine
85
+ // TODO inject space into game engine
248
86
 
249
- async remove(entity: Entity) {
250
- if ((<any>entity).markRemoval) return;
251
- (<any>entity).markRemoval = true;
252
- return new Promise<void>(resolve => this.removeQueue.push([entity, resolve]));
87
+ constructor(
88
+ readonly injector: EcsInjector<Class<System>>,
89
+ readonly clock: Clock,
90
+ ) {
91
+ this.injector.map(GameEngine).toValue(this);
92
+
93
+ this.onPrepare = this.injector.getSignal(EngineSignals.OnPrepare);
94
+ this.onStart = this.injector.getSignal(EngineSignals.OnStart);
95
+ this.onEnd = this.injector.getSignal(EngineSignals.OnEnd);
96
+ this.onRender = this.injector.getSignal(EngineSignals.OnRender);
97
+ this.onFixedUpdate = this.injector.getSignal(EngineSignals.OnFixedUpdate);
98
+ this.onUpdate = this.injector.getSignal(EngineSignals.OnUpdate);
99
+ this.onLateUpdate = this.injector.getSignal(EngineSignals.OnLateUpdate);
100
+ this.onPrePhysicsUpdate = this.injector.getSignal(EngineSignals.OnPrePhysicsUpdate);
101
+ this.onPhysicsUpdate = this.injector.getSignal(EngineSignals.OnPhysicsUpdate);
102
+ this.onPostPhysicsUpdate = this.injector.getSignal(EngineSignals.OnPostPhysicsUpdate);
103
+ this.onLateFixedUpdate = this.injector.getSignal(EngineSignals.onLateFixedUpdate);
104
+
105
+ this.onAddEntity = this.injector.getSignal(EngineSignals.OnAddEntity);
106
+ this.onRemoveEntity = this.injector.getSignal(EngineSignals.OnRemoveEntity);
107
+
108
+ this.setupClock();
109
+ this.prepareFrame();
110
+ }
111
+
112
+ static createDefault(options?: GameEngineOptions) {
113
+ const opts = {...defaultOptions, ...options};
114
+ const clock = new GameClock({
115
+ fixedDeltaTime: opts.fixedDeltaTime,
116
+ autoStart: false,
117
+ });
118
+ const injector = new EcsInjector<Class<System>>();
119
+ const engine = new GameEngine(injector, clock);
120
+ engine.installPlugins(opts.plugins);
121
+ return engine;
122
+ }
123
+
124
+ static createDefaultWithInjector(injector: EcsInjector<Class<System>>, options?: GameEngineOptions) {
125
+ const opts = {...defaultOptions, ...options};
126
+ const clock = new GameClock({
127
+ fixedDeltaTime: opts.fixedDeltaTime,
128
+ autoStart: false,
129
+ });
130
+ const engine = new GameEngine(injector, clock);
131
+ engine.installPlugins(opts.plugins);
132
+ return engine;
133
+ }
134
+
135
+ // TODO: test
136
+ addServiceClass(serviceClass: Class<Service>, mapping?: (injector: EcsInjector) => void) {
137
+ let childInjector: EcsInjector | undefined;
138
+ if (mapping) {
139
+ childInjector = this.injector.createChild();
140
+ mapping(childInjector);
253
141
  }
254
-
255
- stop() {
256
- // this.injector.dispose();
257
- this.clock.stop();
142
+ this.mapStaticAnnotatedSignals(serviceClass);
143
+ const service = childInjector?.get(serviceClass) || this.injector.get(serviceClass);
144
+ this.addService(service);
145
+ if (childInjector) {
146
+ this.systemChildInjectors.set(service, childInjector);
258
147
  }
259
-
260
- runAction<T extends Action>(action: T): ReturnType<T> {
261
- return action(this);
148
+ return service;
149
+ }
150
+
151
+ private addService(service: Service): void {
152
+ this.mapAnnotatedSignals(service);
153
+ service.onStart && service.onStart();
154
+ service.onPreFixedUpdate && this.onPreFixedUpdateSet.add(service);
155
+ service.onFixedUpdate && this.onFixedUpdateSet.add(service);
156
+ service.onUpdate && this.onUpdateSet.add(service);
157
+ service.onLateUpdate && this.onLateUpdateSet.add(service);
158
+ service.onPrePhysicsUpdate && this.onPrePhysicsUpdateSet.add(service);
159
+ service.onPhysicsUpdate && this.onPhysicsUpdateSet.add(service);
160
+ service.onPostPhysicsUpdate && this.onPostPhysicsUpdateSet.add(service);
161
+ service.onLateFixedUpdate && this.onLateFixedUpdateSet.add(service);
162
+ service.onRender && this.onRenderUpdateSet.add(service);
163
+ service.onAddEntity && this.onAddEntitySet.add(service);
164
+ service.onRemoveEntity && this.onRemoveEntitySet.add(service);
165
+ this.services.push(service);
166
+ }
167
+
168
+ removeService(service: Service): void {
169
+ const index = this.services.indexOf(service);
170
+ if (index === -1) return;
171
+ this.services.splice(index, 1);
172
+ this.unmapAnnotatedSignals(service);
173
+ service.onPreFixedUpdate && this.onPreFixedUpdateSet.delete(service);
174
+ service.onFixedUpdate && this.onFixedUpdateSet.delete(service);
175
+ service.onUpdate && this.onUpdateSet.delete(service);
176
+ service.onLateUpdate && this.onLateUpdateSet.delete(service);
177
+ service.onPrePhysicsUpdate && this.onPrePhysicsUpdateSet.delete(service);
178
+ service.onPhysicsUpdate && this.onPhysicsUpdateSet.delete(service);
179
+ service.onPostPhysicsUpdate && this.onPostPhysicsUpdateSet.delete(service);
180
+ service.onLateFixedUpdate && this.onLateFixedUpdateSet.delete(service);
181
+ service.onRender && this.onRenderUpdateSet.delete(service);
182
+ service.onAddEntity && this.onAddEntitySet.delete(service);
183
+ service.onRemoveEntity && this.onRemoveEntitySet.delete(service);
184
+ service.onEnd && service.onEnd();
185
+ const childInjector = this.systemChildInjectors.get(service);
186
+ if (childInjector) {
187
+ childInjector.dispose();
188
+ this.systemChildInjectors.delete(service);
262
189
  }
263
-
264
- getSignal<T>(signalId: ID): Signal<T> {
265
- return this.injector.getSignal<T>(signalId);
190
+ }
191
+
192
+ installPlugins(plugins: GameEnginePlugin[]) {
193
+ plugins.forEach(plugin => {
194
+ plugin.onPrepare && plugin.onPrepare(this);
195
+ });
196
+ plugins.forEach(plugin => {
197
+ plugin.onStart && plugin.onStart(this);
198
+ });
199
+ }
200
+
201
+ registerSystem(systemClass: Class<System>): void {
202
+ this.mapStaticAnnotatedSignals(systemClass);
203
+ if (this._started) throw new Error('Register Systems before engine is started');
204
+ this.injector.registerSystem(systemClass);
205
+ }
206
+
207
+ registerService(serviceClass: Class<Service>): void {
208
+ this.mapStaticAnnotatedSignals(serviceClass);
209
+ if (this._started) throw new Error('Register Services before engine is started');
210
+ this.injector.map(serviceClass).toSingleton();
211
+ this.registeredServices.add(serviceClass);
212
+ }
213
+
214
+ getService<T extends Class<Service>>(serviceClass: T): InstanceType<T> {
215
+ return this.injector.get(serviceClass);
216
+ }
217
+
218
+ start() {
219
+ this._started = true;
220
+ //TODO: throw when registering services or systems when engine is running
221
+ for (const serviceClass of this.registeredServices) {
222
+ const service = this.injector.get(serviceClass);
223
+ this.addService(service);
266
224
  }
267
-
268
- private signalMappings = new Map<Class, [string, Signal][]>();
269
- private staticSignalMappings = new Map<Class, [string, Signal][]>();
270
- private signalMapBindings = new Map<Object, SignalBinding[]>();
271
-
272
- // TODO: staticSignalMapBindings needed if we want to unregister Services or Systems
273
-
274
- private mapStaticAnnotatedSignals(target: Class) {
275
- let staticSignalMap = this.getStaticSignalMap(target);
276
- if (staticSignalMap.length === 0) return;
277
-
278
- const bindings = [];
279
- for (const [key, signal] of staticSignalMap) {
280
- bindings.push(signal.add((<any>target)[key], target));
281
- }
282
- // TODO: ignore bindings for now (store them if we implement unregister Service or Systems
225
+ this.clock.start();
226
+ this.onStart.dispatch();
227
+ }
228
+
229
+ private setupClock() {
230
+ this.clock.onPrepare.add(this.prepareFrame, this);
231
+
232
+ this.clock.onEarlyUpdate.add(({time, deltaTime}) => {
233
+ for (const system of this.onEarlyUpdateSet) {
234
+ system.onEarlyUpdate!(time, deltaTime);
235
+ }
236
+ });
237
+
238
+ this.clock.onFixedUpdate.add((params) => {
239
+ const {time, deltaTime} = params;
240
+ for (const system of this.onPreFixedUpdateSet) {
241
+ system.onPreFixedUpdate!(time, deltaTime);
242
+ }
243
+ for (const system of this.onFixedUpdateSet) {
244
+ system.onFixedUpdate!(time, deltaTime);
245
+ }
246
+ this.onFixedUpdate.dispatch(params);
247
+ for (const system of this.onPhysicsUpdateSet) {
248
+ system.onPhysicsUpdate!(time, deltaTime);
249
+ }
250
+ this.onPhysicsUpdate.dispatch(params);
251
+ this.onPostPhysicsUpdate.dispatch(params);
252
+ for (const system of this.onPostPhysicsUpdateSet) {
253
+ system.onPostPhysicsUpdate!(time, deltaTime);
254
+ }
255
+ this.onLateFixedUpdate.dispatch(params);
256
+ for (const system of this.onLateFixedUpdateSet) {
257
+ system.onLateFixedUpdate!(time, deltaTime);
258
+ }
259
+ this._fixedFrameCount++;
260
+ });
261
+
262
+ // TODO: update from outside
263
+ this.clock.onUpdate.add(onUpdateParams => {
264
+ const {time, deltaTime, alpha} = onUpdateParams;
265
+ for (const system of this.onUpdateSet) {
266
+ system.onUpdate!(time, deltaTime, alpha);
267
+ }
268
+ //TODO: merge with framerate to single signal?
269
+
270
+ this.onUpdate.dispatch(onUpdateParams);
271
+ for (const system of this.onLateUpdateSet) {
272
+ system.onLateUpdate!(time, deltaTime, alpha);
273
+ }
274
+ this.onLateUpdate.dispatch(onUpdateParams);
275
+
276
+ for (const system of this.onRenderUpdateSet) {
277
+ system.onRender!(time, deltaTime, alpha);
278
+ }
279
+ this.onRender.dispatch(onUpdateParams);
280
+ this._frameCount++;
281
+ });
282
+ }
283
+
284
+ add(entity: Entity) {
285
+ return new Promise<void>(resolve => this.addQueue.push([entity, resolve]));
286
+ }
287
+
288
+ waitFrame() {
289
+ return this.framePromise;
290
+ }
291
+
292
+ async remove(entity: Entity) {
293
+ if ((<any>entity).markRemoval) return;
294
+ (<any>entity).markRemoval = true;
295
+ return new Promise<void>(resolve => this.removeQueue.push([entity, resolve]));
296
+ }
297
+
298
+ stop() {
299
+ // this.injector.dispose();
300
+ this.clock.stop();
301
+ }
302
+
303
+ runAction<T extends Action>(action: T): ReturnType<T> {
304
+ return action(this);
305
+ }
306
+
307
+ getSignal<T>(signalId: ID): Signal<T> {
308
+ return this.injector.getSignal<T>(signalId);
309
+ }
310
+
311
+ private signalMappings = new Map<Class, [string, Signal][]>();
312
+ private staticSignalMappings = new Map<Class, [string, Signal][]>();
313
+ private signalMapBindings = new Map<Object, SignalBinding[]>();
314
+
315
+ // TODO: staticSignalMapBindings needed if we want to unregister Services or Systems
316
+
317
+ private mapStaticAnnotatedSignals(target: Class) {
318
+ let staticSignalMap = this.getStaticSignalMap(target);
319
+ if (staticSignalMap.length === 0) return;
320
+
321
+ const bindings = [];
322
+ for (const [key, signal] of staticSignalMap) {
323
+ bindings.push(signal.add((<any>target)[key], target));
283
324
  }
325
+ // TODO: ignore bindings for now (store them if we implement unregister Service or Systems
326
+ }
284
327
 
285
- private mapAnnotatedSignals(target: Object) {
286
- const signalMap = this.getSignalMap(target.constructor);
287
- if (signalMap.length === 0) return;
328
+ private mapAnnotatedSignals(target: Object) {
329
+ const signalMap = this.getSignalMap(target.constructor);
330
+ if (signalMap.length === 0) return;
288
331
 
289
- const bindings = [];
290
- for (const [key, signal] of signalMap) {
291
- bindings.push(signal.add((<any>target)[key], target));
292
- }
293
- this.signalMapBindings.set(target, bindings);
332
+ const bindings = [];
333
+ for (const [key, signal] of signalMap) {
334
+ bindings.push(signal.add((<any>target)[key], target));
294
335
  }
295
-
296
- private unmapAnnotatedSignals(target: Object) {
297
- const signalBindings = this.signalMapBindings.get(target);
298
- if (!signalBindings) return;
299
- for (const binding of signalBindings) {
300
- binding.detach();
301
- }
336
+ this.signalMapBindings.set(target, bindings);
337
+ }
338
+
339
+ private unmapAnnotatedSignals(target: Object) {
340
+ const signalBindings = this.signalMapBindings.get(target);
341
+ if (!signalBindings) return;
342
+ for (const binding of signalBindings) {
343
+ binding.detach();
302
344
  }
303
-
304
- private getSignalMap(target: Function) {
305
- // TODO: we could speed thinks up by introducing "invisible" flags on the systems/services to avoid a map check
306
- return putIfAbsent(this.signalMappings, target, (): [string, Signal][] => {
307
- const handlers = signalHandlers.get(target);
308
- if (!handlers) return [];
309
- const result: [string, Signal][] = [];
310
- for (const [key, signalId] of handlers) {
311
- result.push([key, this.getSignal(signalId)]);
312
- }
313
- return result;
314
- });
345
+ }
346
+
347
+ private getSignalMap(target: Function) {
348
+ // TODO: we could speed thinks up by introducing "invisible" flags on the systems/services to avoid a map check
349
+ return putIfAbsent(this.signalMappings, target, (): [string, Signal][] => {
350
+ const handlers = signalHandlers.get(target);
351
+ if (!handlers) return [];
352
+ const result: [string, Signal][] = [];
353
+ for (const [key, signalId] of handlers) {
354
+ result.push([key, this.getSignal(signalId)]);
355
+ }
356
+ return result;
357
+ });
358
+ }
359
+
360
+ private getStaticSignalMap(target: Class) {
361
+ // TODO: we could speed thinks up by introducing "invisible" flags on the systems/services to avoid a map check
362
+ return putIfAbsent(this.staticSignalMappings, target, (): [string, Signal][] => {
363
+ const handlers = staticSignalHandlers.get(target);
364
+ if (!handlers) return [];
365
+ const result: [string, Signal][] = [];
366
+ for (const [key, signalId] of handlers) {
367
+ result.push([key, this.getSignal(signalId)]);
368
+ }
369
+ return result;
370
+ });
371
+ }
372
+
373
+ dispose() {
374
+ this.clock.stop();
375
+ this.clock.dispose();
376
+ for (const systems of this.entitySystemMap.values()) {
377
+ for (const system of systems) {
378
+ system.system.onEnd && system.system.onEnd();
379
+ }
315
380
  }
316
-
317
- private getStaticSignalMap(target: Class) {
318
- // TODO: we could speed thinks up by introducing "invisible" flags on the systems/services to avoid a map check
319
- return putIfAbsent(this.staticSignalMappings, target, (): [string, Signal][] => {
320
- const handlers = staticSignalHandlers.get(target);
321
- if (!handlers) return [];
322
- const result: [string, Signal][] = [];
323
- for (const [key, signalId] of handlers) {
324
- result.push([key, this.getSignal(signalId)]);
325
- }
326
- return result;
327
- });
381
+ for (const service of this.services) {
382
+ service.onEnd && service.onEnd();
328
383
  }
329
-
330
- dispose() {
331
- this.clock.stop();
332
- this.clock.dispose();
333
- for (const systems of this.entitySystemMap.values()) {
334
- for (const system of systems) {
335
- system.system.onEnd && system.system.onEnd();
336
- }
384
+ this.onEnd.dispatch();
385
+ }
386
+
387
+ private prepareFrame() {
388
+ for (const [entity, resolve] of this.removeQueue) {
389
+ const entities = entity.getAllEntities();
390
+ for (const entity of entities) {
391
+ (<any>entity).markRemoval = false;
392
+ if (!(<any>entity).gameEngine) {
393
+ console.log('Entity not active', entity);
394
+ // throw new Error('Entity not active');
337
395
  }
338
- for (const service of this.services) {
339
- service.onEnd && service.onEnd();
396
+ (<any>entity).gameEngine = undefined;
397
+
398
+ const systemContexts = this.entitySystemMap.get(entity);
399
+ this.entitySystemMap.delete(entity);
400
+ if (systemContexts) {
401
+ for (const context of systemContexts) {
402
+ this.disposeContext(context);
403
+ }
340
404
  }
341
- this.onEnd.dispatch();
342
- }
405
+ entity.onRemove.dispatch();
406
+ entity.onRemove.detachAll();
407
+ entity._signalMap.forEach(signal => signal.detachAll());
343
408
 
344
- private prepareFrame() {
345
- for (const [entity, resolve] of this.removeQueue) {
346
- const entities = entity.getAllEntities();
347
- for (const entity of entities) {
348
- (<any>entity).markRemoval = false;
349
- if (!(<any>entity).gameEngine) {
350
- console.log('Entity not active', entity);
351
- // throw new Error('Entity not active');
352
- }
353
- (<any>entity).gameEngine = undefined;
354
-
355
- const systemContexts = this.entitySystemMap.get(entity);
356
- this.entitySystemMap.delete(entity);
357
- if (systemContexts) {
358
- for (const context of systemContexts) {
359
- this.disposeContext(context);
360
- }
361
- }
362
- entity.onRemove.dispatch();
363
- entity.onRemove.detachAll();
364
- entity._signalMap.forEach(signal => signal.detachAll());
365
-
366
- for (const system of this.onRemoveEntitySet) {
367
- system.onRemoveEntity!(entity);
368
- }
369
- }
370
-
371
- resolve();
372
- }
373
- this.removeQueue = [];
374
-
375
- for (const [entity, resolve] of this.addQueue) {
376
-
377
- const preparePromises = [];
378
- const nextSystemContexts: SystemContext[] = [];
379
- const entities = entity.getAllEntities();
380
- for (const entity of entities) {
381
- if ((<any>entity).gameEngine) throw new Error('Entity already added to a gameEngine');
382
- (<any>entity).gameEngine = this;
383
- const systemContexts = this.injector.createSystemsForEntity(entity);
384
- for (const context of systemContexts) {
385
- // TODO: implement synced mode where async onPrepares aren't allowed
386
- context.system.onPrepare && preparePromises.push(context.system.onPrepare());
387
- nextSystemContexts.push(context);
388
- }
389
- this.entitySystemMap.set(entity, systemContexts);
390
- }
391
-
392
- const entityWasAdded = () => {
393
- for (const system of this.onAddEntitySet) {
394
- system.onAddEntity!(entity);
395
- }
396
- resolve();
397
- };
398
-
399
- // Promise.all doesnt resolve immediately when there are no promises bu
400
- if (preparePromises.length === 0) {
401
- this.startSystems(nextSystemContexts, entityWasAdded);
402
- } else {
403
- Promise.all(preparePromises).then(() => this.startSystems(nextSystemContexts, entityWasAdded));
404
- }
409
+ for (const system of this.onRemoveEntitySet) {
410
+ system.onRemoveEntity!(entity);
405
411
  }
406
- this.addQueue = [];
407
- // create promise for next frame
408
- this.resolveFrame();
409
- this.framePromise = new Promise<void>(resolve => {
410
- this.resolveFrame = resolve;
411
- });
412
- this.onPrepare.dispatch();
413
- }
412
+ }
414
413
 
415
- private startSystems(contexts: Iterable<SystemContext>, then?: () => void) {
416
- for (const context of contexts) {
417
- const system = context.system;
418
- this.mapAnnotatedSignals(system);
419
- system.onStart && system.onStart();
420
- system.onPreFixedUpdate && this.onPreFixedUpdateSet.add(system);
421
- system.onFixedUpdate && this.onFixedUpdateSet.add(system);
422
- system.onUpdate && this.onUpdateSet.add(system);
423
- system.onLateUpdate && this.onLateUpdateSet.add(system);
424
- system.onPhysicsUpdate && this.onPhysicsUpdateSet.add(system);
425
- system.onPrePhysicsUpdate && this.onPrePhysicsUpdateSet.add(system);
426
- system.onPostPhysicsUpdate && this.onPostPhysicsUpdateSet.add(system);
427
- system.onLateFixedUpdate && this.onLateFixedUpdateSet.add(system);
428
- system.onRender && this.onRenderUpdateSet.add(system);
429
- system.onAddEntity && this.onAddEntitySet.add(system);
430
- system.onRemoveEntity && this.onRemoveEntitySet.add(system);
431
- }
432
- then?.();
433
- };
434
-
435
- private disposeContext(context: SystemContext<System>) {
436
- const system = context.system;
437
-
438
- // if onEnd returns a promise, we need to wait for it to finish before we can dispose the system
439
- const onEndPromise = system.onEnd && system.onEnd();
440
- if (onEndPromise instanceof Promise) {
441
- onEndPromise.then(() => {
442
- context.dispose();
443
- });
444
- } else {
445
- context.dispose();
414
+ resolve();
415
+ }
416
+ this.removeQueue = [];
417
+
418
+ for (const [entity, resolve] of this.addQueue) {
419
+
420
+ const preparePromises = [];
421
+ const nextSystemContexts: SystemContext[] = [];
422
+ const entities = entity.getAllEntities();
423
+ for (const entity of entities) {
424
+ if ((<any>entity).gameEngine) throw new Error('Entity already added to a gameEngine');
425
+ (<any>entity).gameEngine = this;
426
+ const systemContexts = this.injector.createSystemsForEntity(entity);
427
+ for (const context of systemContexts) {
428
+ // TODO: implement synced mode where async onPrepares aren't allowed
429
+ context.system.onPrepare && preparePromises.push(context.system.onPrepare());
430
+ nextSystemContexts.push(context);
446
431
  }
432
+ this.entitySystemMap.set(entity, systemContexts);
433
+ }
447
434
 
448
- this.unmapAnnotatedSignals(system);
449
- system.onPreFixedUpdate && this.onPreFixedUpdateSet.delete(system);
450
- system.onFixedUpdate && this.onFixedUpdateSet.delete(system);
451
- system.onUpdate && this.onUpdateSet.delete(system);
452
- system.onLateUpdate && this.onLateUpdateSet.delete(system);
453
- system.onPhysicsUpdate && this.onPhysicsUpdateSet.delete(system);
454
- system.onPrePhysicsUpdate && this.onPrePhysicsUpdateSet.delete(system);
455
- system.onPostPhysicsUpdate && this.onPostPhysicsUpdateSet.delete(system);
456
- system.onLateFixedUpdate && this.onLateFixedUpdateSet.delete(system);
457
- system.onRender && this.onRenderUpdateSet.delete(system);
435
+ const entityWasAdded = () => {
436
+ for (const system of this.onAddEntitySet) {
437
+ system.onAddEntity!(entity);
438
+ }
439
+ resolve();
440
+ };
441
+
442
+ // Promise.all doesnt resolve immediately when there are no promises bu
443
+ if (preparePromises.length === 0) {
444
+ this.startSystems(nextSystemContexts, entityWasAdded);
445
+ } else {
446
+ Promise.all(preparePromises).then(() => this.startSystems(nextSystemContexts, entityWasAdded));
447
+ }
448
+ }
449
+ this.addQueue = [];
450
+ // create promise for next frame
451
+ this.resolveFrame();
452
+ this.framePromise = new Promise<void>(resolve => {
453
+ this.resolveFrame = resolve;
454
+ });
455
+ this.onPrepare.dispatch();
456
+ }
457
+
458
+ private startSystems(contexts: Iterable<SystemContext>, then?: () => void) {
459
+ for (const context of contexts) {
460
+ const system = context.system;
461
+ this.mapAnnotatedSignals(system);
462
+ system.onStart && system.onStart();
463
+ system.onPreFixedUpdate && this.onPreFixedUpdateSet.add(system);
464
+ system.onFixedUpdate && this.onFixedUpdateSet.add(system);
465
+ system.onUpdate && this.onUpdateSet.add(system);
466
+ system.onLateUpdate && this.onLateUpdateSet.add(system);
467
+ system.onPhysicsUpdate && this.onPhysicsUpdateSet.add(system);
468
+ system.onPrePhysicsUpdate && this.onPrePhysicsUpdateSet.add(system);
469
+ system.onPostPhysicsUpdate && this.onPostPhysicsUpdateSet.add(system);
470
+ system.onLateFixedUpdate && this.onLateFixedUpdateSet.add(system);
471
+ system.onRender && this.onRenderUpdateSet.add(system);
472
+ system.onAddEntity && this.onAddEntitySet.add(system);
473
+ system.onRemoveEntity && this.onRemoveEntitySet.add(system);
458
474
  }
475
+ then?.();
476
+ };
477
+
478
+ private disposeContext(context: SystemContext<System>) {
479
+ const system = context.system;
480
+
481
+ // if onEnd returns a promise, we need to wait for it to finish before we can dispose the system
482
+ const onEndPromise = system.onEnd && system.onEnd();
483
+ if (onEndPromise instanceof Promise) {
484
+ onEndPromise.then(() => {
485
+ context.dispose();
486
+ });
487
+ } else {
488
+ context.dispose();
489
+ }
490
+
491
+ this.unmapAnnotatedSignals(system);
492
+ system.onPreFixedUpdate && this.onPreFixedUpdateSet.delete(system);
493
+ system.onFixedUpdate && this.onFixedUpdateSet.delete(system);
494
+ system.onUpdate && this.onUpdateSet.delete(system);
495
+ system.onLateUpdate && this.onLateUpdateSet.delete(system);
496
+ system.onPhysicsUpdate && this.onPhysicsUpdateSet.delete(system);
497
+ system.onPrePhysicsUpdate && this.onPrePhysicsUpdateSet.delete(system);
498
+ system.onPostPhysicsUpdate && this.onPostPhysicsUpdateSet.delete(system);
499
+ system.onLateFixedUpdate && this.onLateFixedUpdateSet.delete(system);
500
+ system.onRender && this.onRenderUpdateSet.delete(system);
501
+ }
459
502
  }
460
503
  //
461
504
  // type RunSpread<T> = T extends undefined