From 04dc67801437c5dcc652453272e5d9ade5769ace Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 20 Oct 2020 03:48:31 +0530 Subject: [PATCH] Fix blitting --- extra/js/drive.js | 14 ++++++-------- src/bitmap.cpp | 7 +++++++ src/emscripten.cpp | 4 ++++ src/emscripten.hpp | 2 ++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/extra/js/drive.js b/extra/js/drive.js index 78b0e76..43e571e 100644 --- a/extra/js/drive.js +++ b/extra/js/drive.js @@ -55,24 +55,20 @@ window.loadFileAsync = function(fullPath, bitmap, callback) { // Main loading function const load = (cb1) => { getLazyAsset(iurl, filename, (data) => { - // Delete original file if existent - try { FS.unlink(path + "/" + filename); } catch (err) {} - FS.createPreloadedFile(path, filename, new Uint8Array(data), true, true, function() { window.fileAsyncCache[fullPath] = 1; if (!bitmap && window.setNotBusy) window.setNotBusy(); if (window.fileLoadedAsync) window.fileLoadedAsync(fullPath); callback(); if (cb1) cb1(); - }, console.error); + }, console.error, false, false, () => { + try { FS.unlink(path + "/" + filename); } catch (err) {} + }); }); } // Show progress if doing it synchronously only if (bitmap && bitmapSizeMapping[mappingKey]) { - // Remove existing file - try { FS.unlink(path + "/" + filename); } catch (err) {} - // Get image const sm = bitmapSizeMapping[mappingKey]; generationCanvas.width = sm[0]; @@ -88,7 +84,9 @@ window.loadFileAsync = function(fullPath, bitmap, callback) { const reloadBitmap = Module.cwrap('reloadBitmap', 'number', ['number']) reloadBitmap(bitmap); }); - }, console.error); + }, console.error, false, false, () => { + try { FS.unlink(path + "/" + filename); } catch (err) {} + }); } else { if (bitmap) { console.warn('No sizemap for image', mappingKey); diff --git a/src/bitmap.cpp b/src/bitmap.cpp index 51f570f..6a7696d 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -422,6 +422,13 @@ void Bitmap::stretchBlt(const IntRect &destRect, if (opacity == 0) return; +#if __EMSCRIPTEN__ + if (strlen(source.filename) > 0 && !file_is_cached(source.filename)) { + load_file_async_js(source.filename); + ((Bitmap*)(&source))->loadFromFilename(); + } +#endif + SDL_Surface *srcSurf = source.megaSurface(); if (srcSurf && shState->config().subImageFix) diff --git a/src/emscripten.cpp b/src/emscripten.cpp index af98cc8..1061047 100644 --- a/src/emscripten.cpp +++ b/src/emscripten.cpp @@ -12,5 +12,9 @@ EM_JS(void, save_file_async_js, (const char* fullPathC), { if (window.saveFile) window.saveFile(UTF8ToString(fullPathC)); }); +EM_JS(int, file_is_cached, (const char* fullPathC), { + return window.fileAsyncCache.hasOwnProperty(UTF8ToString(fullPathC)) ? 1 : 0; +}); + #endif diff --git a/src/emscripten.hpp b/src/emscripten.hpp index 57c38a1..254f6b6 100644 --- a/src/emscripten.hpp +++ b/src/emscripten.hpp @@ -8,6 +8,8 @@ extern "C" { void load_file_async_js(const char* fullPathC, int bitmap=0); void save_file_async_js(const char* fullPathC); + + int file_is_cached(const char* fullPathC); } #endif