You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
[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).
This commit is contained in:
@@ -100,6 +100,11 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
gdnativeLibs: [],
|
||||
/**
|
||||
* @ignore
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
fileSizes: [],
|
||||
/**
|
||||
* A callback function for handling Godot's ``OS.execute`` calls.
|
||||
*
|
||||
@@ -219,6 +224,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
|
||||
this.canvasResizePolicy = parse('canvasResizePolicy', this.canvasResizePolicy);
|
||||
this.persistentPaths = parse('persistentPaths', this.persistentPaths);
|
||||
this.gdnativeLibs = parse('gdnativeLibs', this.gdnativeLibs);
|
||||
this.fileSizes = parse('fileSizes', this.fileSizes);
|
||||
this.args = parse('args', this.args);
|
||||
this.onExecute = parse('onExecute', this.onExecute);
|
||||
this.onExit = parse('onExit', this.onExit);
|
||||
|
||||
@@ -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]);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,9 +43,9 @@ const Preloader = /** @constructor */ function () { // eslint-disable-line no-un
|
||||
}), { headers: response.headers });
|
||||
}
|
||||
|
||||
function loadFetch(file, tracker, raw) {
|
||||
function loadFetch(file, tracker, fileSize, raw) {
|
||||
tracker[file] = {
|
||||
total: 0,
|
||||
total: fileSize || 0,
|
||||
loaded: 0,
|
||||
done: false,
|
||||
};
|
||||
@@ -117,16 +117,16 @@ const Preloader = /** @constructor */ function () { // eslint-disable-line no-un
|
||||
progressFunc = callback;
|
||||
};
|
||||
|
||||
this.loadPromise = function (file, raw = false) {
|
||||
return retry(loadFetch.bind(null, file, loadingFiles, raw), DOWNLOAD_ATTEMPTS_MAX);
|
||||
this.loadPromise = function (file, fileSize, raw = false) {
|
||||
return retry(loadFetch.bind(null, file, loadingFiles, fileSize, raw), DOWNLOAD_ATTEMPTS_MAX);
|
||||
};
|
||||
|
||||
this.preloadedFiles = [];
|
||||
this.preload = function (pathOrBuffer, destPath) {
|
||||
this.preload = function (pathOrBuffer, destPath, fileSize) {
|
||||
let buffer = null;
|
||||
if (typeof pathOrBuffer === 'string') {
|
||||
const me = this;
|
||||
return this.loadPromise(pathOrBuffer).then(function (buf) {
|
||||
return this.loadPromise(pathOrBuffer, fileSize).then(function (buf) {
|
||||
me.preloadedFiles.push({
|
||||
path: destPath || pathOrBuffer,
|
||||
buffer: buf,
|
||||
|
||||
Reference in New Issue
Block a user