background processing

This commit is contained in:
Green Sky 2024-06-04 17:53:49 +02:00
parent b0e25627b3
commit 56f1bf559c
No known key found for this signature in database
2 changed files with 11 additions and 4 deletions

View File

@ -76,9 +76,8 @@
android:theme="@style/AppTheme"
android:hardwareAccelerated="true" >
<!-- Example of setting SDL hints from AndroidManifest.xml:
<meta-data android:name="SDL_ENV.SDL_ANDROID_TRAP_BACK_BUTTON" android:value="0"/>
-->
<!-- setting sdl hints. uses the string value -->
<meta-data android:name="SDL_ENV.SDL_ANDROID_BLOCK_ON_PAUSE" android:value="0"/>
<activity android:name="TomatoActivity"
android:label="@string/app_name"

View File

@ -106,7 +106,7 @@ int main(int argc, char** argv) {
std::unique_ptr<Screen> screen = std::make_unique<StartScreen>(args, renderer.get(), theme);
bool is_background = false;
bool quit = false;
while (!quit) {
auto new_time = std::chrono::steady_clock::now();
@ -131,6 +131,10 @@ int main(int argc, char** argv) {
if (event.type == SDL_EVENT_QUIT) {
quit = true;
break;
} else if (event.type == SDL_EVENT_WILL_ENTER_BACKGROUND) {
is_background = true;
} else if (event.type == SDL_EVENT_DID_ENTER_FOREGROUND) {
is_background = false;
}
if (screen->handleEvent(event)) {
@ -143,6 +147,10 @@ int main(int argc, char** argv) {
break;
}
if (is_background) {
render = false;
}
// can do both in the same loop
if (render) {
ImGui_ImplSDLRenderer3_NewFrame();