Add a loop tick callback
This commit is contained in:
parent
1902d8bb19
commit
d593ccba2f
8 changed files with 54 additions and 8 deletions
4
glfw/glfw3.h
vendored
4
glfw/glfw3.h
vendored
|
|
@ -1510,6 +1510,7 @@ typedef void (* GLFWmonitorfun)(GLFWmonitor*,int);
|
|||
typedef void (* GLFWjoystickfun)(int,int);
|
||||
|
||||
typedef void (* GLFWuserdatafun)(unsigned long long, void*);
|
||||
typedef void (* GLFWtickcallback)(void*);
|
||||
|
||||
/*! @brief Video mode type.
|
||||
*
|
||||
|
|
@ -1657,8 +1658,9 @@ typedef struct GLFWgamepadstate
|
|||
* @ingroup init
|
||||
*/
|
||||
GLFWAPI int glfwInit(void);
|
||||
GLFWAPI void glfwRunMainLoop(void);
|
||||
GLFWAPI void glfwRunMainLoop(GLFWtickcallback callback, void *callback_data);
|
||||
GLFWAPI void glfwStopMainLoop(void);
|
||||
GLFWAPI void glfwRequestTickCallback(void);
|
||||
GLFWAPI unsigned long long glfwAddTimer(double interval, bool repeats, GLFWuserdatafun callback, void * callback_data, GLFWuserdatafun free_callback);
|
||||
GLFWAPI void glfwRemoveTimer(unsigned long long);
|
||||
|
||||
|
|
|
|||
13
glfw/init.c
vendored
13
glfw/init.c
vendored
|
|
@ -322,10 +322,14 @@ GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
|
|||
}
|
||||
|
||||
|
||||
GLFWAPI void glfwRunMainLoop(void)
|
||||
GLFWAPI void glfwRunMainLoop(GLFWtickcallback callback, void *data)
|
||||
{
|
||||
_GLFW_REQUIRE_INIT();
|
||||
_glfwPlatformRunMainLoop();
|
||||
_glfwPlatformRunMainLoop(callback, data);
|
||||
}
|
||||
|
||||
GLFWAPI void glfwRequestTickCallback(void) {
|
||||
_glfwPlatformRequestTickCallback();
|
||||
}
|
||||
|
||||
GLFWAPI void glfwStopMainLoop(void) {
|
||||
|
|
@ -333,7 +337,10 @@ GLFWAPI void glfwStopMainLoop(void) {
|
|||
_glfwPlatformStopMainLoop();
|
||||
}
|
||||
|
||||
GLFWAPI unsigned long long glfwAddTimer(double interval, bool repeats, GLFWuserdatafun callback, void *callback_data, GLFWuserdatafun free_callback) {
|
||||
GLFWAPI unsigned long long glfwAddTimer(
|
||||
double interval, bool repeats, GLFWuserdatafun callback,
|
||||
void *callback_data, GLFWuserdatafun free_callback)
|
||||
{
|
||||
return _glfwPlatformAddTimer(interval, repeats, callback, callback_data, free_callback);
|
||||
}
|
||||
|
||||
|
|
|
|||
3
glfw/internal.h
vendored
3
glfw/internal.h
vendored
|
|
@ -783,7 +783,8 @@ void _glfwTerminateVulkan(void);
|
|||
const char* _glfwGetVulkanResultString(VkResult result);
|
||||
_GLFWwindow* _glfwFocusedWindow();
|
||||
_GLFWwindow* _glfwWindowForId(GLFWid id);
|
||||
void _glfwPlatformRunMainLoop(void);
|
||||
void _glfwPlatformRunMainLoop(GLFWtickcallback, void*);
|
||||
void _glfwPlatformRequestTickCallback();
|
||||
void _glfwPlatformStopMainLoop(void);
|
||||
unsigned long long _glfwPlatformAddTimer(double interval, bool repeats, GLFWuserdatafreefun callback, void *callback_data, GLFWuserdatafreefun free_callback);
|
||||
void _glfwPlatformRemoveTimer(unsigned long long timer_id);
|
||||
|
|
|
|||
13
glfw/x11_init.c
vendored
13
glfw/x11_init.c
vendored
|
|
@ -770,7 +770,11 @@ const char* _glfwPlatformGetVersionString(void)
|
|||
;
|
||||
}
|
||||
|
||||
static GLFWbool keep_going;
|
||||
static GLFWbool keep_going = GLFW_FALSE, tick_callback_requested = GLFW_FALSE;
|
||||
|
||||
void _glfwPlatformRequestTickCallback() {
|
||||
tick_callback_requested = GLFW_TRUE;
|
||||
}
|
||||
|
||||
void _glfwPlatformStopMainLoop(void) {
|
||||
if (keep_going) {
|
||||
|
|
@ -779,9 +783,14 @@ void _glfwPlatformStopMainLoop(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void _glfwPlatformRunMainLoop(void) {
|
||||
void _glfwPlatformRunMainLoop(GLFWtickcallback callback, void* data) {
|
||||
keep_going = GLFW_TRUE;
|
||||
tick_callback_requested = GLFW_FALSE;
|
||||
while(keep_going) {
|
||||
if (tick_callback_requested) {
|
||||
tick_callback_requested = GLFW_FALSE;
|
||||
callback(data);
|
||||
}
|
||||
_glfwPlatformWaitEvents();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3
kitty/glfw-wrapper.c
generated
3
kitty/glfw-wrapper.c
generated
|
|
@ -23,6 +23,9 @@ load_glfw(const char* path) {
|
|||
*(void **) (&glfwStopMainLoop_impl) = dlsym(handle, "glfwStopMainLoop");
|
||||
if (glfwStopMainLoop_impl == NULL) fail("Failed to load glfw function glfwStopMainLoop with error: %s", dlerror());
|
||||
|
||||
*(void **) (&glfwRequestTickCallback_impl) = dlsym(handle, "glfwRequestTickCallback");
|
||||
if (glfwRequestTickCallback_impl == NULL) fail("Failed to load glfw function glfwRequestTickCallback with error: %s", dlerror());
|
||||
|
||||
*(void **) (&glfwAddTimer_impl) = dlsym(handle, "glfwAddTimer");
|
||||
if (glfwAddTimer_impl == NULL) fail("Failed to load glfw function glfwAddTimer with error: %s", dlerror());
|
||||
|
||||
|
|
|
|||
7
kitty/glfw-wrapper.h
generated
7
kitty/glfw-wrapper.h
generated
|
|
@ -1267,6 +1267,7 @@ typedef void (* GLFWmonitorfun)(GLFWmonitor*,int);
|
|||
typedef void (* GLFWjoystickfun)(int,int);
|
||||
|
||||
typedef void (* GLFWuserdatafun)(unsigned long long, void*);
|
||||
typedef void (* GLFWtickcallback)(void*);
|
||||
|
||||
/*! @brief Video mode type.
|
||||
*
|
||||
|
|
@ -1426,7 +1427,7 @@ typedef int (*glfwInit_func)();
|
|||
glfwInit_func glfwInit_impl;
|
||||
#define glfwInit glfwInit_impl
|
||||
|
||||
typedef void (*glfwRunMainLoop_func)();
|
||||
typedef void (*glfwRunMainLoop_func)(GLFWtickcallback, void*);
|
||||
glfwRunMainLoop_func glfwRunMainLoop_impl;
|
||||
#define glfwRunMainLoop glfwRunMainLoop_impl
|
||||
|
||||
|
|
@ -1434,6 +1435,10 @@ typedef void (*glfwStopMainLoop_func)();
|
|||
glfwStopMainLoop_func glfwStopMainLoop_impl;
|
||||
#define glfwStopMainLoop glfwStopMainLoop_impl
|
||||
|
||||
typedef void (*glfwRequestTickCallback_func)();
|
||||
glfwRequestTickCallback_func glfwRequestTickCallback_impl;
|
||||
#define glfwRequestTickCallback glfwRequestTickCallback_impl
|
||||
|
||||
typedef unsigned long long (*glfwAddTimer_func)(double, bool, GLFWuserdatafun, void *, GLFWuserdatafun);
|
||||
glfwAddTimer_func glfwAddTimer_impl;
|
||||
#define glfwAddTimer glfwAddTimer_impl
|
||||
|
|
|
|||
15
kitty/glfw.c
15
kitty/glfw.c
|
|
@ -1123,6 +1123,21 @@ remove_main_loop_timer(id_type timer_id) {
|
|||
glfwRemoveTimer(timer_id);
|
||||
}
|
||||
|
||||
void
|
||||
run_main_loop(tick_callback_fun cb, void* cb_data) {
|
||||
glfwRunMainLoop(cb, cb_data);
|
||||
}
|
||||
|
||||
void
|
||||
request_tick_callback(void) {
|
||||
glfwRequestTickCallback();
|
||||
}
|
||||
|
||||
void
|
||||
stop_main_loop(void) {
|
||||
glfwStopMainLoop();
|
||||
}
|
||||
|
||||
// Boilerplate {{{
|
||||
|
||||
static PyMethodDef module_methods[] = {
|
||||
|
|
|
|||
|
|
@ -222,5 +222,9 @@ void request_application_quit();
|
|||
#endif
|
||||
void request_frame_render(OSWindow *w);
|
||||
typedef void (* timer_callback_fun)(id_type, void*);
|
||||
typedef void (* tick_callback_fun)(void*);
|
||||
id_type add_main_loop_timer(double interval, bool repeats, timer_callback_fun callback, void *callback_data, timer_callback_fun free_callback);
|
||||
void remove_main_loop_timer(id_type timer_id);
|
||||
void run_main_loop(tick_callback_fun, void*);
|
||||
void request_tick_callback(void);
|
||||
void stop_main_loop(void);
|
||||
|
|
|
|||
Loading…
Reference in a new issue