@woosh/meep-engine 2.131.9 → 2.131.11

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Pure JavaScript game engine. Fully featured and production ready.",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.131.9",
8
+ "version": "2.131.11",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Utility for loading multiple assets together.
3
3
  *
4
+ * NOTE: A pre-loader is not intended to be re-used. You have one collection of assets to be loaded, use one {@link AssetPreloader} instance for it. For another batch - use a separate instance.
5
+ *
4
6
  * @example
5
7
  * const loader = new AssetPreloader();
6
8
  *
@@ -33,9 +35,16 @@ export class AssetPreloader {
33
35
  progress: Signal<any, any, any, any, any, any, any, any>;
34
36
  levelFinished: Signal<any, any, any, any, any, any, any, any>;
35
37
  error: Signal<any, any, any, any, any, any, any, any>;
36
- loadStart: Signal<any, any, any, any, any, any, any, any>;
37
- completed: Signal<any, any, any, any, any, any, any, any>;
38
- resolved: Signal<any, any, any, any, any, any, any, any>;
38
+ started: Signal<any, any, any, any, any, any, any, any>;
39
+ /**
40
+ * @type {Signal<number>}
41
+ */
42
+ completed: Signal<number>;
43
+ /**
44
+ * All assets are processed, even if some have errored out
45
+ * @type {Signal<number,number>}
46
+ */
47
+ resolved: Signal<number, number>;
39
48
  };
40
49
  /**
41
50
  *
@@ -1 +1 @@
1
- {"version":3,"file":"AssetPreloader.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/preloader/AssetPreloader.js"],"names":[],"mappings":"AAqDA;;;;;;;;;;;;;;;GAeG;AACH;IACI;;;OAGG;IACH,iBAFU,MAAM,CAEI;IAEpB;;;OAGG;IACH,iBAFU,aAAa,EAAE,EAAE,CAEf;IAEZ;;OAEG;IACH;;;;;;;;MAQE;IAaF;;;;;;;OAOG;IACH,SANW,MAAM,QACN,MAAM,UACN,MAAM,aACN,MAAM,GACL,cAAc,CAqCzB;IAED;;;OAGG;IACH,aAFW;QAAC,GAAG,EAAC,MAAM,CAAC;QAAC,IAAI,EAAC,MAAM,CAAC;QAAC,KAAK,CAAC,EAAC,MAAM,CAAA;KAAC,EAAE,QAQpD;IAED;;;;OAIG;IACH,kCAFY,cAAc,CAyHzB;CACJ;AAED;;;GAGG;AACH,wBAFU,cAAc,CAEgB;AAjSxC;;GAEG;AACH;IA+BI;;;;OAIG;IACH,4BAFY,aAAa,CAQxB;IAxCG;;;OAGG;IACH,YAAe;IACf;;;OAGG;IACH,aAAgB;IAChB;;;OAGG;IACH,OAFU,MAAM,GAAC,UAAU,CAEK;IAChC;;;OAGG;IACH,UAFU,MAAM,CAEC;IAGrB;;;;;aAKC;CAcJ;mBAlDkB,uCAAuC;uBAEnC,iBAAiB"}
1
+ {"version":3,"file":"AssetPreloader.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/preloader/AssetPreloader.js"],"names":[],"mappings":"AAsDA;;;;;;;;;;;;;;;;;GAiBG;AACH;IACI;;;OAGG;IACH,iBAFU,MAAM,CAEI;IAEpB;;;OAGG;IACH,iBAFU,aAAa,EAAE,EAAE,CAEf;IAEZ;;OAEG;IACH;;;;;;QAMI;;WAEG;mBADO,OAAO,MAAM,CAAC;QAGxB;;;WAGG;kBADO,OAAO,MAAM,EAAC,MAAM,CAAC;MAGjC;IAaF;;;;;;;OAOG;IACH,SANW,MAAM,QACN,MAAM,UACN,MAAM,aACN,MAAM,GACL,cAAc,CAqCzB;IAED;;;OAGG;IACH,aAFW;QAAC,GAAG,EAAC,MAAM,CAAC;QAAC,IAAI,EAAC,MAAM,CAAC;QAAC,KAAK,CAAC,EAAC,MAAM,CAAA;KAAC,EAAE,QAQpD;IAED;;;;OAIG;IACH,kCAFY,cAAc,CA+JzB;CACJ;AAED;;;GAGG;AACH,wBAFU,cAAc,CAEgB;AAhVxC;;GAEG;AACH;IA+BI;;;;OAIG;IACH,4BAFY,aAAa,CAQxB;IAxCG;;;OAGG;IACH,YAAe;IACf;;;OAGG;IACH,aAAgB;IAChB;;;OAGG;IACH,OAFU,MAAM,GAAC,UAAU,CAEK;IAChC;;;OAGG;IACH,UAFU,MAAM,CAEC;IAGrB;;;;;aAKC;CAcJ;mBAlDkB,uCAAuC;uBAEnC,iBAAiB"}
@@ -1,4 +1,5 @@
1
1
  import { assert } from "../../../core/assert.js";
2
+ import { array_push_if_unique } from "../../../core/collection/array/array_push_if_unique.js";
2
3
  import Signal from "../../../core/events/signal/Signal.js";
3
4
  import { clamp01 } from "../../../core/math/clamp01.js";
4
5
  import AssetLevel from "./AssetLevel.js";
@@ -54,6 +55,8 @@ class AssetLoadSpec {
54
55
  /**
55
56
  * Utility for loading multiple assets together.
56
57
  *
58
+ * NOTE: A pre-loader is not intended to be re-used. You have one collection of assets to be loaded, use one {@link AssetPreloader} instance for it. For another batch - use a separate instance.
59
+ *
57
60
  * @example
58
61
  * const loader = new AssetPreloader();
59
62
  *
@@ -88,8 +91,15 @@ export class AssetPreloader {
88
91
  progress: new Signal(),
89
92
  levelFinished: new Signal(),
90
93
  error: new Signal(),
91
- loadStart: new Signal(),
94
+ started: new Signal(),
95
+ /**
96
+ * @type {Signal<number>}
97
+ */
92
98
  completed: new Signal(),
