GUI: Cache savestate icons

This commit is contained in:
Jeffrey Pfau 2015-09-03 02:25:16 -07:00
parent cb8d60e211
commit 2cf6c73d7d
2 changed files with 21 additions and 7 deletions

View File

@ -44,8 +44,16 @@ static void _drawState(struct GUIBackground* background, void* id) {
struct GBAGUIBackground* gbaBackground = (struct GBAGUIBackground*) background;
int stateId = ((int) id) >> 16;
if (gbaBackground->p->drawScreenshot) {
if (gbaBackground->screenshot && gbaBackground->screenshotId == (int) id) {
gbaBackground->p->drawScreenshot(gbaBackground->p, gbaBackground->screenshot, true);
return;
}
struct VFile* vf = GBAGetState(gbaBackground->p->context.gba, 0, stateId, false);
uint32_t* pixels = anonymousMemoryMap(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4);
uint32_t* pixels = gbaBackground->screenshot;
if (!pixels) {
pixels = anonymousMemoryMap(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4);
gbaBackground->screenshot = pixels;
}
bool success = false;
if (vf && isPNG(vf) && pixels) {
png_structp png = PNGReadOpen(vf, PNG_HEADER_BYTES);
@ -63,12 +71,10 @@ static void _drawState(struct GUIBackground* background, void* id) {
}
if (success) {
gbaBackground->p->drawScreenshot(gbaBackground->p, pixels, true);
gbaBackground->screenshotId = (int) id;
} else if (gbaBackground->p->drawFrame) {
gbaBackground->p->drawFrame(gbaBackground->p, true);
}
if (pixels) {
mappedMemoryFree(pixels, VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4);
}
}
}
@ -111,7 +117,9 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
.d = {
.draw = _drawState
},
.p = runner
.p = runner,
.screenshot = 0,
.screenshotId = 0
};
struct GUIMenu pauseMenu = {
.title = "Game Paused",
@ -165,8 +173,7 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
if (runner->params.guiFinish) {
runner->params.guiFinish();
}
GUIMenuItemListDeinit(&pauseMenu.items);
return;
break;
}
if (runner->params.guiPrepare) {
@ -272,6 +279,10 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
runner->gameUnloaded(runner);
}
GBAContextUnloadROM(&runner->context);
drawState.screenshotId = 0;
}
if (drawState.screenshot) {
mappedMemoryFree(drawState.screenshot, VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4);
}
GUIMenuItemListDeinit(&pauseMenu.items);
GUIMenuItemListDeinit(&stateSaveMenu.items);

View File

@ -17,6 +17,9 @@ enum GBAGUIInput {
struct GBAGUIBackground {
struct GUIBackground d;
struct GBAGUIRunner* p;
uint32_t* screenshot;
int screenshotId;
};
struct GBAGUIRunnerLux {