@woosh/meep-engine 2.126.68 → 2.126.71
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.
|
|
8
|
+
"version": "2.126.71",
|
|
9
9
|
"main": "build/meep.module.js",
|
|
10
10
|
"module": "build/meep.module.js",
|
|
11
11
|
"exports": {
|
|
@@ -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;
|
|
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"}
|
|
@@ -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
|
|
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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|
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Checks if an asset is currently being loaded.
|
|
321
|
+
* Useful for avoiding redundant requests.
|
|
322
|
+
*
|
|
323
|
+
* @param {string} path
|
|
324
|
+
* @param {string} type
|
|
325
|
+
* @return {boolean}
|
|
326
|
+
*/
|
|
327
|
+
isPending(path, type) {
|
|
328
|
+
const assetDescription = new AssetDescription(path, type);
|
|
329
|
+
return this.request_map.has(assetDescription);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Same as {@link insert}, but will register the asset as pending until loader function resolves.
|
|
334
|
+
*
|
|
335
|
+
* NOTE: {@link AssetTransformer}s are not applied to the asset
|
|
336
|
+
*
|
|
337
|
+
* NOTE: any subsequent normal requests such as {@link get} will be routed to the same loader
|
|
338
|
+
*
|
|
339
|
+
* @template T
|
|
340
|
+
* @param {string} path
|
|
341
|
+
* @param {string} type
|
|
342
|
+
* @param {function(progress?:function(current:number, total:number)):Promise<Asset<T>>} loader
|
|
343
|
+
* @returns {Promise<Asset<T>>} loaded asset
|
|
344
|
+
* @see insert
|
|
345
|
+
* @example
|
|
346
|
+
* manager.insertAsync('path/to/asset', 'my-type', async (progress) => {
|
|
347
|
+
* const asset = await loadAssetFromNetwork('path/to/asset', 'type', progress);
|
|
348
|
+
* return asset;
|
|
349
|
+
* });
|
|
350
|
+
*
|
|
351
|
+
*/
|
|
352
|
+
insertAsync(path, type, loader) {
|
|
353
|
+
|
|
354
|
+
const asset_descriptor = new AssetDescription(path, type);
|
|
355
|
+
|
|
356
|
+
if (this.request_map.get(asset_descriptor)) {
|
|
357
|
+
throw new Error(`Asset with path '${path}' and type '${type}' is already pending`);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const pending = new PendingAsset(asset_descriptor);
|
|
361
|
+
|
|
362
|
+
this.request_map.set(asset_descriptor, pending);
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
*
|
|
366
|
+
* @param {number} current
|
|
367
|
+
* @param {number} total
|
|
368
|
+
*/
|
|
369
|
+
const progress = (current, total) => {
|
|
370
|
+
pending.progress.setValue(current);
|
|
371
|
+
pending.progress.setUpperLimit(total);
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
const asset_promise = loader(progress);
|
|
375
|
+
|
|
376
|
+
const cleanup = () => {
|
|
377
|
+
const existing = this.request_map.get(asset_descriptor);
|
|
378
|
+
|
|
379
|
+
if (existing !== pending) {
|
|
380
|
+
// looks like another resolution is pending, this completely invalidates current insersion request
|
|
381
|
+
// Likely reason is that something else was inserted later on
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
this.request_map.delete(asset_descriptor);
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return asset_promise.then(asset => {
|
|
390
|
+
if (cleanup()) {
|
|
391
|
+
this.insert(path, type, asset);
|
|
392
|
+
|
|
393
|
+
return asset;
|
|
394
|
+
} else {
|
|
395
|
+
throw new Error(`Race condition. Asset with path '${path}' and type '${type}' was already resolved somewhere else.`);
|
|
396
|
+
}
|
|
397
|
+
}, error => {
|
|
398
|
+
cleanup();
|
|
399
|
+
|
|
400
|
+
//rethrow
|
|
401
|
+
throw error;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
319
405
|
/**
|
|
320
406
|
* Manually add a fully resolved resource
|
|
407
|
+
* NOTE: {@link AssetTransformer}s are not applied to the asset
|
|
408
|
+
*
|
|
409
|
+
* @template T
|
|
321
410
|
* @param {string} path
|
|
322
411
|
* @param {string} type
|
|
323
|
-
* @param {Asset} asset
|
|
412
|
+
* @param {Asset<T>} asset
|
|
324
413
|
*/
|
|
325
414
|
insert(path, type, asset) {
|
|
326
415
|
assert.isString(path, 'path');
|
|
327
416
|
assert.isString(type, 'type');
|
|
328
417
|
assert.isObject(asset, 'asset');
|
|
329
418
|
|
|
330
|
-
const
|
|
419
|
+
const asset_descritptor = new AssetDescription(path, type);
|
|
331
420
|
|
|
332
|
-
const existing_resource = this.assets.get(
|
|
421
|
+
const existing_resource = this.assets.get(asset_descritptor);
|
|
333
422
|
|
|
334
423
|
if (existing_resource !== undefined && existing_resource !== asset) {
|
|
335
|
-
console.warn(`Another asset under ${
|
|
424
|
+
console.warn(`Another asset under ${asset_descritptor} already exists and will be replaced`);
|
|
336
425
|
}
|
|
337
426
|
|
|
338
|
-
//
|
|
427
|
+
// check for assets in-flight
|
|
428
|
+
const pending = this.request_map.get(asset_descritptor);
|
|
429
|
+
if (pending !== undefined) {
|
|
430
|
+
console.warn(`Asset with path '${path}' and type '${type}' is already pending, this operation will squash the asset in-flight`);
|
|
431
|
+
|
|
432
|
+
this.request_map.delete(asset_descritptor);
|
|
433
|
+
|
|
434
|
+
const requests = pending.requests;
|
|
435
|
+
const request_count = requests.length;
|
|
436
|
+
|
|
437
|
+
for (let i = 0; i < request_count; i++) {
|
|
438
|
+
const request = requests[i];
|
|
439
|
+
this.#schedule_response(asset, request);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
339
442
|
|
|
340
|
-
this.assets.set(
|
|
443
|
+
this.assets.set(asset_descritptor, asset);
|
|
341
444
|
}
|
|
342
445
|
|
|
343
446
|
/**
|