99
+ /**
100
+ * All assets are processed, even if some have errored out
101
+ * @type {Signal<number,number>}
102
+ */
93
103
  resolved: new Signal(),
94
104
  };
95
105
 
@@ -167,6 +177,9 @@ export class AssetPreloader {
167
177
  * @return {AssetPreloader}
168
178
  */
169
179
  load(assetManager) {
180
+ assert.defined(assetManager, 'assetManager');
181
+ assert.equal(assetManager.isAssetManager, true, 'assetManager.isAssetManager !== true');
182
+
170
183
  const on = this.on;
171
184
 
172
185
  //current level being processed
@@ -180,15 +193,41 @@ export class AssetPreloader {
180
193
  };
181
194
  });
182
195
 
183
- on.loadStart.send1(initEvent);
196
+ on.started.send1(initEvent);
184
197
  const numAssets = this.totalAssetCount;
198
+
185
199
  let numAssetsLoaded = 0;
200
+ let numAssetsFailed = 0;
201
+
202
+ let finished = false;
203
+
204
+ function try_finish() {
205
+ if (finished) {
206
+ // already done
207
+ return;
208
+ }
209
+
210
+ const totalProcessed = numAssetsLoaded + numAssetsFailed;
211
+
212
+ if (totalProcessed <= numAssets) {
213
+ // not done yet
214
+ return;
215
+ }
216
+
217
+ if (numAssetsFailed === 0) {
218
+ on.completed.send1(numAssetsLoaded);
219
+ }
220
+
221
+ on.resolved.send2(numAssetsLoaded, numAssetsFailed);
222
+
223
+ finished = true;
224
+ }
186
225
 
187
226
  /**
188
227
  * submit requests in batches in order of importance
189
228
  * @param {number} level
190
229
  */
191
- function loadBatch(level) {
230
+ function load_level(level) {
192
231
  // filter out assets of the specified level
193
232
  const batch = assets[level];
194
233
 
@@ -232,10 +271,14 @@ export class AssetPreloader {
232
271
  on.levelFinished.dispatch(level);
233
272
  }
234
273
 
274
+ try_finish();
235
275
  }
236
276
 
237
277
  function assetLoadFailed(e) {
278
+ numAssetsFailed++;
238
279
  on.error.dispatch(e);
280
+
281
+ try_finish();
239
282
  }
240
283
 
241
284
  //sort batch by priority
@@ -243,7 +286,7 @@ export class AssetPreloader {
243
286
  return b.priotity - a.priotity;
244
287
  });
245
288
 
246
- batch.forEach(function (def) {
289
+ for (const def of batch) {
247
290
 
248
291
  assetManager.get({
249
292
  path: def.uri,
@@ -252,14 +295,17 @@ export class AssetPreloader {
252
295
  failure: assetLoadFailed
253
296
  });
254
297
 
255
- });
298
+ }
256
299
  }
257
300
 
301
+ /**
302
+ *
303
+ * @type {number[]}
304
+ */
258
305
  const levels = [];
306
+
259
307
  for (let level in assets) {
260
- if (assets.hasOwnProperty(level)) {
261
- levels.push(level);
262
- }
308
+ array_push_if_unique(levels, level);
263
309
  }
264
310
 
265
311
  let lastLoadedLevel = 0;
@@ -268,16 +314,18 @@ export class AssetPreloader {
268
314
 
269
315
  if (lastLoadedLevel < levels.length) {
270
316
 
317
+ // load next
318
+
271
319
  const levelToLoad = lastLoadedLevel;
272
320
  lastLoadedLevel++;
273
321
  on.levelFinished.addOne(prod);
274
322
 
275
- //console.log('requesting load of level ',levelToLoad);
276
-
277
- loadBatch(levelToLoad);
323
+ load_level(levelToLoad);
278
324
 
279
325
  } else {
280
- on.completed.send0();
326
+
327
+ // we're done
328
+
281
329
  }
282
330
 
283
331
  }