@woosh/meep-engine 2.131.5 → 2.131.7
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 +1 -1
- package/src/core/math/physics/mie/compute_lorenz_mie_optical_properties.d.ts.map +1 -1
- package/src/core/math/physics/mie/compute_lorenz_mie_optical_properties.js +0 -3
- package/src/core/math/physics/mie/lorenz_mie_coefs.d.ts +1 -2
- package/src/core/math/physics/mie/lorenz_mie_coefs.d.ts.map +1 -1
- package/src/core/math/physics/mie/lorenz_mie_coefs.js +1 -2
- package/src/core/model/node-graph/node/NodeInstance.d.ts +2 -0
- package/src/core/model/node-graph/node/NodeInstance.d.ts.map +1 -1
- package/src/core/model/node-graph/node/NodeInstance.js +11 -5
- package/src/engine/Engine.d.ts.map +1 -0
- package/src/engine/Engine.js +2 -2
- package/src/engine/asset/preloader/AssetLevel.d.ts +5 -0
- package/src/engine/asset/preloader/AssetLevel.d.ts.map +1 -1
- package/src/engine/asset/preloader/AssetLevel.js +6 -0
- package/src/engine/asset/preloader/AssetPreloader.d.ts +109 -0
- package/src/engine/asset/preloader/AssetPreloader.d.ts.map +1 -0
- package/src/engine/asset/preloader/AssetPreloader.js +289 -0
- package/src/engine/asset/preloader/Preloader.d.ts +0 -7
- package/src/engine/asset/preloader/Preloader.d.ts.map +0 -1
- package/src/engine/asset/preloader/Preloader.js +0 -189
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.
|
|
8
|
+
"version": "2.131.7",
|
|
9
9
|
"main": "build/meep.module.js",
|
|
10
10
|
"module": "build/meep.module.js",
|
|
11
11
|
"exports": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compute_lorenz_mie_optical_properties.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/physics/mie/compute_lorenz_mie_optical_properties.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compute_lorenz_mie_optical_properties.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/physics/mie/compute_lorenz_mie_optical_properties.js"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,kEALW,MAAM,UACN,MAAM,OACN,MAAM,EAAE,SACR,MAAM,EAAE,OAWlB"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { lorenz_mie_coefs } from "./lorenz_mie_coefs.js";
|
|
2
2
|
import { mie_ab_to_optical_properties } from "./mie_ab_to_optical_properties.js";
|
|
3
3
|
|
|
4
|
-
// Complex number operations
|
|
5
|
-
|
|
6
|
-
|
|
7
4
|
/**
|
|
8
5
|
* For refractive index, the imaginary part controls the absorption coefficient.
|
|
9
6
|
* For non-absorbing media, such as pure water - this will be 0.
|
|
@@ -5,8 +5,7 @@ export function cdiv(a: any, b: any): Float64Array;
|
|
|
5
5
|
/**
|
|
6
6
|
* The following source code implements Lorenz-Mie theory using the formulas presented in the SIGGRAPH 2007 paper
|
|
7
7
|
*
|
|
8
|
-
* Computing the Scattering Properties of Participating
|
|
9
|
-
* Media Using Lorenz-Mie Theory
|
|
8
|
+
* "Computing the Scattering Properties of Participating Media Using Lorenz-Mie Theory"
|
|
10
9
|
*
|
|
11
10
|
* By authors: Jeppe Revall Frisvad
|
|
12
11
|
* Niels Joergen Christensen
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lorenz_mie_coefs.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/physics/mie/lorenz_mie_coefs.js"],"names":[],"mappings":"AAOA,mDAEC;AAMD,mDAMC;AAWD,oDAOC;AAED,mDAOC;AA8GD
|
|
1
|
+
{"version":3,"file":"lorenz_mie_coefs.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/physics/mie/lorenz_mie_coefs.js"],"names":[],"mappings":"AAOA,mDAEC;AAMD,mDAMC;AAWD,oDAOC;AAED,mDAOC;AA8GD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,+CALW,MAAM,YADN,MAAM,yCAIJ,YAAY,CAqDxB"}
|
|
@@ -159,8 +159,7 @@ function LorenzMie_ab(n, size, n_p, n_med, A_p, A_med, old_B, old_R, old_psi_zet
|
|
|
159
159
|
/**
|
|
160
160
|
* The following source code implements Lorenz-Mie theory using the formulas presented in the SIGGRAPH 2007 paper
|
|
161
161
|
*
|
|
162
|
-
* Computing the Scattering Properties of Participating
|
|
163
|
-
* Media Using Lorenz-Mie Theory
|
|
162
|
+
* "Computing the Scattering Properties of Participating Media Using Lorenz-Mie Theory"
|
|
164
163
|
*
|
|
165
164
|
* By authors: Jeppe Revall Frisvad
|
|
166
165
|
* Niels Joergen Christensen
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeInstance.d.ts","sourceRoot":"","sources":["../../../../../../src/core/model/node-graph/node/NodeInstance.js"],"names":[],"mappings":"AAcA;;;;GAIG;AACH;IAEI;;;;OAIG;IACH,aAFU,MAAM,CAEE;IAElB;;;OAGG;IACH,6BAAmB;IAEnB;;;OAGG;IACH,WAFU,yBAAyB,EAAE,CAEtB;IAEf;;;OAGG;IACH,gBAAgB;IAEhB;;;OAGG;IACH,qBAAmB;IAEnB;;;OAGG;IACH,sBAFU,gBAAgB,CAED;IAEzB;;;;;;OAMG;IACH,wBAFU,MAAM,CAEE;IAElB;;OAEG;IACH;QACI;;;WAGG;mCADO,OAAO,MAAM,WAAO;QAG9B;;;WAGG;iCADO,OAAO,MAAM,MAAI;QAG3B;;;WAGG;mCADO,OAAO,MAAM,MAAI;QAI3B;;;;WAIG;qCADO,yCAAyC,YAAY,CAAC;MAGlE;IAEF;;;;;;OAMG;IACH,8BALW,MAAM,aACN,aAAa,UACb,YAAY,GACV,MAAM,CAsBlB;IAED;;;OAGG;IACH,gDAEC;IAED;;;OAGG;IACH,+CAEC;IAGD;;;OAGG;IACH,mCAEC;IAED;;;;OAIG;IACH,kCAEC;IAED;;;;OAIG;IACH,mBAHW,MAAM,oBAKhB;IAED;;;;OAIG;IACH,mBAHW,MAAM,OAKhB;IAED;;;;OAIG;IACH,yBAHW,MAAM,KAOhB;IAED;;;;OAIG;IACH,2BAHW,MAAM,oBAmChB;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,OAAO,CAInB;IAED;;;;OAIG;IACH,oBAHW,MAAM,GACJ,OAAO,CAkBnB;IAED;;;OAGG;IACH,uCAQC;IAED,wBAIC;IAED;;;OAGG;IACH,mDAoCC;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACJ,yBAAyB,GAAC,SAAS,CAoB/C;IAED;;;;OAIG;IACH,6BAHW,MAAM,GACJ,SAAS,GAAC,yBAAyB,
|
|
1
|
+
{"version":3,"file":"NodeInstance.d.ts","sourceRoot":"","sources":["../../../../../../src/core/model/node-graph/node/NodeInstance.js"],"names":[],"mappings":"AAcA;;;;GAIG;AACH;IAEI;;;;OAIG;IACH,aAFU,MAAM,CAEE;IAElB;;;OAGG;IACH,6BAAmB;IAEnB;;;OAGG;IACH,WAFU,yBAAyB,EAAE,CAEtB;IAEf;;;OAGG;IACH,gBAAgB;IAEhB;;;OAGG;IACH,qBAAmB;IAEnB;;;OAGG;IACH,sBAFU,gBAAgB,CAED;IAEzB;;;;;;OAMG;IACH,wBAFU,MAAM,CAEE;IAElB;;OAEG;IACH;QACI;;;WAGG;mCADO,OAAO,MAAM,WAAO;QAG9B;;;WAGG;iCADO,OAAO,MAAM,MAAI;QAG3B;;;WAGG;mCADO,OAAO,MAAM,MAAI;QAI3B;;;;WAIG;qCADO,yCAAyC,YAAY,CAAC;MAGlE;IAEF;;;;;;OAMG;IACH,8BALW,MAAM,aACN,aAAa,UACb,YAAY,GACV,MAAM,CAsBlB;IAED;;;OAGG;IACH,gDAEC;IAED;;;OAGG;IACH,+CAEC;IAGD;;;OAGG;IACH,mCAEC;IAED;;;;OAIG;IACH,kCAEC;IAED;;;;OAIG;IACH,mBAHW,MAAM,oBAKhB;IAED;;;;OAIG;IACH,mBAHW,MAAM,OAKhB;IAED;;;;OAIG;IACH,yBAHW,MAAM,KAOhB;IAED;;;;OAIG;IACH,2BAHW,MAAM,oBAmChB;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,OAAO,CAInB;IAED;;;;OAIG;IACH,oBAHW,MAAM,GACJ,OAAO,CAkBnB;IAED;;;OAGG;IACH,uCAQC;IAED,wBAIC;IAED;;;OAGG;IACH,mDAoCC;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACJ,yBAAyB,GAAC,SAAS,CAoB/C;IAED;;;;OAIG;IACH,6BAHW,MAAM,GACJ,SAAS,GAAC,yBAAyB,CAmB/C;IAED;;;OAGG;IACH,QAFY,MAAM,CAIjB;IAED;;;;OAIG;IACH,cAHW,YAAY,GACV,OAAO,CAQnB;IAED,mBAYC;IAIL;;;OAGG;IACH,yBAFU,OAAO,CAEoB;CAPpC;0CA9YyC,gCAAgC;iBAHzD,kCAAkC;mBAChC,kCAAkC;8BAGvB,oBAAoB"}
|
|
@@ -351,13 +351,19 @@ export class NodeInstance {
|
|
|
351
351
|
getFirstEndpointByName(name) {
|
|
352
352
|
assert.isString(name, 'name');
|
|
353
353
|
|
|
354
|
-
const
|
|
354
|
+
const endpoints = this.endpoints;
|
|
355
|
+
const endpoint_count = endpoints.length;
|
|
356
|
+
|
|
357
|
+
for (let i = 0; i < endpoint_count; i++) {
|
|
358
|
+
const ref = endpoints[i];
|
|
355
359
|
|
|
356
|
-
|
|
357
|
-
|
|
360
|
+
if (ref.port.name === name) {
|
|
361
|
+
return ref;
|
|
362
|
+
}
|
|
358
363
|
}
|
|
359
364
|
|
|
360
|
-
|
|
365
|
+
// not found
|
|
366
|
+
return undefined;
|
|
361
367
|
|
|
362
368
|
}
|
|
363
369
|
|
|
@@ -387,7 +393,7 @@ export class NodeInstance {
|
|
|
387
393
|
|
|
388
394
|
// add description
|
|
389
395
|
const d = this.description;
|
|
390
|
-
if(d !== undefined && d !== null){
|
|
396
|
+
if (d !== undefined && d !== null) {
|
|
391
397
|
result += `, description = ${d.id}(${d.name})`
|
|
392
398
|
}
|
|
393
399
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Engine.d.ts","sourceRoot":"","sources":["../../../src/engine/Engine.js"],"names":[],"mappings":";AA6CA;IAqCI;;;;;;;;OAQG;IACH,8FANW,aAAa,EAoOvB;IAzQD,qBAA4B;IAE5B;;;;;;;;;OASG;IACH,0BAFU,uBAAuB,CAEe;IAEhD;;;OAGG;IACH,kBAFU,mBAAmB,CAEO;IAEpC;;;;OAIG;IACH,iBAFU,MAAM,CAEM;IAEtB;;;;OAIG;IACH,mBAFU,kBAAkB,CAEa;IAmBrC;;;OAGG;IACH,yBAAwB;IAKxB;;;OAGG;IACH,aAFU,gBAAgB,CAEe;IAGzC,yCAAkE;IAK9D,mBAAkC;IAMtC;;;OAGG;IACH,cAFU,aAAa,MAAM,CAAC,CAK5B;IAEF,8CAiCE;IA4BF;;;OAGG;IACH,SAFU,WAAW,CAEoB;IAEzC;;;OAGG;IACH,gBAFU,cAAc,CAEkB;IAE1C;;;OAGG;IACH,sCAFU,2BAA2B,CAE+B;IAEpE,yBAAoC;IAGpC;;OAEG;IACH,aAAkB;IAElB;;;OAGG;IACH,SAFU,OAAO,CAEwB;IAGzC,2BAAsC;IAOtC,+BAA6E;IAUzE;;;OAGG;IACH,UAFU,cAAc,CAEM;IAiB9B;;;OAGG;IACH,OAFU,WAAW,CAEG;IAK5B;;;OAGG;IACH,KAFU,SAAS,CAEO;IAE1B;;;OAGG;IACH,uBAFU,YAAY,CAEqD;IAI3E;;;MAGC;IAYD;;;OAGG;IACH,kBAFU,OAAO,CAEW;IAsBhC,wBAgCC;IApBG,oBAAwB;IAsB5B,2BAgCC;IAED,oBAiBC;IAED;;;OAGG;IACH,+CAUC;IAED,eAwBC;IAED;;;OAGG;IACH,sBA0CC;IAqBD;;OAEG;IACH,sBAqBC;IAED,aAEC;IAED;;OAEG;IACH,4BAOC;IAIL;;;OAGG;IACH,mBAFU,OAAO,CAEQ;;CAPxB;0BA5iByB,0CAA0C;wCAY5B,iDAAiD;oCAGrD,iCAAiC;mBAElD,wBAAwB;+BAnBZ,gDAAgD;iCAM9C,+CAA+C;6BAFnD,yBAAyB;uCAIf,6DAA6D;4BAQxE,0BAA0B;+BAlBvB,iCAAiC;4CAYpB,qDAAqD;AAejG;IACI,gDAA2D;IAC3D,0BAAkC;IAClC,iCAAyC;CAC5C;6BAhC4B,sCAAsC;4DAHP,OAAO;+BAiBpC,8BAA8B;wBASrC,wBAAwB;sBAE1B,mBAAmB;yBAJhB,yBAAyB;8BALpB,kCAAkC;2BADrC,mCAAmC;sBAXxC,+BAA+B;+BAItB,qCAAqC;8BAItC,wBAAwB;4BAV1B,kCAAkC;oBAH1C,yBAAyB"}
|
package/src/engine/Engine.js
CHANGED
|
@@ -13,7 +13,7 @@ import EmptyView from "../view/elements/EmptyView.js";
|
|
|
13
13
|
import { ViewStack } from "../view/elements/navigation/ViewStack.js";
|
|
14
14
|
|
|
15
15
|
import { AssetManager } from './asset/AssetManager.js';
|
|
16
|
-
import
|
|
16
|
+
import { AssetPreloader } from "./asset/preloader/AssetPreloader.js";
|
|
17
17
|
import { MetricCollection } from "./development/performance/MetricCollection.js";
|
|
18
18
|
import { MetricStatistics } from "./development/performance/MetricStatistics.js";
|
|
19
19
|
import { PeriodicConsolePrinter } from "./development/performance/monitor/PeriodicConsolePrinter.js";
|
|
@@ -421,7 +421,7 @@ class Engine {
|
|
|
421
421
|
* @param {String} listURL
|
|
422
422
|
*/
|
|
423
423
|
loadAssetList(listURL) {
|
|
424
|
-
const preloader = new
|
|
424
|
+
const preloader = new AssetPreloader();
|
|
425
425
|
const assetManager = this.assetManager;
|
|
426
426
|
assetManager.get({
|
|
427
427
|
path: listURL, type: "json", callback: function (asset) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export default AssetLevel;
|
|
2
|
+
/**
|
|
3
|
+
* How important an asset is. The scale is numerically ascending, higher number = less important, lower number = more important.
|
|
4
|
+
* This controls what order we load assets in.
|
|
5
|
+
*/
|
|
6
|
+
type AssetLevel = number;
|
|
2
7
|
declare namespace AssetLevel {
|
|
3
8
|
let CRITICAL: number;
|
|
4
9
|
let HIGH: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetLevel.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/preloader/AssetLevel.js"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"AssetLevel.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/preloader/AssetLevel.js"],"names":[],"mappings":";;;;;kBAGU,MAAM"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How important an asset is. The scale is numerically ascending, higher number = less important, lower number = more important.
|
|
3
|
+
* This controls what order we load assets in.
|
|
4
|
+
* @enum {number}
|
|
5
|
+
*/
|
|
1
6
|
const AssetLevel = {
|
|
2
7
|
CRITICAL: 0,
|
|
3
8
|
HIGH: 1,
|
|
4
9
|
NORMAL: 2,
|
|
5
10
|
OPTIONAL: 3
|
|
6
11
|
};
|
|
12
|
+
|
|
7
13
|
export default AssetLevel;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility for loading multiple assets together.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const loader = new AssetPreloader();
|
|
6
|
+
*
|
|
7
|
+
* loader.add("/images/cat.jpg", "image", AssetLevel.CRITICAL );
|
|
8
|
+
* loader.add("/images/meow.mp3", "sound", AssetLevel.NORMAL );
|
|
9
|
+
*
|
|
10
|
+
* const assetManager:AssetManager = ...; // Obtain your asset manager
|
|
11
|
+
*
|
|
12
|
+
* loader.on.progress.add(({global}) => console.log(`loaded ${global.ratio*100}%`));
|
|
13
|
+
* loader.on.completed.add(()=> console.log("preload complete"));
|
|
14
|
+
*
|
|
15
|
+
* loader.load(assetManager);
|
|
16
|
+
*/
|
|
17
|
+
export class AssetPreloader {
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @type {number}
|
|
21
|
+
*/
|
|
22
|
+
totalAssetCount: number;
|
|
23
|
+
/**
|
|
24
|
+
* @readonly
|
|
25
|
+
* @type {AssetLoadSpec[][]}
|
|
26
|
+
*/
|
|
27
|
+
readonly assets: AssetLoadSpec[][];
|
|
28
|
+
/**
|
|
29
|
+
* @readonly
|
|
30
|
+
*/
|
|
31
|
+
readonly on: {
|
|
32
|
+
added: Signal<any, any, any, any, any, any, any, any>;
|
|
33
|
+
progress: Signal<any, any, any, any, any, any, any, any>;
|
|
34
|
+
levelFinished: Signal<any, any, any, any, any, any, any, any>;
|
|
35
|
+
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
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param {string} uri
|
|
42
|
+
* @param {string} type
|
|
43
|
+
* @param {number} [level] defines priority group
|
|
44
|
+
* @param {number} [priority] defines priority within the group
|
|
45
|
+
* @return {AssetPreloader}
|
|
46
|
+
*/
|
|
47
|
+
add(uri: string, type: string, level?: number, priority?: number): AssetPreloader;
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @param {{uri:string, type:string, level?:number}[]} list
|
|
51
|
+
*/
|
|
52
|
+
addAll(list: {
|
|
53
|
+
uri: string;
|
|
54
|
+
type: string;
|
|
55
|
+
level?: number;
|
|
56
|
+
}[]): void;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param {AssetManager} assetManager
|
|
60
|
+
* @return {AssetPreloader}
|
|
61
|
+
*/
|
|
62
|
+
load(assetManager: AssetManager): AssetPreloader;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated use {@link AssetPreloader} import instead. Renamed in v2.131.7
|
|
66
|
+
* @type {AssetPreloader}
|
|
67
|
+
*/
|
|
68
|
+
export const Preloader: AssetPreloader;
|
|
69
|
+
/**
|
|
70
|
+
* Definition of a single asset to be loaded
|
|
71
|
+
*/
|
|
72
|
+
declare class AssetLoadSpec {
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @param data
|
|
76
|
+
* @return {AssetLoadSpec}
|
|
77
|
+
*/
|
|
78
|
+
static fromJSON(data: any): AssetLoadSpec;
|
|
79
|
+
/**
|
|
80
|
+
* Path to the asset
|
|
81
|
+
* @type {String}
|
|
82
|
+
*/
|
|
83
|
+
uri: string;
|
|
84
|
+
/**
|
|
85
|
+
* Type of the asset
|
|
86
|
+
* @type {String}
|
|
87
|
+
*/
|
|
88
|
+
type: string;
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @type {number|AssetLevel}
|
|
92
|
+
*/
|
|
93
|
+
level: number | AssetLevel;
|
|
94
|
+
/**
|
|
95
|
+
* Priority within the level group (see {@link level})
|
|
96
|
+
* @type {number}
|
|
97
|
+
*/
|
|
98
|
+
priotity: number;
|
|
99
|
+
fromJSON({ uri, type, level, priority }: {
|
|
100
|
+
uri: any;
|
|
101
|
+
type: any;
|
|
102
|
+
level?: number;
|
|
103
|
+
priority?: number;
|
|
104
|
+
}): void;
|
|
105
|
+
}
|
|
106
|
+
import Signal from "../../../core/events/signal/Signal.js";
|
|
107
|
+
import AssetLevel from "./AssetLevel.js";
|
|
108
|
+
export {};
|
|
109
|
+
//# sourceMappingURL=AssetPreloader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssetPreloader.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/preloader/AssetPreloader.js"],"names":[],"mappings":"AAoDA;;;;;;;;;;;;;;;GAeG;AACH;IACI;;;OAGG;IACH,iBAFU,MAAM,CAEI;IAEpB;;;OAGG;IACH,iBAFU,aAAa,EAAE,EAAE,CAEf;IAEZ;;OAEG;IACH;;;;;;;MAOE;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,CAoHzB;CACJ;AAED;;;GAGG;AACH,wBAFU,cAAc,CAEgB;AA3RxC;;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;mBAjDkB,uCAAuC;uBACnC,iBAAiB"}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { assert } from "../../../core/assert.js";
|
|
2
|
+
import Signal from "../../../core/events/signal/Signal.js";
|
|
3
|
+
import AssetLevel from "./AssetLevel.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Definition of a single asset to be loaded
|
|
7
|
+
*/
|
|
8
|
+
class AssetLoadSpec {
|
|
9
|
+
constructor() {
|
|
10
|
+
/**
|
|
11
|
+
* Path to the asset
|
|
12
|
+
* @type {String}
|
|
13
|
+
*/
|
|
14
|
+
this.uri = null;
|
|
15
|
+
/**
|
|
16
|
+
* Type of the asset
|
|
17
|
+
* @type {String}
|
|
18
|
+
*/
|
|
19
|
+
this.type = null;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @type {number|AssetLevel}
|
|
23
|
+
*/
|
|
24
|
+
this.level = AssetLevel.OPTIONAL;
|
|
25
|
+
/**
|
|
26
|
+
* Priority within the level group (see {@link level})
|
|
27
|
+
* @type {number}
|
|
28
|
+
*/
|
|
29
|
+
this.priotity = 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fromJSON({ uri, type, level = AssetLevel.OPTIONAL, priority = 0 }) {
|
|
33
|
+
this.uri = uri;
|
|
34
|
+
this.type = type;
|
|
35
|
+
this.level = level;
|
|
36
|
+
this.priotity = priority;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param data
|
|
42
|
+
* @return {AssetLoadSpec}
|
|
43
|
+
*/
|
|
44
|
+
static fromJSON(data) {
|
|
45
|
+
const r = new AssetLoadSpec();
|
|
46
|
+
|
|
47
|
+
r.fromJSON(data);
|
|
48
|
+
|
|
49
|
+
return r;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Utility for loading multiple assets together.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const loader = new AssetPreloader();
|
|
58
|
+
*
|
|
59
|
+
* loader.add("/images/cat.jpg", "image", AssetLevel.CRITICAL );
|
|
60
|
+
* loader.add("/images/meow.mp3", "sound", AssetLevel.NORMAL );
|
|
61
|
+
*
|
|
62
|
+
* const assetManager:AssetManager = ...; // Obtain your asset manager
|
|
63
|
+
*
|
|
64
|
+
* loader.on.progress.add(({global}) => console.log(`loaded ${global.ratio*100}%`));
|
|
65
|
+
* loader.on.completed.add(()=> console.log("preload complete"));
|
|
66
|
+
*
|
|
67
|
+
* loader.load(assetManager);
|
|
68
|
+
*/
|
|
69
|
+
export class AssetPreloader {
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
* @type {number}
|
|
73
|
+
*/
|
|
74
|
+
totalAssetCount = 0;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @readonly
|
|
78
|
+
* @type {AssetLoadSpec[][]}
|
|
79
|
+
*/
|
|
80
|
+
assets = [];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @readonly
|
|
84
|
+
*/
|
|
85
|
+
on = {
|
|
86
|
+
added: new Signal(),
|
|
87
|
+
progress: new Signal(),
|
|
88
|
+
levelFinished: new Signal(),
|
|
89
|
+
error: new Signal(),
|
|
90
|
+
loadStart: new Signal(),
|
|
91
|
+
completed: new Signal()
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
constructor() {
|
|
95
|
+
|
|
96
|
+
//build batch containers for each level
|
|
97
|
+
for (let l in AssetLevel) {
|
|
98
|
+
if (AssetLevel.hasOwnProperty(l)) {
|
|
99
|
+
const level = AssetLevel[l];
|
|
100
|
+
this.assets[level] = [];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @param {string} uri
|
|
108
|
+
* @param {string} type
|
|
109
|
+
* @param {number} [level] defines priority group
|
|
110
|
+
* @param {number} [priority] defines priority within the group
|
|
111
|
+
* @return {AssetPreloader}
|
|
112
|
+
*/
|
|
113
|
+
add(
|
|
114
|
+
uri,
|
|
115
|
+
type,
|
|
116
|
+
level = AssetLevel.OPTIONAL,
|
|
117
|
+
priority = 0
|
|
118
|
+
) {
|
|
119
|
+
|
|
120
|
+
assert.isString(uri, 'uri');
|
|
121
|
+
assert.isString(type, 'type');
|
|
122
|
+
assert.isNumber(level, 'level');
|
|
123
|
+
assert.isNumber(priority, 'priority');
|
|
124
|
+
|
|
125
|
+
const assets = this.assets;
|
|
126
|
+
|
|
127
|
+
//asset definition
|
|
128
|
+
const def = AssetLoadSpec.fromJSON({
|
|
129
|
+
uri,
|
|
130
|
+
type,
|
|
131
|
+
priority
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
let _level = level;
|
|
135
|
+
|
|
136
|
+
if (!assets.hasOwnProperty(_level)) {
|
|
137
|
+
//unsupported level was requested, rewrite to optional
|
|
138
|
+
_level = AssetLevel.OPTIONAL;
|
|
139
|
+
console.warn(`Unsupported level(=${level}) was requested for ${JSON.stringify(def)}, defaulting to optional`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
assets[_level].push(def);
|
|
143
|
+
|
|
144
|
+
this.totalAssetCount++;
|
|
145
|
+
this.on.added.send2(def, _level);
|
|
146
|
+
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
*
|
|
152
|
+
* @param {{uri:string, type:string, level?:number}[]} list
|
|
153
|
+
*/
|
|
154
|
+
addAll(list) {
|
|
155
|
+
assert.isArray(list, 'list');
|
|
156
|
+
|
|
157
|
+
for (const el of list) {
|
|
158
|
+
this.add(el.uri, el.type, el.level);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
*
|
|
164
|
+
* @param {AssetManager} assetManager
|
|
165
|
+
* @return {AssetPreloader}
|
|
166
|
+
*/
|
|
167
|
+
load(assetManager) {
|
|
168
|
+
const on = this.on;
|
|
169
|
+
|
|
170
|
+
//current level being processed
|
|
171
|
+
const assets = this.assets;
|
|
172
|
+
|
|
173
|
+
//dispatch init event
|
|
174
|
+
const initEvent = assets.map(function (batch, level) {
|
|
175
|
+
return {
|
|
176
|
+
level: level,
|
|
177
|
+
count: batch.length
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
on.loadStart.send1(initEvent);
|
|
182
|
+
const numAssets = this.totalAssetCount;
|
|
183
|
+
let numAssetsLoaded = 0;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* submit requests in batches in order of importance
|
|
187
|
+
* @param {number} level
|
|
188
|
+
*/
|
|
189
|
+
function loadBatch(level) {
|
|
190
|
+
// filter out assets of the specified level
|
|
191
|
+
const batch = assets[level];
|
|
192
|
+
|
|
193
|
+
const batchElementCount = batch.length;
|
|
194
|
+
|
|
195
|
+
if (batchElementCount === 0) {
|
|
196
|
+
// batch of 0 elements
|
|
197
|
+
// dispatch completion event
|
|
198
|
+
on.levelFinished.dispatch(level);
|
|
199
|
+
//early exit
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
let batchElementLoadedCount = 0;
|
|
204
|
+
|
|
205
|
+
function assetLoadSuccess(asset) {
|
|
206
|
+
batchElementLoadedCount++;
|
|
207
|
+
numAssetsLoaded++;
|
|
208
|
+
|
|
209
|
+
let ratio = numAssetsLoaded / numAssets;
|
|
210
|
+
|
|
211
|
+
//dispatch progress
|
|
212
|
+
on.progress.dispatch({
|
|
213
|
+
level: {
|
|
214
|
+
id: level,
|
|
215
|
+
value: batchElementLoadedCount,
|
|
216
|
+
max: batchElementCount
|
|
217
|
+
},
|
|
218
|
+
global: {
|
|
219
|
+
value: numAssetsLoaded,
|
|
220
|
+
max: numAssets,
|
|
221
|
+
fraction: ratio
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
//monitor completion
|
|
226
|
+
if (batchElementLoadedCount >= batchElementCount) {
|
|
227
|
+
on.levelFinished.dispatch(level);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function assetLoadFailed(e) {
|
|
233
|
+
on.error.dispatch(e);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
//sort batch by priority
|
|
237
|
+
batch.sort((a, b) => {
|
|
238
|
+
return b.priotity - a.priotity;
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
batch.forEach(function (def) {
|
|
242
|
+
assetManager.get({
|
|
243
|
+
path: def.uri,
|
|
244
|
+
type: def.type,
|
|
245
|
+
callback: assetLoadSuccess,
|
|
246
|
+
failure: assetLoadFailed
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const levels = [];
|
|
252
|
+
for (let level in assets) {
|
|
253
|
+
if (assets.hasOwnProperty(level)) {
|
|
254
|
+
levels.push(level);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
let lastLoadedLevel = 0;
|
|
259
|
+
|
|
260
|
+
function prod() {
|
|
261
|
+
|
|
262
|
+
if (lastLoadedLevel < levels.length) {
|
|
263
|
+
|
|
264
|
+
const levelToLoad = lastLoadedLevel;
|
|
265
|
+
lastLoadedLevel++;
|
|
266
|
+
on.levelFinished.addOne(prod);
|
|
267
|
+
|
|
268
|
+
//console.log('requesting load of level ',levelToLoad);
|
|
269
|
+
|
|
270
|
+
loadBatch(levelToLoad);
|
|
271
|
+
|
|
272
|
+
} else {
|
|
273
|
+
on.completed.send0();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
prod();
|
|
279
|
+
|
|
280
|
+
return this;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @deprecated use {@link AssetPreloader} import instead. Renamed in v2.131.7
|
|
286
|
+
* @type {AssetPreloader}
|
|
287
|
+
*/
|
|
288
|
+
export const Preloader = AssetPreloader;
|
|
289
|
+
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Preloader.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/preloader/Preloader.js"],"names":[],"mappings":";;IAqEA,0DAqBC;IAED,wBAKC;IAED,8BAwFC"}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import AssetLevel from "./AssetLevel.js";
|
|
2
|
-
import Signal from "../../../core/events/signal/Signal.js";
|
|
3
|
-
|
|
4
|
-
class AssetLoadSpec {
|
|
5
|
-
constructor() {
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @type {String}
|
|
9
|
-
*/
|
|
10
|
-
this.uri = null;
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @type {String}
|
|
14
|
-
*/
|
|
15
|
-
this.type = null;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @type {number|AssetLevel}
|
|
19
|
-
*/
|
|
20
|
-
this.level = AssetLevel.OPTIONAL;
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
* @type {number}
|
|
24
|
-
*/
|
|
25
|
-
this.priotity = 0;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
fromJSON({ uri, type, level = AssetLevel.OPTIONAL, priority = 0 }) {
|
|
29
|
-
this.uri = uri;
|
|
30
|
-
this.type = type;
|
|
31
|
-
this.level = level;
|
|
32
|
-
this.priotity = priority;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @param data
|
|
38
|
-
* @return {AssetLoadSpec}
|
|
39
|
-
*/
|
|
40
|
-
static fromJSON(data) {
|
|
41
|
-
const r = new AssetLoadSpec();
|
|
42
|
-
|
|
43
|
-
r.fromJSON(data);
|
|
44
|
-
|
|
45
|
-
return r;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const Preloader = function () {
|
|
50
|
-
this.totalAssetCount = 0;
|
|
51
|
-
//
|
|
52
|
-
const assets = this.assets = [];
|
|
53
|
-
//build batch containers for each level
|
|
54
|
-
for (let l in AssetLevel) {
|
|
55
|
-
if (AssetLevel.hasOwnProperty(l)) {
|
|
56
|
-
const level = AssetLevel[l];
|
|
57
|
-
assets[level] = [];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
//setup signals
|
|
61
|
-
this.on = {
|
|
62
|
-
added: new Signal(),
|
|
63
|
-
progress: new Signal(),
|
|
64
|
-
levelFinished: new Signal(),
|
|
65
|
-
error: new Signal(),
|
|
66
|
-
loadStart: new Signal(),
|
|
67
|
-
completed: new Signal()
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
Preloader.prototype.add = function (uri, type, level, priority) {
|
|
71
|
-
if (level === void 0) {
|
|
72
|
-
level = AssetLevel.OPTIONAL;
|
|
73
|
-
}
|
|
74
|
-
const assets = this.assets;
|
|
75
|
-
//asset definition
|
|
76
|
-
const def = AssetLoadSpec.fromJSON({
|
|
77
|
-
uri,
|
|
78
|
-
type,
|
|
79
|
-
priority
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (!assets.hasOwnProperty(level)) {
|
|
83
|
-
//unsupported level was requested, defaulting to optional
|
|
84
|
-
level = AssetLevel.OPTIONAL;
|
|
85
|
-
console.warn(`Unsupported level(=${level}) was requested for ${JSON.stringify(def)}, defaulting to optional`);
|
|
86
|
-
}
|
|
87
|
-
assets[level].push(def);
|
|
88
|
-
this.totalAssetCount++;
|
|
89
|
-
this.on.added.send2(def, level);
|
|
90
|
-
return this;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
Preloader.prototype.addAll = function (list) {
|
|
94
|
-
const self = this;
|
|
95
|
-
list.forEach(function (el) {
|
|
96
|
-
self.add(el.uri, el.type, el.level);
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
Preloader.prototype.load = function (assetManager) {
|
|
101
|
-
const on = this.on;
|
|
102
|
-
//current level being processed
|
|
103
|
-
const assets = this.assets;
|
|
104
|
-
//dispatch init event
|
|
105
|
-
const initEvent = assets.map(function (batch, level) {
|
|
106
|
-
return {
|
|
107
|
-
level: level,
|
|
108
|
-
count: batch.length
|
|
109
|
-
};
|
|
110
|
-
});
|
|
111
|
-
on.loadStart.send1(initEvent);
|
|
112
|
-
const numAssets = this.totalAssetCount;
|
|
113
|
-
let numAssetsLoaded = 0;
|
|
114
|
-
|
|
115
|
-
//submit requests in batches in order of importance
|
|
116
|
-
function loadBatch(level) {
|
|
117
|
-
//filter out assets of specified level
|
|
118
|
-
const batch = assets[level];
|
|
119
|
-
const batchElementCount = batch.length;
|
|
120
|
-
if (batchElementCount === 0) {
|
|
121
|
-
//batch of 0 elements
|
|
122
|
-
//dispatch completion event
|
|
123
|
-
on.levelFinished.dispatch(level);
|
|
124
|
-
//early exit
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
let batchElementLoadedCount = 0;
|
|
128
|
-
|
|
129
|
-
function assetLoadSuccess(asset) {
|
|
130
|
-
batchElementLoadedCount++;
|
|
131
|
-
numAssetsLoaded++;
|
|
132
|
-
let ratio = numAssetsLoaded / numAssets;
|
|
133
|
-
//dispatch progress
|
|
134
|
-
on.progress.dispatch({
|
|
135
|
-
level: {
|
|
136
|
-
id: level,
|
|
137
|
-
value: batchElementLoadedCount,
|
|
138
|
-
max: batchElementCount
|
|
139
|
-
},
|
|
140
|
-
global: {
|
|
141
|
-
value: numAssetsLoaded,
|
|
142
|
-
max: numAssets
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
//monitor completion
|
|
146
|
-
if (batchElementLoadedCount >= batchElementCount) {
|
|
147
|
-
on.levelFinished.dispatch(level);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function assetLoadFailed(e) {
|
|
152
|
-
on.error.dispatch(e);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
//sort batch by priority
|
|
156
|
-
batch.sort((a, b) => {
|
|
157
|
-
return b.priotity - a.priority;
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
batch.forEach(function (def) {
|
|
161
|
-
assetManager.get({ path: def.uri, type: def.type, callback: assetLoadSuccess, failure: assetLoadFailed });
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const levels = [];
|
|
166
|
-
for (let level in assets) {
|
|
167
|
-
if (assets.hasOwnProperty(level)) {
|
|
168
|
-
levels.push(level);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
let lastLoadedLevel = 0;
|
|
172
|
-
|
|
173
|
-
function f() {
|
|
174
|
-
if (lastLoadedLevel < levels.length) {
|
|
175
|
-
const levelToLoad = lastLoadedLevel;
|
|
176
|
-
lastLoadedLevel++;
|
|
177
|
-
on.levelFinished.addOne(f);
|
|
178
|
-
// console.log("requesting load of level ",levelToLoad);
|
|
179
|
-
loadBatch(levelToLoad);
|
|
180
|
-
} else {
|
|
181
|
-
on.completed.send0();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
f();
|
|
186
|
-
|
|
187
|
-
return this;
|
|
188
|
-
};
|
|
189
|
-
export default Preloader;
|