From cb1b89dac5b9a73612ccf8f61dfcc9d55c9ad598 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 1 Mar 2021 17:53:56 +0100 Subject: [HTML5] Export process writes sizes in template. This allow the loading bar to be much more reliable, even in cases where realible stream loading status is not detectable (server-side compression, chunked encoding). --- platform/javascript/js/engine/engine.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'platform/javascript/js/engine/engine.js') diff --git a/platform/javascript/js/engine/engine.js b/platform/javascript/js/engine/engine.js index e2d27c4c02..19a0552c8c 100644 --- a/platform/javascript/js/engine/engine.js +++ b/platform/javascript/js/engine/engine.js @@ -35,14 +35,15 @@ const Engine = (function () { * Load the engine from the specified base path. * * @param {string} basePath Base path of the engine to load. + * @param {number=} [size=0] The file size if known. * @returns {Promise} A Promise that resolves once the engine is loaded. * * @function Engine.load */ - Engine.load = function (basePath) { + Engine.load = function (basePath, size) { if (loadPromise == null) { loadPath = basePath; - loadPromise = preloader.loadPromise(`${loadPath}.wasm`, true); + loadPromise = preloader.loadPromise(`${loadPath}.wasm`, size, true); requestAnimationFrame(preloader.animateProgress); } return loadPromise; @@ -96,7 +97,7 @@ const Engine = (function () { initPromise = Promise.reject(new Error('A base path must be provided when calling `init` and the engine is not loaded.')); return initPromise; } - Engine.load(basePath); + Engine.load(basePath, this.config.fileSizes[`${basePath}.wasm`]); } const me = this; function doInit(promise) { @@ -137,7 +138,7 @@ const Engine = (function () { * @returns {Promise} A Promise that resolves once the file is loaded. */ preloadFile: function (file, path) { - return preloader.preload(file, path); + return preloader.preload(file, path, this.config.fileSizes[file]); }, /** -- cgit v1.2.3