From 00ccbf5db9e764d40633e4ce74bea607e2d5e44f Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Thu, 7 May 2020 15:29:30 +0530 Subject: [PATCH] Remove preloading progress, load wasm --- shell.html | 28 ++++++++++++++++++---------- src/emscripten.cpp | 4 ++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/shell.html b/shell.html index 298f353..42709f6 100644 --- a/shell.html +++ b/shell.html @@ -217,13 +217,10 @@ const url = mapping[f.toLowerCase().replace(new RegExp("\\.[^/.]+$"), "")]; if (!url) return; - // Get filename - let filename = url.split('?')[0]; - filename = filename.split('/'); - filename = filename[filename.length -1]; - - // Preload asset - getLazyAsset('gameasync/' + url, filename, () => {}); + // Preload the asset + setTimeout(() => { + fetch('gameasync/' + url).then().catch(); + }, 1000); }); }); }; @@ -238,7 +235,6 @@ if (xhr.readyState == XMLHttpRequest.DONE) { pdiv.innerHTML = `${filename} - done`; hideTimer = setTimeout(() => { - window.setNotBusy(); pdiv.style.opacity = '0'; hideTimer = 0; }, 500); @@ -255,9 +251,10 @@ xhr.open('GET', url); xhr.send(); + pdiv.innerHTML = `${filename} - starting`; + showTimer = setTimeout(() => { pdiv.style.opacity = '0.5'; - window.setBusy(); }, 100); if (hideTimer) { @@ -267,6 +264,17 @@ } - {{{ SCRIPT }}} + + + diff --git a/src/emscripten.cpp b/src/emscripten.cpp index 21b81ec..5a8dd8e 100644 --- a/src/emscripten.cpp +++ b/src/emscripten.cpp @@ -13,6 +13,9 @@ EM_JS(void, load_file_async_js, (const char* fullPathC), { // Check if already loaded if (window.fileAsyncCache.hasOwnProperty(fullPath)) return wakeUp(); + // Show spinner + if (window.setBusy) window.setBusy(); + // Get mapping key const mappingKey = fullPath.toLowerCase().replace(new RegExp("\\\\.[^/.]+$"), ""); const mappingValue = mapping[mappingKey]; @@ -39,6 +42,7 @@ EM_JS(void, load_file_async_js, (const char* fullPathC), { getLazyAsset(iurl, filename, () => { FS.createPreloadedFile(path, filename, iurl, true, true, function() { window.fileAsyncCache[fullPath] = 1; + if (window.setNotBusy) window.setNotBusy(); if (window.fileLoadedAsync) window.fileLoadedAsync(fullPath); wakeUp(); }, console.error);