aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-05-06 21:36:33 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-05-06 21:36:33 -0700
commitdbea06d1d8c0c8ce4eb2651891dc905d71f6afd7 (patch)
tree6d823f657c5ca250061cf66c1fe786fbdb3fc034
parente6a6ffecdad07bcb2eeafe39a9f0c6d25c190970 (diff)
fix main loop pausing to handle pauses from main loop and other sources as well, and pause/resumes before the main loop returns
-rw-r--r--src/library_browser.js25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/library_browser.js b/src/library_browser.js
index 07641aed..4e25d9d0 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -7,6 +7,7 @@ mergeInto(LibraryManager.library, {
$Browser: {
mainLoop: {
scheduler: null,
+ shouldPause: false,
paused: false
},
pointerLock: false,
@@ -154,8 +155,19 @@ mergeInto(LibraryManager.library, {
var jsFunc = FUNCTION_TABLE[func];
var wrapper = function() {
- if (Browser.mainLoop.paused) return;
+ if (Browser.mainLoop.shouldPause) {
+ // catch pauses from non-main loop sources
+ Browser.mainLoop.paused = true;
+ Browser.mainLoop.shouldPause = false;
+ return;
+ }
jsFunc();
+ if (Browser.mainLoop.shouldPause) {
+ // catch pauses from the main loop itself
+ Browser.mainLoop.paused = true;
+ Browser.mainLoop.shouldPause = false;
+ return;
+ }
Browser.mainLoop.scheduler();
}
if (fps && fps > 0) {
@@ -172,16 +184,19 @@ mergeInto(LibraryManager.library, {
emscripten_cancel_main_loop: function(func) {
Browser.mainLoop.scheduler = null;
- Browser.mainLoop.paused = true;
+ Browser.mainLoop.shouldPause = true;
},
emscripten_pause_main_loop: function(func) {
- Browser.mainLoop.paused = true;
+ Browser.mainLoop.shouldPause = true;
},
emscripten_resume_main_loop: function(func) {
- Browser.mainLoop.paused = false;
- Browser.mainLoop.scheduler();
+ if (Browser.mainLoop.paused) {
+ Browser.mainLoop.paused = false;
+ Browser.mainLoop.scheduler();
+ }
+ Browser.mainLoop.shouldPause = false;
},
emscripten_async_call: function(func, millis) {