@woosh/meep-engine 2.131.8 → 2.131.10
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/engine/asset/AssetManager.js +1 -1
- package/src/engine/asset/preloader/AssetPreloader.d.ts +2 -0
- package/src/engine/asset/preloader/AssetPreloader.d.ts.map +1 -1
- package/src/engine/asset/preloader/AssetPreloader.js +37 -18
- package/src/view/asset/PreloaderView.js +2 -2
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.10",
|
|
9
9
|
"main": "build/meep.module.js",
|
|
10
10
|
"module": "build/meep.module.js",
|
|
11
11
|
"exports": {
|
|
@@ -273,7 +273,7 @@ export class AssetManager {
|
|
|
273
273
|
* @template T
|
|
274
274
|
* @param {String} path
|
|
275
275
|
* @param {String} type
|
|
276
|
-
* @param {function(asset:Asset<T>)} [callback]
|
|
276
|
+
* @param {function(asset:Asset<T>)} [callback] success callback
|
|
277
277
|
* @param {function(*)} [failure]
|
|
278
278
|
* @param {function(loaded:number, total:number)} [progress]
|
|
279
279
|
* @param {boolean} [skip_queue]
|
|
@@ -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
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetPreloader.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/preloader/AssetPreloader.js"],"names":[],"mappings":"
|
|
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;;;;;;;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,CAmIzB;CACJ;AAED;;;GAGG;AACH,wBAFU,cAAc,CAEgB;AA5SxC;;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,5 +1,7 @@
|
|
|
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";
|
|
4
|
+
import { clamp01 } from "../../../core/math/clamp01.js";
|
|
3
5
|
import AssetLevel from "./AssetLevel.js";
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -53,6 +55,8 @@ class AssetLoadSpec {
|
|
|
53
55
|
/**
|
|
54
56
|
* Utility for loading multiple assets together.
|
|
55
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
|
+
*
|
|
56
60
|
* @example
|
|
57
61
|
* const loader = new AssetPreloader();
|
|
58
62
|
*
|
|
@@ -88,7 +92,7 @@ export class AssetPreloader {
|
|
|
88
92
|
levelFinished: new Signal(),
|
|
89
93
|
error: new Signal(),
|
|
90
94
|
loadStart: new Signal(),
|
|
91
|
-
completed: new Signal()
|
|
95
|
+
completed: new Signal(),
|
|
92
96
|
};
|
|
93
97
|
|
|
94
98
|
constructor() {
|
|
@@ -165,6 +169,9 @@ export class AssetPreloader {
|
|
|
165
169
|
* @return {AssetPreloader}
|
|
166
170
|
*/
|
|
167
171
|
load(assetManager) {
|
|
172
|
+
assert.defined(assetManager, 'assetManager');
|
|
173
|
+
assert.equal(assetManager.isAssetManager, true, 'assetManager.isAssetManager !== true');
|
|
174
|
+
|
|
168
175
|
const on = this.on;
|
|
169
176
|
|
|
170
177
|
//current level being processed
|
|
@@ -186,14 +193,14 @@ export class AssetPreloader {
|
|
|
186
193
|
* submit requests in batches in order of importance
|
|
187
194
|
* @param {number} level
|
|
188
195
|
*/
|
|
189
|
-
function
|
|
196
|
+
function load_level(level) {
|
|
190
197
|
// filter out assets of the specified level
|
|
191
198
|
const batch = assets[level];
|
|
192
199
|
|
|
193
200
|
const batchElementCount = batch.length;
|
|
194
201
|
|
|
195
202
|
if (batchElementCount === 0) {
|
|
196
|
-
// batch of 0 elements
|
|
203
|
+
// a batch of 0 elements.
|
|
197
204
|
// dispatch completion event
|
|
198
205
|
on.levelFinished.dispatch(level);
|
|
199
206
|
//early exit
|
|
@@ -206,19 +213,22 @@ export class AssetPreloader {
|
|
|
206
213
|
batchElementLoadedCount++;
|
|
207
214
|
numAssetsLoaded++;
|
|
208
215
|
|
|
209
|
-
let
|
|
216
|
+
let total_ratio = numAssets > 0 ? clamp01(numAssetsLoaded / numAssets) : 1;
|
|
217
|
+
|
|
218
|
+
const level_ratio = batchElementCount > 0 ? clamp01(batchElementLoadedCount / batchElementCount) : 1;
|
|
210
219
|
|
|
211
220
|
//dispatch progress
|
|
212
|
-
on.progress.
|
|
221
|
+
on.progress.send1({
|
|
213
222
|
level: {
|
|
214
223
|
id: level,
|
|
215
|
-
|
|
216
|
-
|
|
224
|
+
current: batchElementLoadedCount,
|
|
225
|
+
total: batchElementCount,
|
|
226
|
+
progress: level_ratio,
|
|
217
227
|
},
|
|
218
228
|
global: {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
229
|
+
current: numAssetsLoaded,
|
|
230
|
+
total: numAssets,
|
|
231
|
+
progress: total_ratio
|
|
222
232
|
}
|
|
223
233
|
});
|
|
224
234
|
|
|
@@ -238,21 +248,26 @@ export class AssetPreloader {
|
|
|
238
248
|
return b.priotity - a.priotity;
|
|
239
249
|
});
|
|
240
250
|
|
|
241
|
-
|
|
251
|
+
for (const def of batch) {
|
|
252
|
+
|
|
242
253
|
assetManager.get({
|
|
243
254
|
path: def.uri,
|
|
244
255
|
type: def.type,
|
|
245
256
|
callback: assetLoadSuccess,
|
|
246
257
|
failure: assetLoadFailed
|
|
247
258
|
});
|
|
248
|
-
|
|
259
|
+
|
|
260
|
+
}
|
|
249
261
|
}
|
|
250
262
|
|
|
263
|
+
/**
|
|
264
|
+
*
|
|
265
|
+
* @type {number[]}
|
|
266
|
+
*/
|
|
251
267
|
const levels = [];
|
|
268
|
+
|
|
252
269
|
for (let level in assets) {
|
|
253
|
-
|
|
254
|
-
levels.push(level);
|
|
255
|
-
}
|
|
270
|
+
array_push_if_unique(levels, level);
|
|
256
271
|
}
|
|
257
272
|
|
|
258
273
|
let lastLoadedLevel = 0;
|
|
@@ -260,17 +275,21 @@ export class AssetPreloader {
|
|
|
260
275
|
function prod() {
|
|
261
276
|
|
|
262
277
|
if (lastLoadedLevel < levels.length) {
|
|
278
|
+
|
|
279
|
+
// load next
|
|
263
280
|
|
|
264
281
|
const levelToLoad = lastLoadedLevel;
|
|
265
282
|
lastLoadedLevel++;
|
|
266
283
|
on.levelFinished.addOne(prod);
|
|
267
284
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
loadBatch(levelToLoad);
|
|
285
|
+
load_level(levelToLoad);
|
|
271
286
|
|
|
272
287
|
} else {
|
|
288
|
+
|
|
289
|
+
// we're done
|
|
290
|
+
|
|
273
291
|
on.completed.send0();
|
|
292
|
+
|
|
274
293
|
}
|
|
275
294
|
|
|
276
295
|
}
|