@woosh/meep-engine 2.126.68 → 2.126.69

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.126.68",
8
+ "version": "2.126.69",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -26,6 +26,12 @@ export class ObservedMap<K, V> {
26
26
  * @type {Map<K, V>}
27
27
  */
28
28
  data: Map<K_1, V_1>;
29
+ /**
30
+ *
31
+ * @param {K} key
32
+ * @return {boolean}
33
+ */
34
+ has(key: K): boolean;
29
35
  /**
30
36
  *
31
37
  * @param {K} key
@@ -1 +1 @@
1
- {"version":3,"file":"ObservedMap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/ObservedMap.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH;IAeI;;;OAGG;IACH,oCAOC;IAzBD;;OAEG;IACH;QACI;;WAEG;aADO,MAAM;QAGhB;;WAEG;iBADO,MAAM;MAGlB;IAQE;;;OAGG;IACH,oBAAkB;IAGtB;;;;OAIG;IACH,SAHW,CAAC,GACC,CAAC,GAAC,SAAS,CAIvB;IAED;;;;;OAKG;IACH,SAJW,CAAC,SACD,CAAC,yBAQX;IAED;;;;OAIG;IACH,YAHW,CAAC,GACC,OAAO,CAUnB;IAED;;;;OAIG;IACH,iDAEC;IAED;;;OAGG;IACH,mBAEC;CACJ;mBAvFkB,+BAA+B"}
1
+ {"version":3,"file":"ObservedMap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/ObservedMap.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH;IAeI;;;OAGG;IACH,oCAOC;IAzBD;;OAEG;IACH;QACI;;WAEG;aADO,MAAM;QAGhB;;WAEG;iBADO,MAAM;MAGlB;IAQE;;;OAGG;IACH,oBAAkB;IAGtB;;;;OAIG;IACH,SAHW,CAAC,GACA,OAAO,CAIlB;IAED;;;;OAIG;IACH,SAHW,CAAC,GACC,CAAC,GAAC,SAAS,CAIvB;IAED;;;;;OAKG;IACH,SAJW,CAAC,SACD,CAAC,yBAQX;IAED;;;;OAIG;IACH,YAHW,CAAC,GACC,OAAO,CAUnB;IAED;;;;OAIG;IACH,iDAEC;IAED;;;OAGG;IACH,mBAEC;CACJ;mBAhGkB,+BAA+B"}
@@ -32,6 +32,15 @@ export class ObservedMap {
32
32
  this.data = source;
33
33
  }
34
34
 
35
+ /**
36
+ *
37
+ * @param {K} key
38
+ * @return {boolean}
39
+ */
40
+ has(key){
41
+ return this.data.has(key);
42
+ }
43
+
35
44
  /**
36
45
  *
37
46
  * @param {K} key
@@ -1 +1 @@
1
- {"version":3,"file":"AssetManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/asset/AssetManager.js"],"names":[],"mappings":"AA8CA;;;;GAIG;AACH;IAgII;;;;;OAKG;IACH,oCAJW,GAAG,EAYb;IA7ID;;;;OAIG;IACH,eAEG;IAEH;;;OAGG;IACH,aAFU,YAAY,gBAAgB,EAAE,YAAY,CAAC,CAER;IAe7C;;;;;;OAMG;IACH,kBAFU,MAAM,CAEY;IAyB5B;;;;OAIG;IACH,iBAAc;IAEd;;;OAGG;IACH,mBAFU,iBAAiB,CAEiB;IAwE5C,gBAQC;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACL,QAAQ,IAAI,CAAC,CAexB;IAED;;;;;OAKG;IACH,oCAFa,OAAO,CAOnB;IAED;;OAEG;IACH,cAEC;IAED,8BAEC;IAED;;;;;;OAMG;IACH,4DAJW,iBAAiB,GAEf,cAAc,CAY1B;IAED;;;;;;;;;OASG;IACH,qFAsCC;IAED;;;;;OAKG;IACH,aAJW,MAAM,QACN,MAAM,sBAmBhB;IA2QD;;;;;OAKG;IACH,sBA2BC;IAGD;;;;OAIG;IACH,uBAHW,MAAM,GACL,OAAO,CAIlB;IAED;;;;OAIG;IACH,sBAHW,MAAM,GACJ,wBAAY,SAAS,CAMjC;IAaD;;;;OAIG;IACH,+BAHW,MAAM,4CAqBhB;IAED;;;;OAIG;IACH,iCAHW,MAAM,+CAyBhB;IAED;;;;;;OAMG;IACH,6BAJW,MAAM,kCAEJ,QAAQ,OAAO,CAAC,CAU5B;IAED;;;;;OAKG;IACH,0BAJW,MAAM,iEAwChB;IAED;;;OAGG;IACH,uBAFW,MAAM,iBAkBhB;IAED;;;;;;OAMG;IACH,yCAFa,aAAS,IAAI,CAYzB;IAED;;;;;OAKG;IACH,eAJW,MAAM,QACN,MAAM,GACJ,OAAO,CAMnB;IAED;;;;OAIG;IACH,2BAHW,MAAM,GACL,mBAAiB,CAa5B;IAED;;;;OAIG;IACH,oBAHW,MAAM,GACL,gBAAgB,GAAC,SAAS,CAQrC;IAED;;;;;OAKG;IACH,mBAJW,MAAM,QACN,MAAM,QACN,MAAM,QAUhB;IAGL;;;OAGG;IACH,yBAFU,OAAO,CAEoB;;CANpC;4BAn3B2B,0CAA0C;iCAOrC,uBAAuB;6BAM3B,mBAAmB;kCAFd,6BAA6B;kCAD7B,wBAAwB;4BAE9B,0BAA0B"}
1
+ {"version":3,"file":"AssetManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/asset/AssetManager.js"],"names":[],"mappings":"AA8CA;;;;GAIG;AACH;IAgII;;;;;OAKG;IACH,oCAJW,GAAG,EAYb;IA7ID;;;;OAIG;IACH,eAEG;IAEH;;;OAGG;IACH,aAFU,YAAY,gBAAgB,EAAE,YAAY,CAAC,CAER;IAe7C;;;;;;OAMG;IACH,kBAFU,MAAM,CAEY;IAyB5B;;;;OAIG;IACH,iBAAc;IAEd;;;OAGG;IACH,mBAFU,iBAAiB,CAEiB;IAwE5C,gBAQC;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACL,QAAQ,IAAI,CAAC,CAexB;IAED;;;;;OAKG;IACH,oCAFa,OAAO,CAOnB;IAED;;OAEG;IACH,cAEC;IAED,8BAEC;IAED;;;;;;OAMG;IACH,4DAJW,iBAAiB,GAEf,cAAc,CAY1B;IAED;;;;;;;;;OASG;IACH,qFAsCC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,uBAZW,MAAM,QACN,MAAM,gBAEJ,mBAAiB,CA4D7B;IAED;;;;;;;;OAQG;IACH,kBAJW,MAAM,QACN,MAAM,2BAiChB;IA2QD;;;;;OAKG;IACH,sBA2BC;IAGD;;;;OAIG;IACH,uBAHW,MAAM,GACL,OAAO,CAIlB;IAED;;;;OAIG;IACH,sBAHW,MAAM,GACJ,wBAAY,SAAS,CAMjC;IAaD;;;;OAIG;IACH,+BAHW,MAAM,4CAqBhB;IAED;;;;OAIG;IACH,iCAHW,MAAM,+CAyBhB;IAED;;;;;;OAMG;IACH,6BAJW,MAAM,kCAEJ,QAAQ,OAAO,CAAC,CAU5B;IAED;;;;;OAKG;IACH,0BAJW,MAAM,iEAwChB;IAED;;;OAGG;IACH,uBAFW,MAAM,iBAkBhB;IAED;;;;;;OAMG;IACH,yCAFa,aAAS,IAAI,CAYzB;IAED;;;;;OAKG;IACH,eAJW,MAAM,QACN,MAAM,GACJ,OAAO,CAMnB;IAED;;;;OAIG;IACH,2BAHW,MAAM,GACL,mBAAiB,CAa5B;IAED;;;;OAIG;IACH,oBAHW,MAAM,GACL,gBAAgB,GAAC,SAAS,CAQrC;IAED;;;;;OAKG;IACH,mBAJW,MAAM,QACN,MAAM,QACN,MAAM,QAUhB;IAGL;;;OAGG;IACH,yBAFU,OAAO,CAEoB;;CANpC;4BA78B2B,0CAA0C;iCAOrC,uBAAuB;6BAM3B,mBAAmB;kCAFd,6BAA6B;kCAD7B,wBAAwB;4BAE9B,0BAA0B"}
@@ -316,28 +316,118 @@ export class AssetManager {
316
316
  }
317
317
  }
318
318
 
319
+ /**
320
+ * Same as {@link insert}, but will register the asset as pending until loader function resolves.
321
+ *
322
+ * NOTE: {@link AssetTransformer}s are not applied to the asset
323
+ *
324
+ * NOTE: any subsequent normal requests such as {@link get} will be routed to the same loader
325
+ *
326
+ * @template T
327
+ * @param {string} path
328
+ * @param {string} type
329
+ * @param {function(progress?:function(current:number, total:number)):Promise<Asset<T>>} loader
330
+ * @returns {Promise<Asset<T>>} loaded asset
331
+ * @see insert
332
+ * @example
333
+ * manager.insertAsync('path/to/asset', 'my-type', async (progress) => {
334
+ * const asset = await loadAssetFromNetwork('path/to/asset', 'type', progress);
335
+ * return asset;
336
+ * });
337
+ *
338
+ */
339
+ insertAsync(path, type, loader) {
340
+
341
+ const asset_descriptor = new AssetDescription(path, type);
342
+
343
+ if (this.request_map.get(asset_descriptor)) {
344
+ throw new Error(`Asset with path ${path} and type ${type} is already pending`);
345
+ }
346
+
347
+ const pending = new PendingAsset(asset_descriptor);
348
+
349
+ this.request_map.set(asset_descriptor, pending);
350
+
351
+ /**
352
+ *
353
+ * @param {number} current
354
+ * @param {number} total
355
+ */
356
+ const progress = (current, total) => {
357
+ pending.progress.setValue(current);
358
+ pending.progress.setUpperLimit(total);
359
+ };
360
+
361
+ const asset_promise = loader(progress);
362
+
363
+ const cleanup = () => {
364
+ const existing = this.request_map.get(asset_descriptor);
365
+
366
+ if (existing !== pending) {
367
+ // looks like another resolution is pending, this completely invalidates current insersion request
368
+ // Likely reason is that something else was inserted later on
369
+ return false;
370
+ }
371
+
372
+ this.request_map.delete(asset_descriptor);
373
+ return true;
374
+ }
375
+
376
+ return asset_promise.then(asset => {
377
+ if (cleanup()) {
378
+ this.insert(path, type, asset);
379
+
380
+ return asset;
381
+ } else {
382
+ throw new Error(`Race condition. Asset with path ${path} and type ${type} was already resolved somewhere else.`);
383
+ }
384
+ }, error => {
385
+ cleanup();
386
+
387
+ //rethrow
388
+ throw error;
389
+ });
390
+ }
391
+
319
392
  /**
320
393
  * Manually add a fully resolved resource
394
+ * NOTE: {@link AssetTransformer}s are not applied to the asset
395
+ *
396
+ * @template T
321
397
  * @param {string} path
322
398
  * @param {string} type
323
- * @param {Asset} asset
399
+ * @param {Asset<T>} asset
324
400
  */
325
401
  insert(path, type, asset) {
326
402
  assert.isString(path, 'path');
327
403
  assert.isString(type, 'type');
328
404
  assert.isObject(asset, 'asset');
329
405
 
330
- const assetDescription = new AssetDescription(path, type);
406
+ const asset_descritptor = new AssetDescription(path, type);
331
407
 
332
- const existing_resource = this.assets.get(assetDescription);
408
+ const existing_resource = this.assets.get(asset_descritptor);
333
409
 
334
410
  if (existing_resource !== undefined && existing_resource !== asset) {
335
- console.warn(`Another asset under ${assetDescription} already exists and will be replaced`);
411
+ console.warn(`Another asset under ${asset_descritptor} already exists and will be replaced`);
336
412
  }
337
413
 
338
- // TODO check for assets in-flight
414
+ // check for assets in-flight
415
+ const pending = this.request_map.get(asset_descritptor);
416
+ if (pending !== undefined) {
417
+ console.warn(`Asset with path ${path} and type ${type} is already pending, this operation will squash the asset in-flight`);
418
+
419
+ this.request_map.delete(asset_descritptor);
420
+
421
+ const requests = pending.requests;
422
+ const request_count = requests.length;
423
+
424
+ for (let i = 0; i < request_count; i++) {
425
+ const request = requests[i];
426
+ this.#schedule_response(asset, request);
427
+ }
428
+ }
339
429
 
340
- this.assets.set(assetDescription, asset);
430
+ this.assets.set(asset_descritptor, asset);
341
431
  }
342
432
 
343
433
  /**