From ab9f59e59adbbcca9cc4a15966dc5616eb2475f6 Mon Sep 17 00:00:00 2001
From: Yorick Reum <[EMAIL REDACTED]>
Date: Sat, 12 Jul 2025 11:38:49 +0200
Subject: [PATCH] Xcode-iOS/Demos/src/fireworks.c: Make rendering CPU efficient
(cherry picked from commit 6c9c2a9ac2e59259db66d802aa9e000b26ead0e5)
---
Xcode-iOS/Demos/src/fireworks.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/Xcode-iOS/Demos/src/fireworks.c b/Xcode-iOS/Demos/src/fireworks.c
index 55762bd089c46..9f444b4b2bb61 100644
--- a/Xcode-iOS/Demos/src/fireworks.c
+++ b/Xcode-iOS/Demos/src/fireworks.c
@@ -456,7 +456,10 @@ main(int argc, char *argv[])
while (!done) {
SDL_Event event;
double deltaTime = updateDeltaTime();
+ SDL_bool hasEvents = SDL_FALSE;
+
while (SDL_PollEvent(&event)) {
+ hasEvents = SDL_TRUE;
if (event.type == SDL_QUIT) {
done = 1;
}
@@ -466,10 +469,17 @@ main(int argc, char *argv[])
spawnEmitterParticle(x, y);
}
}
- stepParticles(deltaTime);
- drawParticles();
- SDL_GL_SwapWindow(window);
- SDL_Delay(1);
+
+ /* Only update and render if we have active particles or just received events */
+ if (num_active_particles > 0 || hasEvents) {
+ stepParticles(deltaTime);
+ drawParticles();
+ SDL_GL_SwapWindow(window);
+ SDL_Delay(16); // Target 60 FPS when active
+ } else {
+ /* Idle state - wait for events with longer delay to save CPU */
+ SDL_Delay(100); // Much longer delay when idle
+ }
}
/* delete textures */