瀏覽代碼

Don't mix keyboard and mouse raw input timestamps

We want to keep mouse timestamps consistently using the same interval, and it's helpful to know when multiple keyboard events come in at the same time.
Sam Lantinga 1 年之前
父節點
當前提交
1954ac407f
共有 1 個文件被更改,包括 15 次插入9 次删除
  1. 15 9
      src/video/windows/SDL_windowsevents.c

+ 15 - 9
src/video/windows/SDL_windowsevents.c

@@ -785,25 +785,31 @@ void WIN_PollRawInput(SDL_VideoDevice *_this)
 
 
     now = SDL_GetTicksNS();
     now = SDL_GetTicksNS();
     if (total > 0) {
     if (total > 0) {
-        Uint64 timestamp, increment;
+        Uint64 mouse_timestamp, mouse_increment;
         Uint64 delta = (now - data->last_rawinput_poll);
         Uint64 delta = (now - data->last_rawinput_poll);
-        if (total > 1 && delta <= SDL_MS_TO_NS(100)) {
+        UINT total_mouse = 0;
+        for (i = 0, input = (RAWINPUT *)data->rawinput; i < total; ++i, input = NEXTRAWINPUTBLOCK(input)) {
+            if (input->header.dwType == RIM_TYPEMOUSE) {
+                ++total_mouse;
+            }
+        }
+        if (total_mouse > 1 && delta <= SDL_MS_TO_NS(100)) {
             /* We'll spread these events over the time since the last poll */
             /* We'll spread these events over the time since the last poll */
-            timestamp = data->last_rawinput_poll;
-            increment = delta / total;
+            mouse_timestamp = data->last_rawinput_poll;
+            mouse_increment = delta / total_mouse;
         } else {
         } else {
             /* Do we want to track the update rate per device? */
             /* Do we want to track the update rate per device? */
-            timestamp = now;
-            increment = 0;
+            mouse_timestamp = now;
+            mouse_increment = 0;
         }
         }
         for (i = 0, input = (RAWINPUT *)data->rawinput; i < total; ++i, input = NEXTRAWINPUTBLOCK(input)) {
         for (i = 0, input = (RAWINPUT *)data->rawinput; i < total; ++i, input = NEXTRAWINPUTBLOCK(input)) {
-            timestamp += increment;
             if (input->header.dwType == RIM_TYPEMOUSE) {
             if (input->header.dwType == RIM_TYPEMOUSE) {
                 RAWMOUSE *rawmouse = (RAWMOUSE *)((BYTE *)input + data->rawinput_offset);
                 RAWMOUSE *rawmouse = (RAWMOUSE *)((BYTE *)input + data->rawinput_offset);
-                WIN_HandleRawMouseInput(timestamp, data, input->header.hDevice, rawmouse);
+                mouse_timestamp += mouse_increment;
+                WIN_HandleRawMouseInput(mouse_timestamp, data, input->header.hDevice, rawmouse);
             } else if (input->header.dwType == RIM_TYPEKEYBOARD) {
             } else if (input->header.dwType == RIM_TYPEKEYBOARD) {
                 RAWKEYBOARD *rawkeyboard = (RAWKEYBOARD *)((BYTE *)input + data->rawinput_offset);
                 RAWKEYBOARD *rawkeyboard = (RAWKEYBOARD *)((BYTE *)input + data->rawinput_offset);
-                WIN_HandleRawKeyboardInput(timestamp, data, input->header.hDevice, rawkeyboard);
+                WIN_HandleRawKeyboardInput(now, data, input->header.hDevice, rawkeyboard);
             }
             }
         }
         }
     }
     }