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. 98
      src/Magnum/Platform/EmscriptenApplication.js

98
src/Magnum/Platform/EmscriptenApplication.js

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

Loading…
Cancel
Save