mGUI: Skip second scan loop when possible

This commit is contained in:
Vicki Pfau 2020-11-26 22:33:05 -08:00
parent 0d96ba4f8f
commit 7640c38684
2 changed files with 52 additions and 50 deletions

View File

@ -92,6 +92,7 @@ Misc:
- Debugger: Keep track of global cycle count - Debugger: Keep track of global cycle count
- 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
- 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

@ -89,6 +89,8 @@ static bool _refreshDirectory(struct GUIParams* params, const char* currentPath,
char* n2 = malloc(len); char* n2 = malloc(len);
snprintf(n2, len, "%s/", name); snprintf(n2, len, "%s/", name);
name = n2; name = n2;
} else if (filterName && !filterName(name)) {
continue;
} else { } else {
name = strdup(name); name = strdup(name);
} }
@ -96,59 +98,58 @@ static bool _refreshDirectory(struct GUIParams* params, const char* currentPath,
++items; ++items;
} }
qsort(GUIMenuItemListGetPointer(currentFiles, 1), GUIMenuItemListSize(currentFiles) - 1, sizeof(struct GUIMenuItem), _strpcmp); qsort(GUIMenuItemListGetPointer(currentFiles, 1), GUIMenuItemListSize(currentFiles) - 1, sizeof(struct GUIMenuItem), _strpcmp);
i = 0; if (preselect || filterContents) {
size_t item = 0; i = 0;
while (item < GUIMenuItemListSize(currentFiles)) { size_t item = 0;
++i; while (item < GUIMenuItemListSize(currentFiles)) {
if (!(i % SCANNING_THRESHOLD_2)) { ++i;
uint32_t input = 0; // If we're not filtering the contents, this loop is fast, so there's no need to show updates
GUIPollInput(params, &input, 0); if (filterContents && !(i % SCANNING_THRESHOLD_2)) {
if (input & (1 << GUI_INPUT_CANCEL)) { uint32_t input = 0;
dir->close(dir); GUIPollInput(params, &input, 0);
return false; if (input & (1 << GUI_INPUT_CANCEL)) {
} dir->close(dir);
return false;
params->drawStart();
if (params->guiPrepare) {
params->guiPrepare();
}
GUIFontPrintf(params->font, 0, GUIFontHeight(params->font), GUI_ALIGN_LEFT, 0xFFFFFFFF, "(scanning item %"PRIz"u of %"PRIz"u)", i, items);
GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_ALIGN_LEFT, 0xFFFFFFFF, "%s", currentPath);
if (params->guiFinish) {
params->guiFinish();
}
params->drawEnd();
}
struct GUIMenuItem* testItem = GUIMenuItemListGetPointer(currentFiles, item);
if (testItem->data != (void*) VFS_FILE) {
++item;
continue;
}
bool failed = false;
if (filterName && !filterName(testItem->title)) {
failed = true;
}
if (!failed && filterContents) {
struct VFile* vf = dir->openFile(dir, testItem->title, O_RDONLY);
if (!vf) {
failed = true;
} else {
if (!filterContents(vf)) {
failed = true;
} }
vf->close(vf);
}
}
if (failed) { params->drawStart();
free((char*) testItem->title); if (params->guiPrepare) {
GUIMenuItemListShift(currentFiles, item, 1); params->guiPrepare();
} else { }
if (preselect && strncmp(testItem->title, preselect, PATH_MAX) == 0) { GUIFontPrintf(params->font, 0, GUIFontHeight(params->font), GUI_ALIGN_LEFT, 0xFFFFFFFF, "(scanning item %"PRIz"u of %"PRIz"u)", i, items);
params->fileIndex = item; GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_ALIGN_LEFT, 0xFFFFFFFF, "%s", currentPath);
if (params->guiFinish) {
params->guiFinish();
}
params->drawEnd();
}
struct GUIMenuItem* testItem = GUIMenuItemListGetPointer(currentFiles, item);
if (testItem->data != (void*) VFS_FILE) {
++item;
continue;
}
bool failed = false;
if (filterContents) {
struct VFile* vf = dir->openFile(dir, testItem->title, O_RDONLY);
if (!vf) {
failed = true;
} else {
if (!filterContents(vf)) {
failed = true;
}
vf->close(vf);
}
}
if (failed) {
free((char*) testItem->title);
GUIMenuItemListShift(currentFiles, item, 1);
} else {
if (preselect && strncmp(testItem->title, preselect, PATH_MAX) == 0) {
params->fileIndex = item;
}
++item;
} }
++item;
} }
} }
dir->close(dir); dir->close(dir);