summaryrefslogtreecommitdiffstats
path: root/platform/javascript/engine/engine.js
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-10-23 18:33:20 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-11-10 11:42:51 +0100
commite2083871eb57e56fe637c3d8f6647ddb4ff539e0 (patch)
treea58669c68065541e0062f82d7edb45789d8f354f /platform/javascript/engine/engine.js
parent54cda5c3b8622c9168fcd5d1c68964ef7697b27e (diff)
downloadredot-engine-e2083871eb57e56fe637c3d8f6647ddb4ff539e0.tar.gz
[HTML5] Port JavaScript inline code to libraries.
The API is implemented in javascript, and generates C functions that can be called from godot. This allows much cleaner code replacing all `EM_ASM` calls in our C++ code with plain C function calls. This also gets rid of few hacks and comes with few optimizations (e.g. custom cursor shapes should be much faster now).
Diffstat (limited to 'platform/javascript/engine/engine.js')
-rw-r--r--platform/javascript/engine/engine.js36
1 files changed, 23 insertions, 13 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;
};