Remove preloading progress, load wasm

This commit is contained in:
Varun Patil 2020-05-07 15:29:30 +05:30
parent 30c4b1d594
commit 00ccbf5db9
2 changed files with 22 additions and 10 deletions

View File

@ -217,13 +217,10 @@
const url = mapping[f.toLowerCase().replace(new RegExp("\\.[^/.]+$"), "")]; const url = mapping[f.toLowerCase().replace(new RegExp("\\.[^/.]+$"), "")];
if (!url) return; if (!url) return;
// Get filename // Preload the asset
let filename = url.split('?')[0]; setTimeout(() => {
filename = filename.split('/'); fetch('gameasync/' + url).then().catch();
filename = filename[filename.length -1]; }, 1000);
// Preload asset
getLazyAsset('gameasync/' + url, filename, () => {});
}); });
}); });
}; };
@ -238,7 +235,6 @@
if (xhr.readyState == XMLHttpRequest.DONE) { if (xhr.readyState == XMLHttpRequest.DONE) {
pdiv.innerHTML = `${filename} - done`; pdiv.innerHTML = `${filename} - done`;
hideTimer = setTimeout(() => { hideTimer = setTimeout(() => {
window.setNotBusy();
pdiv.style.opacity = '0'; pdiv.style.opacity = '0';
hideTimer = 0; hideTimer = 0;
}, 500); }, 500);
@ -255,9 +251,10 @@
xhr.open('GET', url); xhr.open('GET', url);
xhr.send(); xhr.send();
pdiv.innerHTML = `${filename} - starting`;
showTimer = setTimeout(() => { showTimer = setTimeout(() => {
pdiv.style.opacity = '0.5'; pdiv.style.opacity = '0.5';
window.setBusy();
}, 100); }, 100);
if (hideTimer) { if (hideTimer) {
@ -267,6 +264,17 @@
} }
</script> </script>
{{{ SCRIPT }}} <script>
// Load wasm then initialize
setTimeout(() => {
getLazyAsset('mkxp.wasm', 'Game engine', () => {
const s = document.createElement('script');
s.setAttribute('src', 'mkxp.js');
document.body.appendChild(s);
});
}, 500);
</script>
<!-- {{{ SCRIPT }}} -->
</body> </body>
</html> </html>

View File

@ -13,6 +13,9 @@ EM_JS(void, load_file_async_js, (const char* fullPathC), {
// Check if already loaded // Check if already loaded
if (window.fileAsyncCache.hasOwnProperty(fullPath)) return wakeUp(); if (window.fileAsyncCache.hasOwnProperty(fullPath)) return wakeUp();
// Show spinner
if (window.setBusy) window.setBusy();
// Get mapping key // Get mapping key
const mappingKey = fullPath.toLowerCase().replace(new RegExp("\\\\.[^/.]+$"), ""); const mappingKey = fullPath.toLowerCase().replace(new RegExp("\\\\.[^/.]+$"), "");
const mappingValue = mapping[mappingKey]; const mappingValue = mapping[mappingKey];
@ -39,6 +42,7 @@ EM_JS(void, load_file_async_js, (const char* fullPathC), {
getLazyAsset(iurl, filename, () => { getLazyAsset(iurl, filename, () => {
FS.createPreloadedFile(path, filename, iurl, true, true, function() { FS.createPreloadedFile(path, filename, iurl, true, true, function() {
window.fileAsyncCache[fullPath] = 1; window.fileAsyncCache[fullPath] = 1;
if (window.setNotBusy) window.setNotBusy();
if (window.fileLoadedAsync) window.fileLoadedAsync(fullPath); if (window.fileLoadedAsync) window.fileLoadedAsync(fullPath);
wakeUp(); wakeUp();
}, console.error); }, console.error);