Skip to content
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

Use SDL_GetKeyboardState instead of event polling #469

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thatcosmonaut
Copy link
Member

@thatcosmonaut thatcosmonaut commented Dec 28, 2023

We got a report from the Celeste modding/speedrunning community that FNA was causing input latency on keyboard relative to XNA. FNA currently processes keyboard input by processing all keyboard events in PollEvents and setting the keys in an internal array. But according to the report, XNA actually gets a new state every time Keyboard.GetState is called, not just once per frame. This patch brings the behavior in line with XNA, and it should address latency by allowing input polling to occur closer to when input is actually processed by the game.

We got a report from the Celeste modding/speedrunning community that FNA was causing input latency on keyboard relative to XNA when an IME was installed. This patch gets the keyboard state directly all at once instead of iterating over keydown events. This might address some scenarios where the keydown event is intercepted by something. It should also be very slightly more efficient to not have to call keys.Contains on all keypresses.

Copy link
Member

@flibitijibibo flibitijibibo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally this makes sense, so we can go into the polishing stage at this point.

src/Input/Keyboard.cs Outdated Show resolved Hide resolved
src/FNAPlatform/SDL2_FNAPlatform.cs Outdated Show resolved Hide resolved
Copy link
Member

@flibitijibibo flibitijibibo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took care of the notes, as long as this works as intended this is ready to go.

@flibitijibibo flibitijibibo force-pushed the keyboard branch 2 times, most recently from c87ce2e to 88f940f Compare January 1, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants