glfw: add glfw.waitEvents, glfw.waitEventsTimeout

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-10-16 18:20:16 -07:00 committed by Stephen Gutekanst
parent 45195bd21c
commit 66678f1df0

View file

@ -157,85 +157,79 @@ pub inline fn pollEvents() Error!void {
try getError(); try getError();
} }
// /// Waits until events are queued and processes them. /// Waits until events are queued and processes them.
// /// ///
// /// This function puts the calling thread to sleep until at least one event is /// This function puts the calling thread to sleep until at least one event is available in the
// /// available in the event queue. Once one or more events are available, /// event queue. Once one or more events are available, it behaves exactly like glfw.pollEvents,
// /// it behaves exactly like @ref glfwPollEvents, i.e. the events in the queue /// i.e. the events in the queue are processed and the function then returns immediately.
// /// are processed and the function then returns immediately. Processing events /// Processing events will cause the window and input callbacks associated with those events to be
// /// will cause the window and input callbacks associated with those events to be /// called.
// /// called. ///
// /// /// Since not all events are associated with callbacks, this function may return without a callback
// /// Since not all events are associated with callbacks, this function may return /// having been called even if you are monitoring all callbacks.
// /// without a callback having been called even if you are monitoring all ///
// /// callbacks. /// On some platforms, a window move, resize or menu operation will cause event processing to
// /// /// block. This is due to how event processing is designed on those platforms. You can use the
// /// On some platforms, a window move, resize or menu operation will cause event /// window refresh callback (see window_refresh) to redraw the contents of your window when
// /// processing to block. This is due to how event processing is designed on /// necessary during such operations.
// /// those platforms. You can use the ///
// /// [window refresh callback](@ref window_refresh) to redraw the contents of /// Do not assume that callbacks you set will _only_ be called in response to event processing
// /// your window when necessary during such operations. /// functions like this one. While it is necessary to poll for events, window systems that require
// /// /// GLFW to register callbacks of its own can pass events to GLFW in response to many window system
// /// Do not assume that callbacks you set will _only_ be called in response to /// function calls. GLFW will pass those events on to the application callbacks before returning.
// /// event processing functions like this one. While it is necessary to poll for ///
// /// events, window systems that require GLFW to register callbacks of its own /// Event processing is not required for joystick input to work.
// /// can pass events to GLFW in response to many window system function calls. ///
// /// GLFW will pass those events on to the application callbacks before /// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
// /// returning. ///
// /// /// @reentrancy This function must not be called from a callback.
// /// Event processing is not required for joystick input to work. ///
// /// /// @thread_safety This function must only be called from the main thread.
// /// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError. ///
// /// /// see also: events, glfw.pollEvents, glfw.waitEventsTimeout
// /// @reentrancy This function must not be called from a callback. pub inline fn waitEvents() Error!void {
// /// c.glfwWaitEvents();
// /// @thread_safety This function must only be called from the main thread. try getError();
// /// }
// /// see also: events, glfw.pollEvents, glfw.waitEventsTimeout
// ///
// GLFWAPI void glfwWaitEvents(void);
// /// Waits with timeout until events are queued and processes them. /// Waits with timeout until events are queued and processes them.
// /// ///
// /// This function puts the calling thread to sleep until at least one event is /// This function puts the calling thread to sleep until at least one event is available in the
// /// available in the event queue, or until the specified timeout is reached. If /// event queue, or until the specified timeout is reached. If one or more events are available, it
// /// one or more events are available, it behaves exactly like @ref /// behaves exactly like glfw.pollEvents, i.e. the events in the queue are processed and the
// /// glfwPollEvents, i.e. the events in the queue are processed and the function /// function then returns immediately. Processing events will cause the window and input callbacks
// /// then returns immediately. Processing events will cause the window and input /// associated with those events to be called.
// /// callbacks associated with those events to be called. ///
// /// /// The timeout value must be a positive finite number.
// /// The timeout value must be a positive finite number. ///
// /// /// Since not all events are associated with callbacks, this function may return without a callback
// /// Since not all events are associated with callbacks, this function may return /// having been called even if you are monitoring all callbacks.
// /// without a callback having been called even if you are monitoring all ///
// /// callbacks. /// On some platforms, a window move, resize or menu operation will cause event processing to
// /// /// block. This is due to how event processing is designed on those platforms. You can use the
// /// On some platforms, a window move, resize or menu operation will cause event /// window refresh callback (see window_refresh) to redraw the contents of your window when
// /// processing to block. This is due to how event processing is designed on /// necessary during such operations.
// /// those platforms. You can use the ///
// /// [window refresh callback](@ref window_refresh) to redraw the contents of /// Do not assume that callbacks you set will _only_ be called in response to event processing
// /// your window when necessary during such operations. /// functions like this one. While it is necessary to poll for events, window systems that require
// /// /// GLFW to register callbacks of its own can pass events to GLFW in response to many window system
// /// Do not assume that callbacks you set will _only_ be called in response to /// function calls. GLFW will pass those events on to the application callbacks before returning.
// /// event processing functions like this one. While it is necessary to poll for ///
// /// events, window systems that require GLFW to register callbacks of its own /// Event processing is not required for joystick input to work.
// /// can pass events to GLFW in response to many window system function calls. ///
// /// GLFW will pass those events on to the application callbacks before /// @param[in] timeout The maximum amount of time, in seconds, to wait.
// /// returning. ///
// /// /// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidValue and glfw.Error.PlatformError.
// /// Event processing is not required for joystick input to work. ///
// /// /// @reentrancy This function must not be called from a callback.
// /// @param[in] timeout The maximum amount of time, in seconds, to wait. ///
// /// /// @thread_safety This function must only be called from the main thread.
// /// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidValue and glfw.Error.PlatformError. ///
// /// /// see also: events, glfw.pollEvents, glfw.waitEvents
// /// @reentrancy This function must not be called from a callback. pub inline fn waitEventsTimeout(timeout: f64) Error!void {
// /// c.glfwWaitEventsTimeout(timeout);
// /// @thread_safety This function must only be called from the main thread. try getError();
// /// }
// /// see also: events, glfw.pollEvents, glfw.waitEvents
// ///
// GLFWAPI void glfwWaitEventsTimeout(double timeout);
// /// Posts an empty event to the event queue. // /// Posts an empty event to the event queue.
// /// // ///
@ -287,6 +281,13 @@ test "pollEvents" {
try pollEvents(); try pollEvents();
} }
test "waitEventsTimeout" {
try init();
defer terminate();
try waitEventsTimeout(0.25);
}
test "basic" { test "basic" {
try basicTest(); try basicTest();
} }