Skip to content

Set keyboard state array to SDL scan code range bound, refactor key state to bitset (#3466)#3472

Merged
AaronVanGeffen merged 3 commits intoOpenLoco:masterfrom
Hammster:fix-sdl-scan-key-range
Nov 27, 2025
Merged

Set keyboard state array to SDL scan code range bound, refactor key state to bitset (#3466)#3472
AaronVanGeffen merged 3 commits intoOpenLoco:masterfrom
Hammster:fix-sdl-scan-key-range

Conversation

@Hammster
Copy link
Copy Markdown
Contributor

@Hammster Hammster commented Nov 22, 2025

Setting the bounds for the scan code array to SDL defined safe value SDL_NUM_SCANCODES fixes #3466

https://wiki.libsdl.org/SDL2/SDL_Scancode

@AaronVanGeffen
Copy link
Copy Markdown
Member

Okay, so this essentially doubles it. Makes sense that it was crashing before, then, heh.

Wonder if, in the future, it would make sense to use, say, a BitSet here? 512 bytes seems like a lot just for keyboard state.

@Hammster
Copy link
Copy Markdown
Contributor Author

Hammster commented Nov 22, 2025

I agree, to be honest I'll update the implementation to a BitSet directly. No need to delay this from my POV

@AaronVanGeffen
Copy link
Copy Markdown
Member

Thanks, sounds good! Thinking about it, the current data type might've been left as-is for a long time for interop reasons.

Not sure if you saw, but we have our own BitSet implementation in the Core subproject, fwiw.

@Hammster
Copy link
Copy Markdown
Contributor Author

Hammster commented Nov 22, 2025

I hope this is the correct usage of the core bitset implementation,

I noticed that it's not implementing the .test(offset) function, I don't know if you maybe want this to be added to be in parity with std::bitset but accessing it directly works too 👍

Also to test this correctly on my end, how does the hotkey work for cheats so that i can test? I kinda stumbled there.

@Hammster Hammster changed the title Set keyboard state array to SDL scancode range bound (#3466) Set keyboard state array to SDL scan code range bound, refactor key state to bitset (#3466) Nov 22, 2025
@AaronVanGeffen
Copy link
Copy Markdown
Member

AaronVanGeffen commented Nov 23, 2025

I hope this is the correct usage of the core bitset implementation,

Thanks. Looks good to me, though I haven't tested things yet.

Also to test this correctly on my end, how does the hotkey work for cheats so that i can test? I kinda stumbled there.

In vanilla, the player is supposed to hold down the Insert key while typing one of the cheats. (Bit obscure, yeah.)

@AaronVanGeffen AaronVanGeffen added the changelog Requires a changelog entry label Nov 23, 2025
@AaronVanGeffen AaronVanGeffen added this to the v25.11+ milestone Nov 23, 2025
@Hammster
Copy link
Copy Markdown
Contributor Author

Looks working to me when testing the "DRIVER" cheat.

@AaronVanGeffen AaronVanGeffen enabled auto-merge (squash) November 27, 2025 14:42
@AaronVanGeffen AaronVanGeffen merged commit 198d90d into OpenLoco:master Nov 27, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog Requires a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Game crashes if you press next track multimedia key on your keyboard

3 participants