-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async mouse input on windows #6235
base: master
Are you sure you want to change the base?
Conversation
This works because SDL queries for raw mouse and keyboard input on a separate thread and we sync all inputs to a `ConcurrentQueue`.
29b83bf
to
7fac7bf
Compare
This seems to break input on my VM setup. Yes I have a weird setup but it did work, so something has potentially changed or broken. I haven't yet investigated why, but can if required (if the issue isn't obvious). master: 2024-04-15.15.35.29.mp4this PR: 2024-04-15.15.34.02.mp4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As commented
Hmm, it's weird that the relative mouse movements align with the cursor in one scenario but not the other. But I wouldn't call it broken, the framework cursor is still moving proportionally to your mouse movements. The weirder thing is that the mouse cursor isn't hidden when in relative mode. I have no idea what could cause any of this. But if you'll be looking at this, don't forget to enable event logging with SDL3.SDL_SetHint(SDL3.SDL_HINT_EVENT_LOGGING, "2"u8); |
I tried to show this, but it's actually not proportionally correct either. I'll see what I can find. |
@Susko3 can you please check back on this? a lot of upstream changes meant that I basically had to reapply your changes here. I'm also curious when we should not be using the filter method for handling things. I guess only when we want thread synchronisation on the input thread? |
I'm not sure. Maybe it's safe to handle all input events in the watch. Especially if we're not relying on SDL state and are just consuming fields from the See the following review for some thread unsafety, and methods that query SDL state: |
@@ -306,7 +307,39 @@ protected virtual void HandleEventFromFilter(SDL_Event evt) | |||
case SDL_EventType.SDL_EVENT_LOW_MEMORY: | |||
LowOnMemory?.Invoke(); | |||
break; | |||
|
|||
case SDL_EventType.SDL_EVENT_MOUSE_MOTION: | |||
handleMouseMotionEvent(e.motion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calls SDL_GetWindowRelativeMouseMode()
which could be considered as reading SDL state in a event filter, but it's currently just reading a window flag.
case SDL_EventType.SDL_EVENT_JOYSTICK_AXIS_MOTION: | ||
handleJoyAxisEvent(e.jaxis); | ||
return false; | ||
|
||
case SDL_EventType.SDL_EVENT_JOYSTICK_BALL_MOTION: | ||
handleJoyBallEvent(e.jball); | ||
return false; | ||
|
||
case SDL_EventType.SDL_EVENT_JOYSTICK_HAT_MOTION: | ||
handleJoyHatEvent(e.jhat); | ||
return false; | ||
|
||
case SDL_EventType.SDL_EVENT_JOYSTICK_BUTTON_DOWN: | ||
case SDL_EventType.SDL_EVENT_JOYSTICK_BUTTON_UP: | ||
handleJoyButtonEvent(e.jbutton); | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These don't directly depend on SDL state, but they do depend on SDL_EVENT_GAMEPAD_ADDED
, SDL_EVENT_GAMEPAD_REMOVED
, etc. for correct handling. By handling some events in the filter, we may reverse the order these events are understood by o!f. controllers
is also just a regular dictionary, so it's not thread safe.
I'm fine with moving input handling to the filter, but we need to ensure thread safety (in our code, and minimising SDL function calls). Some testing is needed. I think it's best to get the high-priority changes in (mouse & keyboard) and leave the rest for later. Mouse events seem fine to handle in the filter, Hmm, I'm not too sure about keyboard input. It may mess up our textbox handling because the order of events might be changed. |
@Susko3 sounds good. i think i'd like to make moving keyboard input there a goal (because otherwise it will run into the same issues as mouse). did you want to make any follow up changes? |
Yep, we can keep the original issues open. Having only mouse input async will make the issue less obvious, as the mouse is smooth, but the keyboard is delayed. Keyboard input needs additional consideration because SDL_HINT_WINDOWS_RAW_KEYBOARD is off by default.
I wanted to make I will try to use |
Depends on:
This PR simply handles relative mouse and keyboard events in the
SDL_EventFilter
i.e.HandleEventFromFilter
.This works because SDL queries raw mouse and keyboard inputs on a separate thread. Our
SDL_EventFilter
will intercept those events before they are pushed to the internal SDL queue, handle them, and then request SDL to drop them.Testing
Apply the diff and toggle relative mouse mode in
TestSceneInputManger
.This isn't a perfect simulation of
SDL_PumpEvents()
lag, but it shows the async input in action.