archetype-ecs-lib 0.6.0 → 0.6.1

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/README.md CHANGED
@@ -55,7 +55,7 @@ world.addSystem((w) => {
55
55
  world.update(1 / 60);
56
56
  ```
57
57
 
58
- > Note: `SystemFn` is typed as `(world: WorldApi, dt) => void`..
58
+ > Note: `SystemFn` is typed as `(world: WorldApi, dt) => void`.
59
59
 
60
60
  ---
61
61
 
@@ -183,61 +183,65 @@ var Schedule = /** @class */ (function () {
183
183
  }
184
184
  var frameStart = worldInstance._profBeginFrame(dt);
185
185
  try {
186
- for (var phases_1 = __values(phases), phases_1_1 = phases_1.next(); !phases_1_1.done; phases_1_1 = phases_1.next()) {
187
- var phase = phases_1_1.value;
188
- var phaseStart = performance.now();
189
- var list = world._scheduleSystems.get(phase);
190
- // Run systems only if they exist for this phase
191
- if (list) {
192
- try {
193
- for (var list_1 = (e_2 = void 0, __values(list)), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
194
- var fn = list_1_1.value;
195
- var sysStart = performance.now();
196
- try {
197
- fn(world, dt);
198
- }
199
- catch (error) {
200
- var sysName = fn.name && fn.name.length > 0 ? fn.name : "<anonymous>";
201
- var msg = error.message !== undefined && typeof error.message === 'string' ?
202
- error.message : JSON.stringify(error);
203
- var e = new Error("[phase=".concat(phase, " system=").concat(sysName, "] ").concat(msg));
204
- e.cause = error;
205
- throw e;
186
+ try {
187
+ for (var phases_1 = __values(phases), phases_1_1 = phases_1.next(); !phases_1_1.done; phases_1_1 = phases_1.next()) {
188
+ var phase = phases_1_1.value;
189
+ var phaseStart = performance.now();
190
+ var list = world._scheduleSystems.get(phase);
191
+ // Run systems only if they exist for this phase
192
+ if (list) {
193
+ try {
194
+ for (var list_1 = (e_2 = void 0, __values(list)), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
195
+ var fn = list_1_1.value;
196
+ var sysStart = performance.now();
197
+ try {
198
+ fn(world, dt);
199
+ }
200
+ catch (error) {
201
+ var sysName = fn.name && fn.name.length > 0 ? fn.name : "<anonymous>";
202
+ var msg = error.message !== undefined && typeof error.message === 'string' ?
203
+ error.message : JSON.stringify(error);
204
+ var e = new Error("[phase=".concat(phase, " system=").concat(sysName, "] ").concat(msg));
205
+ e.cause = error;
206
+ throw e;
207
+ }
208
+ finally {
209
+ var sysName = fn.name && fn.name.length > 0 ? fn.name : "<anonymous>";
210
+ worldInstance._profAddSystem("".concat(phase, ":").concat(sysName), performance.now() - sysStart);
211
+ }
206
212
  }
207
- finally {
208
- var sysName = fn.name && fn.name.length > 0 ? fn.name : "<anonymous>";
209
- worldInstance._profAddSystem("".concat(phase, ":").concat(sysName), performance.now() - sysStart);
213
+ }
214
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
215
+ finally {
216
+ try {
217
+ if (list_1_1 && !list_1_1.done && (_b = list_1.return)) _b.call(list_1);
210
218
  }
219
+ finally { if (e_2) throw e_2.error; }
211
220
  }
212
221
  }
213
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
214
- finally {
215
- try {
216
- if (list_1_1 && !list_1_1.done && (_b = list_1.return)) _b.call(list_1);
222
+ if (this.boundaryMode !== "manual") {
223
+ // apply deferred commands between phases
224
+ if (world.cmd().hasPending()) {
225
+ world.flush();
217
226
  }
218
- finally { if (e_2) throw e_2.error; }
227
+ // deliver events emitted in this phase to the next phase
228
+ world.swapEvents();
219
229
  }
230
+ worldInstance._profAddPhase(phase, performance.now() - phaseStart);
220
231
  }
221
- if (this.boundaryMode !== "manual") {
222
- // apply deferred commands between phases
223
- if (world.cmd().hasPending()) {
224
- world.flush();
225
- }
226
- // deliver events emitted in this phase to the next phase
227
- world.swapEvents();
232
+ }
233
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
234
+ finally {
235
+ try {
236
+ if (phases_1_1 && !phases_1_1.done && (_a = phases_1.return)) _a.call(phases_1);
228
237
  }
229
- worldInstance._profAddPhase(phase, performance.now() - phaseStart);
238
+ finally { if (e_1) throw e_1.error; }
230
239
  }
231
240
  }
232
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
233
241
  finally {
234
- try {
235
- if (phases_1_1 && !phases_1_1.done && (_a = phases_1.return)) _a.call(phases_1);
236
- }
237
- finally { if (e_1) throw e_1.error; }
242
+ worldInstance._profEndFrame(frameStart);
243
+ worldInstance.updateOverlay(worldInstance.stats(), worldInstance.statsHistory());
238
244
  }
239
- worldInstance._profEndFrame(frameStart);
240
- worldInstance.updateOverlay(worldInstance.stats(), worldInstance.statsHistory());
241
245
  };
242
246
  /**
243
247
  * Record a phase ordering constraint `before -> after`.
package/lib/ecs/World.js CHANGED
@@ -271,6 +271,7 @@ var World = /** @class */ (function (_super) {
271
271
  }
272
272
  var frameStart = this._profBeginFrame(dt);
273
273
  this._iterateDepth++;
274
+ var caughtError;
274
275
  try {
275
276
  try {
276
277
  for (var _b = __values(this.systems), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -294,13 +295,25 @@ var World = /** @class */ (function (_super) {
294
295
  finally { if (e_7) throw e_7.error; }
295
296
  }
296
297
  }
298
+ catch (e) {
299
+ caughtError = e;
300
+ }
297
301
  finally {
298
302
  this._iterateDepth--;
299
- this.flush();
303
+ try {
304
+ this.flush();
305
+ }
306
+ catch (e) {
307
+ // System error takes priority; flush error only surfaced when no system threw.
308
+ if (caughtError === undefined)
309
+ caughtError = e;
310
+ }
300
311
  this.swapEvents();
301
312
  this._profAddPhase("update", this._profilingEnabled ? (performance.now() - frameStart) : 0);
302
313
  this._profEndFrame(frameStart);
303
314
  }
315
+ if (caughtError !== undefined)
316
+ throw caughtError;
304
317
  this.updateOverlay(this.stats(), this.statsHistory());
305
318
  };
306
319
  World.prototype.flush = function () {
@@ -668,11 +681,12 @@ var World = /** @class */ (function (_super) {
668
681
  });
669
682
  };
670
683
  World.prototype.query = function () {
684
+ var _a;
671
685
  var ctors = [];
672
686
  for (var _i = 0; _i < arguments.length; _i++) {
673
687
  ctors[_i] = arguments[_i];
674
688
  }
675
- var _a = World._buildQueryTypeIds(ctors), requested = _a.requested, needSorted = _a.needSorted;
689
+ var _b = World._buildQueryTypeIds(ctors), requested = _b.requested, needSorted = _b.needSorted;
676
690
  function gen(world) {
677
691
  var _a, _b, a, cols, i, row, e, out, i, e_16_1;
678
692
  var e_16, _c;
@@ -735,14 +749,17 @@ var World = /** @class */ (function (_super) {
735
749
  }
736
750
  });
737
751
  }
738
- return gen(this);
752
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
753
+ var self = this;
754
+ return _a = {}, _a[Symbol.iterator] = function () { return gen(self); }, _a;
739
755
  };
740
756
  World.prototype.queryTables = function () {
757
+ var _a;
741
758
  var ctors = [];
742
759
  for (var _i = 0; _i < arguments.length; _i++) {
743
760
  ctors[_i] = arguments[_i];
744
761
  }
745
- var _a = World._buildQueryTypeIds(ctors), requested = _a.requested, needSorted = _a.needSorted;
762
+ var _b = World._buildQueryTypeIds(ctors), requested = _b.requested, needSorted = _b.needSorted;
746
763
  function gen(world) {
747
764
  var _a, _b, a, out, i, e_17_1;
748
765
  var e_17, _c;
@@ -795,7 +812,9 @@ var World = /** @class */ (function (_super) {
795
812
  }
796
813
  });
797
814
  }
798
- return gen(this);
815
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
816
+ var self = this;
817
+ return _a = {}, _a[Symbol.iterator] = function () { return gen(self); }, _a;
799
818
  };
800
819
  World.prototype.queryEach = function () {
801
820
  var e_18, _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archetype-ecs-lib",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "An Archetype Entity Component System (AECS)",
5
5
  "main": "./lib/index.js",
6
6
  "scripts": {