-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wait-event-timeout main loop modification #4133
Comments
Thank you for your comment, you are correctly pointing out a real problem with the modification I proposed. On the other side my proposition was just meant to show an idea and it is not a complete solution to be used in a real applications as it is. In my application, lite-xl I found the following approach to be optimal:
With (1) the cursor keeps blinking and animations can run smoothly and with (2) we reduce CPU usage to zero as it should be when the window is unfocused or reduced to icon. As for the animations, my application, lite-xl, has them and they run smoothly. The key is that the application has a flag and when the application needs to redraw, for example because there are some animations running, we set the redraw flag. In turns the main loop looks at the redraw flag and keep running the frames as long as the flag is on. So, I mean that probably each application should come up with some application specific-logic to decide if it is ok to stop and wait for events or not. I am just wondering if this kind of logic can be backed directly in imgui in a generic way. For this we would need to have some flag that tells us if the application drawing is changing or not. I think really ImGui can be used also for some desktop applications with these kind of adjustments, it doesn't need to be limited to game applications. On the other side the game developers tends to completely disregards these kind of details because these are not really an issue for games, they just want to run at a fixed framerate anyway. |
This is not a real issue but something I would like to discuss and double-check with the imgui developers and users.
Proposition to discuss
Here the modification I made to the SDL/opengl3 example. The purpose is to let the demo application wait on event and stop using the CPU.
Context / SDL2 issue
I am the author of a patch of the SDL2 library with the purpose to reduce CPU usage to zero when waiting for an incoming event. Here the PR (not accepted neither refused up to now):
libsdl-org/SDL#4180
The patch is meant for desktop applications that use SDL2. The SDL2 library internally continuously polls for events even when WaitEvent or WaitEventTimeout is used. This cause continuous CPU usage even when a desktop applications is idle waiting for incoming events. My patch fix this so that the functions WaitEvent/WaitEventTimeout actually wait for events instead of polling.
I am successfully using the modified SDL library for my applications lite-xl
Discussion
You may notice that I use a variable idle_frames to check for how many frames the applications was running idle without events. The idea is that when an event arrives we want to let the application process at least a few frames before blocking the application waiting for events.
I found empirically the imgui needs a few frames to make some transitions in the UI but I would appreciate to have a confirmation if I am correct or not.
If the variable config_fps is set to -1000 it waits indefinitely for events. To run at a fixed FPS the value should be set to the desired FPS value but no attempt is made to account for the elapsed time and correct the waiting time.
I am asking to @ocornut and other imgui users or contributors is they can validated the correctness of the modified loop I am using.
I don't mean the modification should be included into the imgui library.
The text was updated successfully, but these errors were encountered: