mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-12 06:18:13 +00:00
Xcode-iOS/Demos/src/fireworks.c: Make rendering CPU efficient
(cherry picked from commit 6c9c2a9ac2
)
This commit is contained in:

committed by
Sam Lantinga

parent
f99f57ffd1
commit
ab9f59e59a
@@ -456,7 +456,10 @@ main(int argc, char *argv[])
|
|||||||
while (!done) {
|
while (!done) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
double deltaTime = updateDeltaTime();
|
double deltaTime = updateDeltaTime();
|
||||||
|
SDL_bool hasEvents = SDL_FALSE;
|
||||||
|
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
|
hasEvents = SDL_TRUE;
|
||||||
if (event.type == SDL_QUIT) {
|
if (event.type == SDL_QUIT) {
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
@@ -466,10 +469,17 @@ main(int argc, char *argv[])
|
|||||||
spawnEmitterParticle(x, y);
|
spawnEmitterParticle(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stepParticles(deltaTime);
|
|
||||||
drawParticles();
|
/* Only update and render if we have active particles or just received events */
|
||||||
SDL_GL_SwapWindow(window);
|
if (num_active_particles > 0 || hasEvents) {
|
||||||
SDL_Delay(1);
|
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 */
|
/* delete textures */
|
||||||
|
Reference in New Issue
Block a user