diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-06-16 14:38:43 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-06-16 14:38:43 -0700 |
commit | 7acb48826165890ebc9d3794d8d7473aa62b762e (patch) | |
tree | f23f1e3ac029b6f359c5986da7b1b903d6032731 | |
parent | b8d63ddfd7e620e812f35ff12e4869f0bc7a9473 (diff) |
share main loop iter logic with emscripten_*_loop and glut
-rw-r--r-- | src/library_browser.js | 30 | ||||
-rw-r--r-- | src/library_glut.js | 7 |
2 files changed, 20 insertions, 17 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 86447bc9..8509c9d7 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -41,6 +41,21 @@ mergeInto(LibraryManager.library, { Module['setStatus'](''); } } + }, + runIter: function(func) { + if (ABORT) return; + if (Module['preMainLoop']) Module['preMainLoop'](); + try { + func(); + } catch (e) { + if (e instanceof ExitStatus) { + return; + } else { + if (e && typeof e === 'object' && e.stack) Module.printErr('exception thrown: ' + [e, e.stack]); + throw e; + } + } + if (Module['postMainLoop']) Module['postMainLoop'](); } }, isFullScreen: false, @@ -954,24 +969,13 @@ mergeInto(LibraryManager.library, { Browser.mainLoop.method = ''; // just warn once per call to set main loop } - if (Module['preMainLoop']) Module['preMainLoop'](); - - try { + Browser.mainLoop.runIter(function() { if (typeof arg !== 'undefined') { Runtime.dynCall('vi', func, [arg]); } else { Runtime.dynCall('v', func); } - } catch (e) { - if (e instanceof ExitStatus) { - return; - } else { - if (e && typeof e === 'object' && e.stack) Module.printErr('exception thrown: ' + [e, e.stack]); - throw e; - } - } - - if (Module['postMainLoop']) Module['postMainLoop'](); + }); if (Browser.mainLoop.shouldPause) { // catch pauses from the main loop itself diff --git a/src/library_glut.js b/src/library_glut.js index d5f1b7b0..d6293d85 100644 --- a/src/library_glut.js +++ b/src/library_glut.js @@ -489,10 +489,9 @@ var LibraryGLUT = { GLUT.requestedAnimationFrame = true; Browser.requestAnimationFrame(function() { GLUT.requestedAnimationFrame = false; - if (ABORT) return; - if (Module['preMainLoop']) Module['preMainLoop'](); - Runtime.dynCall('v', GLUT.displayFunc); - if (Module['postMainLoop']) Module['postMainLoop'](); + Browser.mainLoop.runIter(function() { + Runtime.dynCall('v', GLUT.displayFunc); + }); }); } }, |