glfwWaitEvents (and glfwWaitEventsTimeout) which only return if GLFW events are encountered (or timeout) #2792
+105
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a draft PR with a fix for issues #685, #1911 and #2600 which works by only returning from the wait if either a GLFW relevant event is encountered or the timeout is reached if set.
Current status of backends
I do not have a Mac machine at the moment as mine has died, but I will see about using an online remote desktop service to implement the Cocoa branch if this PR architecture is deemed suitable.
Design
This PR adds a boolean
newEventsRcvdto the_glfwglobal struct. This is set toGLFW_FALSEat the start of a poll/wait event call, and set toGLFW_TRUEif a GLFW relevant event is received, including one from aglfwPostEmptyEvent. The majority of the code fornewEventsRcvdstate management is in cross platform code.Each platform adds a loop to the 2 wait event calls, reducing the timeout by the passage of time where required (note to self: POSIX implementation may need timeout adjustment). This code could potentially be moved to the cross platform code.
Each platform needs to handle the
glfwPostEmptyEventon the same thread as theglfwWaitEvents*call (the main thread by design).wl_display_syncdisplay sync donedrainEmptyEventspipe functionWM_NULLcase to the helper window procedureNSApplicationDefinedNSEventfor this.Questions
uint32_toruint64_tevent counter?2a. Should this be a global event counter or reset every event loop?
2b. With atomics it might actually be possible to move the entire implementation to cross platform code. Whilst C99 does not have atomic integers I am well versed in their cross platform implementation and can add these if needed.
TODO
See Contributing a bug fix documentation for general requirements for a bug fix contribution, and if we add functions to control/query this then also the feature list.