mGUI: Improve loading speed (fixes #1957)

This commit is contained in:
Vicki Pfau 2020-11-29 15:56:15 -08:00
parent 20f8baa82c
commit 2d6087aa98
3 changed files with 20 additions and 6 deletions

View File

@ -97,6 +97,7 @@ Misc:
- FFmpeg: Add looping option for GIF/APNG - FFmpeg: Add looping option for GIF/APNG
- mGUI: Show battery percentage - mGUI: Show battery percentage
- mGUI: Skip second scan loop when possible - mGUI: Skip second scan loop when possible
- mGUI: Improve loading speed (fixes mgba.io/i/1957)
- Qt: Renderer can be changed while a game is running - Qt: Renderer can be changed while a game is running
- Qt: Add hex index to palette view - Qt: Add hex index to palette view
- Qt: Add transformation matrix info to sprite view - Qt: Add transformation matrix info to sprite view

View File

@ -153,12 +153,23 @@ bool mCorePreloadVFCB(struct mCore* core, struct VFile* vf, void (cb)(size_t, si
vfm = VFileMemChunk(NULL, size); vfm = VFileMemChunk(NULL, size);
#endif #endif
uint8_t buffer[2048]; size_t chunkSize;
#ifdef FIXED_ROM_BUFFER
uint8_t* buffer = (uint8_t*) romBuffer;
chunkSize = 0x10000;
#else
uint8_t buffer[0x4000];
chunkSize = sizeof(buffer);
#endif
ssize_t read; ssize_t read;
size_t total = 0; size_t total = 0;
vf->seek(vf, 0, SEEK_SET); vf->seek(vf, 0, SEEK_SET);
while ((read = vf->read(vf, buffer, sizeof(buffer))) > 0) { while ((read = vf->read(vf, buffer, chunkSize)) > 0) {
#ifdef FIXED_ROM_BUFFER
buffer += read;
#else
vfm->write(vfm, buffer, read); vfm->write(vfm, buffer, read);
#endif
total += read; total += read;
if (cb) { if (cb) {
cb(total, size, context); cb(total, size, context);

View File

@ -296,10 +296,6 @@ static void _log(struct mLogger* logger, int category, enum mLogLevel level, con
static void _updateLoading(size_t read, size_t size, void* context) { static void _updateLoading(size_t read, size_t size, void* context) {
struct mGUIRunner* runner = context; struct mGUIRunner* runner = context;
if (read & 0x3FFFF) {
return;
}
runner->params.drawStart(); runner->params.drawStart();
if (runner->params.guiPrepare) { if (runner->params.guiPrepare) {
runner->params.guiPrepare(); runner->params.guiPrepare();
@ -388,7 +384,13 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) {
mInputMapInit(&runner->core->inputMap, &GBAInputInfo); mInputMapInit(&runner->core->inputMap, &GBAInputInfo);
struct VFile* rom = mDirectorySetOpenPath(&runner->core->dirs, path, runner->core->isROM); struct VFile* rom = mDirectorySetOpenPath(&runner->core->dirs, path, runner->core->isROM);
if (runner->setFrameLimiter) {
runner->setFrameLimiter(runner, false);
}
found = mCorePreloadVFCB(runner->core, rom, _updateLoading, runner); found = mCorePreloadVFCB(runner->core, rom, _updateLoading, runner);
if (runner->setFrameLimiter) {
runner->setFrameLimiter(runner, true);
}
#ifdef FIXED_ROM_BUFFER #ifdef FIXED_ROM_BUFFER
extern size_t romBufferSize; extern size_t romBufferSize;