AtomicLoader.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var Module;
  2. /*
  3. window.onerror = function(event) {
  4. // TODO: do not warn on ok events like simulating an infinite loop or exitStatus
  5. Module.setStatus('Exception thrown, see JavaScript console');
  6. Module.setStatus = function(text) {
  7. if (text) Module.printErr('[post-exception status] ' + text);
  8. };
  9. };
  10. */
  11. var AtomicLoader = function(playerCanvas, spinner, width, height) {
  12. AtomicLoader.instance = this;
  13. this.playerCanvas = playerCanvas;
  14. this.spinner = spinner;
  15. this.width = width;
  16. this.height = height;
  17. playerCanvas.width = width;
  18. playerCanvas.height = height;
  19. // starts invisible
  20. playerCanvas.style.display = 'none';
  21. this.backgroundImageData = null;
  22. this.progress = 0.0;
  23. this.progressText = "Downloading"
  24. this.initModuleObject();
  25. }
  26. AtomicLoader.prototype.constructor = AtomicLoader;
  27. AtomicLoader.prototype.initModuleObject = function() {
  28. Module = {
  29. arguments: ["-x", AtomicLoader.instance.width.toString(), "-y", AtomicLoader.instance.height.toString()],
  30. preRun:[function() {
  31. var loader = AtomicLoader.instance;
  32. }],
  33. postRun: [function() {
  34. var loader = AtomicLoader.instance;
  35. loader.playerCanvas.style.display = 'block';
  36. loader.spinner.style.display = 'none';
  37. }],
  38. canvas: (function() {
  39. var loader = AtomicLoader.instance;
  40. // As a default initial behavior, pop up an alert when webgl context is lost. To make your
  41. // application robust, you may want to override this behavior before shipping!
  42. // See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
  43. loader.playerCanvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
  44. return loader.playerCanvas;
  45. })(),
  46. setStatus: function(text) {
  47. },
  48. totalDependencies: 0,
  49. monitorRunDependencies: function(left) {
  50. this.totalDependencies = Math.max(this.totalDependencies, left);
  51. Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
  52. }
  53. };
  54. }