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

sdl2 escapes keycodes to support 32bits #919

Merged
merged 1 commit into from
Jun 23, 2020

Conversation

EduardoRFS
Copy link
Contributor

@EduardoRFS EduardoRFS commented Jun 23, 2020

Why?

OCaml on 32bits systems, have an int size of 31 bits, but SDL keycodes are actually 32bits integers, and some of them actually uses 31 bits of the integer, like let right = 1073741903.

One platform that suffers of this is problem is the Raspberry Pi, which by default is 32bits.

Solution

There is no SDL keycode negative, so to fix that without a breaking change we can use the negative part of our 31 bits int to fit any SDL keycode.

The only problem is that if you try to serialize big keycodes they will be different based on the platform, that is not ideal, but seems like a really small edge case and changing everything to int32 is probably not worth it.

let right = 1073741903;
let left = 1073741904;
let unknown = int(0l);
let backspace = int(8l);
Copy link
Member

Choose a reason for hiding this comment

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

I don't remember the prefix but their is a prefix to cast at compile time here it is at runtime

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm couldn't found anything related to that, but this happens at compile time anyways, even in classic mode and even in bytecode mode. Also this isn't a safe transformation, technically it's not a type cast as you loose one bit

@bryphe
Copy link
Member

bryphe commented Jun 23, 2020

Looks good to me! Thanks for fixing this, @EduardoRFS . Exciting to have it work on Raspberry Pi 😍

@bryphe bryphe merged commit 14861e7 into revery-ui:master Jun 23, 2020
@EduardoRFS EduardoRFS deleted the sdl2-32bits branch June 24, 2020 01:00
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.

3 participants