mirror of https://github.com/mgba-emu/mgba.git
GUI: Cache savestate icons
This commit is contained in:
parent
cb8d60e211
commit
2cf6c73d7d
|
@ -44,8 +44,16 @@ static void _drawState(struct GUIBackground* background, void* id) {
|
||||||
struct GBAGUIBackground* gbaBackground = (struct GBAGUIBackground*) background;
|
struct GBAGUIBackground* gbaBackground = (struct GBAGUIBackground*) background;
|
||||||
int stateId = ((int) id) >> 16;
|
int stateId = ((int) id) >> 16;
|
||||||
if (gbaBackground->p->drawScreenshot) {
|
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);
|
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;
|
bool success = false;
|
||||||
if (vf && isPNG(vf) && pixels) {
|
if (vf && isPNG(vf) && pixels) {
|
||||||
png_structp png = PNGReadOpen(vf, PNG_HEADER_BYTES);
|
png_structp png = PNGReadOpen(vf, PNG_HEADER_BYTES);
|
||||||
|
@ -63,12 +71,10 @@ static void _drawState(struct GUIBackground* background, void* id) {
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
gbaBackground->p->drawScreenshot(gbaBackground->p, pixels, true);
|
gbaBackground->p->drawScreenshot(gbaBackground->p, pixels, true);
|
||||||
|
gbaBackground->screenshotId = (int) id;
|
||||||
} else if (gbaBackground->p->drawFrame) {
|
} else if (gbaBackground->p->drawFrame) {
|
||||||
gbaBackground->p->drawFrame(gbaBackground->p, true);
|
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 = {
|
.d = {
|
||||||
.draw = _drawState
|
.draw = _drawState
|
||||||
},
|
},
|
||||||
.p = runner
|
.p = runner,
|
||||||
|
.screenshot = 0,
|
||||||
|
.screenshotId = 0
|
||||||
};
|
};
|
||||||
struct GUIMenu pauseMenu = {
|
struct GUIMenu pauseMenu = {
|
||||||
.title = "Game Paused",
|
.title = "Game Paused",
|
||||||
|
@ -165,8 +173,7 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
|
||||||
if (runner->params.guiFinish) {
|
if (runner->params.guiFinish) {
|
||||||
runner->params.guiFinish();
|
runner->params.guiFinish();
|
||||||
}
|
}
|
||||||
GUIMenuItemListDeinit(&pauseMenu.items);
|
break;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runner->params.guiPrepare) {
|
if (runner->params.guiPrepare) {
|
||||||
|
@ -272,6 +279,10 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
|
||||||
runner->gameUnloaded(runner);
|
runner->gameUnloaded(runner);
|
||||||
}
|
}
|
||||||
GBAContextUnloadROM(&runner->context);
|
GBAContextUnloadROM(&runner->context);
|
||||||
|
drawState.screenshotId = 0;
|
||||||
|
}
|
||||||
|
if (drawState.screenshot) {
|
||||||
|
mappedMemoryFree(drawState.screenshot, VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4);
|
||||||
}
|
}
|
||||||
GUIMenuItemListDeinit(&pauseMenu.items);
|
GUIMenuItemListDeinit(&pauseMenu.items);
|
||||||
GUIMenuItemListDeinit(&stateSaveMenu.items);
|
GUIMenuItemListDeinit(&stateSaveMenu.items);
|
||||||
|
|
|
@ -17,6 +17,9 @@ enum GBAGUIInput {
|
||||||
struct GBAGUIBackground {
|
struct GBAGUIBackground {
|
||||||
struct GUIBackground d;
|
struct GUIBackground d;
|
||||||
struct GBAGUIRunner* p;
|
struct GBAGUIRunner* p;
|
||||||
|
|
||||||
|
uint32_t* screenshot;
|
||||||
|
int screenshotId;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GBAGUIRunnerLux {
|
struct GBAGUIRunnerLux {
|
||||||
|
|
Loading…
Reference in New Issue