diff options
-rw-r--r-- | src/library_browser.js | 22 | ||||
-rw-r--r-- | system/include/emscripten/emscripten.h | 8 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 5461e663..b9570683 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -23,6 +23,19 @@ mergeInto(LibraryManager.library, { } Browser.mainLoop.shouldPause = false; }, + updateStatus: function() { + if (Module['setStatus']) { + if (Browser.mainLoop.queue.length > 0) { + if (Browser.mainLoop.blockersNum && Browser.mainLoop.blockersNum >= Browser.mainLoop.queue.length) { + Module['setStatus']('Please wait.. (' + Browser.mainLoop.queue.length + '/' + Browser.mainLoop.blockersNum + ')'); + } else { + Module['setStatus']('Please wait..'); + } + } else { + Module['setStatus'](''); + } + } + } }, pointerLock: false, moduleContextCreatedCallbacks: [], @@ -251,7 +264,7 @@ mergeInto(LibraryManager.library, { var wrapper = function() { if (Browser.mainLoop.queue.length > 0) { Browser.mainLoop.queue.shift()(); - if (Browser.mainLoop.queue.length == 0 && Module['setStatus']) Module['setStatus'](''); + Browser.mainLoop.updateStatus(); setTimeout(wrapper, 0); return; } @@ -296,8 +309,13 @@ mergeInto(LibraryManager.library, { }, emscripten_push_main_loop_blocker: function(func) { - if (Module['setStatus']) Module['setStatus']('Please wait..'); Browser.mainLoop.queue.push(FUNCTION_TABLE[func]); + Browser.mainLoop.updateStatus(); + }, + + emscripten_set_main_loop_blockers_num: function(num) { + Browser.mainLoop.blockersNum = num; + Browser.mainLoop.updateStatus(); }, emscripten_async_call: function(func, millis) { diff --git a/system/include/emscripten/emscripten.h b/system/include/emscripten/emscripten.h index 9bc6c410..2e26bc6d 100644 --- a/system/include/emscripten/emscripten.h +++ b/system/include/emscripten/emscripten.h @@ -61,6 +61,14 @@ inline void emscripten_push_main_loop_blocker(void (*func)()) { #endif /* + * Sets the number of blockers remaining until some user-relevant + * event. This affects how we show progress. So if you set this + * to 10, then push 10 blockers, as they complete the user will + * see x/10 and so forth. + */ +extern void emscripten_set_main_loop_blockers_num(void (*func)()); + +/* * Call a C function asynchronously, that is, after returning * control to the JS event loop. This is done by a setTimeout. * When building natively this becomes a simple direct call, |