Use the new common RunMainLoop on Android

This commit is contained in:
Henrik Rydgård
2026-07-26 13:42:16 +02:00
parent 4a95d8eeaa
commit 8020b60dda
3 changed files with 41 additions and 54 deletions
+31 -31
View File
@@ -70,7 +70,6 @@ static void EmuThreadFunc(GraphicsContext *graphicsContext, Application *applica
// This normally calls NativeShutdownGraphics()
application->ShutdownGraphics(graphicsContext);
delete application;
INFO_LOG(Log::System, "Leaving separate emu thread");
@@ -102,6 +101,36 @@ void EmuThread_Join(GraphicsContext *graphicsContext, std::thread &emuThread) {
emuThread = std::thread();
}
bool RunMainLoop(GraphicsContext *graphicsContext, Application *application, std::function<bool()> runCondition, std::function<void()> postFrame) {
// This is the main thread. the graphics contexts will spawn and handle its own threads if needed.
// InitFromRenderThread/ShutdownFromRenderThread are not used.
application->InitGraphics(graphicsContext);
// NativeResized();
DEBUG_LOG(Log::Boot, "Done.");
g_inLoop = true;
while (runCondition()) {
// We're here again, so the game quit. Restart Run() which controls the UI.
// This way they can load a new game.
application->Frame(graphicsContext);
postFrame();
}
Core_Stop();
// Process the shutdown. Without this, non-GL delays 800ms on shutdown.
Core_StateProcessed();
application->Frame(graphicsContext);
g_inLoop = false;
application->ShutdownGraphics(graphicsContext);
delete application;
return true;
}
// Call InitAPI and ShutdownAPI outside this!
bool MainThreadFunc(GraphicsContext *graphicsContext, Application *application, WindowSystem windowSystem, void *windowData1, void *windowData2, std::function<void()> postFrame) {
// This is now the render thread, and will spawn the emu thread below.
@@ -143,36 +172,7 @@ bool MainThreadFunc(GraphicsContext *graphicsContext, Application *application,
} else {
SetCurrentThreadName("MainThread");
// This is the main thread. the graphics contexts will spawn and handle its own threads if needed.
// InitFromRenderThread/ShutdownFromRenderThread are not used.
std::string error_string;
application->InitGraphics(graphicsContext);
// NativeResized();
DEBUG_LOG(Log::Boot, "Done.");
g_inLoop = true;
graphicsContext->ThreadStart();
while (GetUIState() != UISTATE_EXIT) {
// We're here again, so the game quit. Restart Run() which controls the UI.
// This way they can load a new game.
application->Frame(graphicsContext);
postFrame();
}
Core_Stop();
// Process the shutdown. Without this, non-GL delays 800ms on shutdown.
Core_StateProcessed();
application->Frame(graphicsContext);
g_inLoop = false;
application->ShutdownGraphics(graphicsContext);
graphicsContext->ThreadEnd();
RunMainLoop(graphicsContext, application, []() { return GetUIState() != UISTATE_EXIT; }, postFrame);
}
graphicsContext->ShutdownSurface();