Fix blitting

This commit is contained in:
Varun Patil 2020-10-20 03:48:31 +05:30
parent 8ff0e868ca
commit 04dc678014
4 changed files with 19 additions and 8 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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

View File

@ -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