-
Should I block the following infinite loop when the application does not need to process any event or animation? bool running = true;
while (running)
{
// Handle input and window events.
running = Backend::ProcessEvents(context, &Shell::ProcessKeyDownShortcuts);
//......
} I just want to reduce CPU cust. SFML use sf::Event event;
while (window.waitEvent(event)) //waitEvent
{
if (event.type == sf::Event::Closed)
window.close();
window.clear();
window.draw(shape);
window.display();
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Yeah, I would suggest that you try it out and see how it goes. You can simply test it by modifying the SFML backend, it would just be a matter of swapping out the RmlUi/Backends/RmlUi_Backend_SFML_GL2.cpp Line 201 in 1b1a882 You could implement the same functionality in any of the other backends too. That will be platform specific, so you will have to look up how to do it for your platform (or see how SFML implements it). Now, this clearly wouldn't work for example if you have animations playing. Then you would have to run the loop regardless of events. There could be other situations like this, like when you manually want to update the DOM. |
Beta Was this translation helpful? Give feedback.
-
I think you'll be happy to see that this feature is now integrated into RmlUi, through the pull request #436 (thanks @Thalhammer). 🥳 This will be included in the next release of RmlUi. For example, on the SDL platform, you can now poll for events like shown here: RmlUi/Backends/RmlUi_Backend_SDL_GL2.cpp Line 266 in 801b239 We couldn't integrate this into the SFML platform, since the library seems to lack a timeout version of waitEvent, but please check out the other platforms. For usage on other platforms, check the pull request or backends source code. Documentation is being updated. |
Beta Was this translation helpful? Give feedback.
Yeah, I would suggest that you try it out and see how it goes. You can simply test it by modifying the SFML backend, it would just be a matter of swapping out the
pollEvent
withwaitEvent
here:RmlUi/Backends/RmlUi_Backend_SFML_GL2.cpp
Line 201 in 1b1a882
You could implement the same functionality in any of the other backends too. That will be platform specific, so you will have to look up how to do it for your platform (or see how SFML implements it).
Now, this clearly wouldn't work for example if you have animations playing. Then you would have to run the loop regardless of events. There could be other situations like this, like when …