@codehz/ecs 0.1.7 → 0.1.8

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.
package/index.js CHANGED
@@ -656,6 +656,24 @@ class SystemScheduler {
656
656
  this.cachedExecutionOrder = result;
657
657
  return result;
658
658
  }
659
+ update(...params) {
660
+ const executionOrder = this.getExecutionOrder();
661
+ const systemPromises = new Map;
662
+ for (const system of executionOrder) {
663
+ const deps = Array.from(this.systemDependencies.get(system) || []);
664
+ const depPromises = deps.map((dep) => systemPromises.get(dep)).filter(Boolean);
665
+ if (depPromises.length > 0) {
666
+ const promise = Promise.all(depPromises).then(() => system.update(...params));
667
+ systemPromises.set(system, promise);
668
+ } else {
669
+ const result = system.update(...params);
670
+ if (result instanceof Promise) {
671
+ systemPromises.set(system, result);
672
+ }
673
+ }
674
+ }
675
+ return Promise.all(systemPromises.values());
676
+ }
659
677
  clear() {
660
678
  this.systems.clear();
661
679
  this.cachedExecutionOrder = null;
@@ -825,11 +843,12 @@ class World {
825
843
  this.exclusiveComponents.add(componentId);
826
844
  }
827
845
  update(...params) {
828
- const systems = this.systemScheduler.getExecutionOrder();
829
- for (const system of systems) {
830
- system.update(...params);
846
+ const result = this.systemScheduler.update(...params);
847
+ if (result instanceof Promise) {
848
+ return result.then(() => this.commandBuffer.execute());
849
+ } else {
850
+ this.commandBuffer.execute();
831
851
  }
832
- this.commandBuffer.execute();
833
852
  }
834
853
  sync() {
835
854
  this.commandBuffer.execute();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codehz/ecs",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -2,7 +2,7 @@ import type { System } from "./system";
2
2
  /**
3
3
  * System Scheduler for managing system dependencies and execution order
4
4
  */
5
- export declare class SystemScheduler<UpdateParams extends any[] = [deltaTime: number]> {
5
+ export declare class SystemScheduler<UpdateParams extends any[] = []> {
6
6
  private systems;
7
7
  private systemDependencies;
8
8
  private cachedExecutionOrder;
@@ -17,6 +17,7 @@ export declare class SystemScheduler<UpdateParams extends any[] = [deltaTime: nu
17
17
  * Uses topological sort
18
18
  */
19
19
  getExecutionOrder(): System<UpdateParams>[];
20
+ update(...params: UpdateParams): Promise<void[]> | void;
20
21
  /**
21
22
  * Clear all systems and dependencies
22
23
  */
package/system.d.ts CHANGED
@@ -5,7 +5,7 @@ export interface System<UpdateParams extends any[] = []> {
5
5
  /**
6
6
  * Update the system
7
7
  */
8
- update(...params: UpdateParams): void;
8
+ update(...params: UpdateParams): void | Promise<void>;
9
9
  /**
10
10
  * Dependencies of this system (systems that must run before this one)
11
11
  */
package/world.d.ts CHANGED
@@ -110,8 +110,10 @@ export declare class World<UpdateParams extends any[] = []> {
110
110
  setExclusive(componentId: EntityId): void;
111
111
  /**
112
112
  * Update the world (run all systems in dependency order)
113
+ * This function is synchronous when all systems are synchronous,
114
+ * and asynchronous (returns a Promise) when any system is asynchronous.
113
115
  */
114
- update(...params: UpdateParams): void;
116
+ update(...params: UpdateParams): Promise<void> | void;
115
117
  /**
116
118
  * Execute all deferred commands immediately without running systems
117
119
  */