Bladeren bron

Add flag: SUPPORT_EVENTS_WAITING

Wait for input events passively (sleep) instead of polling events actively every frame
Ray 7 jaren geleden
bovenliggende
commit
0f6f326a86
4 gewijzigde bestanden met toevoegingen van 12 en 1 verwijderingen
  1. 1 0
      src/CMakeOptions.txt
  2. 2 0
      src/config.h
  3. 2 0
      src/config.h.in
  4. 7 1
      src/core.c

+ 1 - 0
src/CMakeOptions.txt

@@ -24,6 +24,7 @@ set(OFF ${INCLUDE_EVERYTHING} CACHE INTERNAL "Replace any OFF by default with \$
 
 # core.c
 option(SUPPORT_BUSY_WAIT_LOOP "Use busy wait loop for timing sync instead of a high-resolution timer" ON)
+option(SUPPORT_EVENTS_WAITING "Wait for events passively (sleeping while no events) instead of polling them actively every frame" OFF)
 option(SUPPORT_CAMERA_SYSTEM "Provide camera module (camera.h) with multiple predefined cameras: free, 1st/3rd person, orbital" ON)
 option(SUPPORT_DEFAULT_FONT "Default font is loaded on window initialization to be available for the user to render simple text. If enabled, uses external module functions to load default raylib font (module: text)" ON)
 option(SUPPORT_SCREEN_CAPTURE "Allow automatic screen capture of current screen pressing F12, defined in KeyCallback()" ON)

+ 2 - 0
src/config.h

@@ -44,6 +44,8 @@
 #define SUPPORT_MOUSE_GESTURES      1
 // Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used
 #define SUPPORT_BUSY_WAIT_LOOP      1
+// Wait for events passively (sleeping while no events) instead of polling them actively every frame
+//SUPPORT_EVENTS_WAITING            1
 // Allow automatic screen capture of current screen pressing F12, defined in KeyCallback()
 #define SUPPORT_SCREEN_CAPTURE      1
 // Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()

+ 2 - 0
src/config.h.in

@@ -9,6 +9,8 @@
 #cmakedefine SUPPORT_MOUSE_GESTURES 1
 /* Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used */
 #cmakedefine SUPPORT_BUSY_WAIT_LOOP 1
+/* Wait for events passively (sleeping while no events) instead of polling them actively every frame */
+#cmakedefine SUPPORT_EVENTS_WAITING 1
 /* Allow automatic screen capture of current screen pressing F12, defined in KeyCallback() */
 #cmakedefine SUPPORT_SCREEN_CAPTURE 1
 /* Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback() */

+ 7 - 1
src/core.c

@@ -50,6 +50,9 @@
 *   #define SUPPORT_BUSY_WAIT_LOOP
 *       Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used
 *
+*   #define SUPPORT_EVENTS_WAITING
+*       Wait for events passively (sleeping while no events) instead of polling them actively every frame
+*
 *   #define SUPPORT_SCREEN_CAPTURE
 *       Allow automatic screen capture of current screen pressing F12, defined in KeyCallback()
 *
@@ -2933,7 +2936,6 @@ static void PollInputEvents(void)
         previousMouseState[i] = currentMouseState[i];
         currentMouseState[i] = currentMouseStateEvdev[i];
     }
-
 #endif
 
 #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
@@ -3007,8 +3009,12 @@ static void PollInputEvents(void)
         }
     }
 
+#if defined(SUPPORT_EVENTS_WAITING)
+    glfwWaitEvents();
+#else
     glfwPollEvents();       // Register keyboard/mouse events (callbacks)... and window events!
 #endif
+#endif      //defined(PLATFORM_DESKTOP)
 
 // Gamepad support using emscripten API
 // NOTE: GLFW3 joystick functionality not available in web