diff options
Diffstat (limited to 'platform/javascript/engine')
-rw-r--r-- | platform/javascript/engine/engine.js | 36 | ||||
-rw-r--r-- | platform/javascript/engine/preloader.js | 4 | ||||
-rw-r--r-- | platform/javascript/engine/utils.js | 4 |
3 files changed, 25 insertions, 19 deletions
diff --git a/platform/javascript/engine/engine.js b/platform/javascript/engine/engine.js index 05a11701c0..3745e04479 100644 --- a/platform/javascript/engine/engine.js +++ b/platform/javascript/engine/engine.js @@ -33,7 +33,7 @@ Function('return this')()['Engine'] = (function() { this.resizeCanvasOnStart = false; this.onExecute = null; this.onExit = null; - this.persistentPaths = []; + this.persistentPaths = ['/userfs']; }; Engine.prototype.init = /** @param {string=} basePath */ function(basePath) { @@ -114,18 +114,30 @@ Function('return this')()['Engine'] = (function() { locale = navigator.languages ? navigator.languages[0] : navigator.language; locale = locale.split('.')[0]; } - me.rtenv['locale'] = locale; - me.rtenv['canvas'] = me.canvas; + // Emscripten configuration. me.rtenv['thisProgram'] = me.executableName; - me.rtenv['resizeCanvasOnStart'] = me.resizeCanvasOnStart; me.rtenv['noExitRuntime'] = true; - me.rtenv['onExecute'] = me.onExecute; - me.rtenv['onExit'] = function(code) { - me.rtenv['deinitFS'](); - if (me.onExit) - me.onExit(code); - me.rtenv = null; - }; + // Godot configuration. + me.rtenv['initConfig']({ + 'resizeCanvasOnStart': me.resizeCanvasOnStart, + 'canvas': me.canvas, + 'locale': locale, + 'onExecute': function(p_args) { + if (me.onExecute) { + me.onExecute(p_args); + return 0; + } + return 1; + }, + 'onExit': function(p_code) { + me.rtenv['deinitFS'](); + if (me.onExit) { + me.onExit(p_code); + } + me.rtenv = null; + }, + }); + return new Promise(function(resolve, reject) { preloader.preloadedFiles.forEach(function(file) { me.rtenv['copyToFS'](file.path, file.buffer); @@ -208,8 +220,6 @@ Function('return this')()['Engine'] = (function() { }; Engine.prototype.setOnExecute = function(onExecute) { - if (this.rtenv) - this.rtenv.onExecute = onExecute; this.onExecute = onExecute; }; diff --git a/platform/javascript/engine/preloader.js b/platform/javascript/engine/preloader.js index 17918eae38..b3467d009f 100644 --- a/platform/javascript/engine/preloader.js +++ b/platform/javascript/engine/preloader.js @@ -1,5 +1,4 @@ var Preloader = /** @constructor */ function() { - var DOWNLOAD_ATTEMPTS_MAX = 4; var progressFunc = null; var lastProgress = { loaded: 0, total: 0 }; @@ -20,9 +19,7 @@ var Preloader = /** @constructor */ function() { } function onXHREvent(resolve, reject, file, tracker, ev) { - if (this.status >= 400) { - if (this.status < 500 || ++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) { reject(new Error("Failed loading file '" + file + "': " + this.statusText)); this.abort(); @@ -103,7 +100,6 @@ var Preloader = /** @constructor */ function() { }; var animateProgress = function() { - var loaded = 0; var total = 0; var totalIsValid = true; diff --git a/platform/javascript/engine/utils.js b/platform/javascript/engine/utils.js index 0c97b38199..8455739a25 100644 --- a/platform/javascript/engine/utils.js +++ b/platform/javascript/engine/utils.js @@ -1,9 +1,10 @@ var Utils = { - createLocateRewrite: function(execName) { function rw(path) { if (path.endsWith('.worker.js')) { return execName + '.worker.js'; + } else if (path.endsWith('.audio.worklet.js')) { + return execName + '.audio.worklet.js'; } else if (path.endsWith('.js')) { return execName + '.js'; } else if (path.endsWith('.wasm')) { @@ -36,7 +37,6 @@ var Utils = { }, isWebGLAvailable: function(majorVersion = 1) { - var testContext = false; try { var testCanvas = document.createElement('canvas'); |