Browse Source

EmscriptenApplication: use existing Module object

This prevents deleting elements in Module that were set by Emscripten preamble code when using EmscriptenApplication.js with --pre-js
pull/480/head
Pablo Escobar 6 years ago
parent
commit
0e657a5f91
  1. 40
      src/Magnum/Platform/EmscriptenApplication.js

40
src/Magnum/Platform/EmscriptenApplication.js

@ -25,46 +25,47 @@
"use strict"; /* it summons the Cthulhu in a proper way, they say */
var Module = {
preRun: [],
postRun: [],
var Module = typeof Module !== "undefined" ? Module : {};
arguments: [],
Module.preRun = [];
Module.postRun = [];
printErr: function(message) {
Module.arguments = [];
Module.printErr = function(_message) {
console.error(Array.prototype.slice.call(arguments).join(' '));
},
};
print: function(message) {
Module.print = function(_message) {
console.log(Array.prototype.slice.call(arguments).join(' '));
},
};
onAbort: function() {
Module.onAbort = function() {
Module.canvas.style.opacity = 0.333;
Module.canvas.style.zIndex = -1;
Module.setStatus("Oops :(");
Module.setStatusDescription("The app crashed. Refresh the page or check the browser console for details.");
},
};
canvas: document.getElementById('canvas'),
status: document.getElementById('status'),
statusDescription: document.getElementById('status-description'),
Module.canvas = document.getElementById('canvas');
Module.status = document.getElementById('status');
Module.statusDescription = document.getElementById('status-description');
setStatus: function(message) {
Module.setStatus = function(message) {
/* Emscripten calls setStatus("") after a timeout even if the app
aborts. That would erase the crash message, so don't allow that */
if(Module.status && Module.status.innerHTML != "Oops :(")
Module.status.innerHTML = message;
},
};
setStatusDescription: function(message) {
Module.setStatusDescription = function(message) {
if(Module.statusDescription)
Module.statusDescription.innerHTML = message;
},
};
totalDependencies: 0,
Module.totalDependencies = 0;
monitorRunDependencies: function(left) {
Module.monitorRunDependencies = function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
if(left) {
@ -74,7 +75,6 @@ var Module = {
Module.setStatus('Download complete');
Module.setStatusDescription('');
}
}
};
/* Parse arguments, e.g. /app/?foo=bar&fizz&buzz=3 goes to the app as

Loading…
Cancel
Save