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

optimization, map mouse button and modifier flags to sdl2 ones #17172

Open
anvilvapre opened this issue Oct 4, 2019 · 0 comments

Comments

@anvilvapre
Copy link

commented Oct 4, 2019

Possible optimization.

Why use custom mouse button and mouse button key modifier flags rather than using the same value as defined in SDL2. This is already done for key codes.

In SdlInput.cs it avoid the need for each mouse movement to have to execute at least 5 comparisons, 5 logical AND operations + 5 logical OR operations, plus possible casts to int.

`
static MouseButton MakeButton(byte b)
{
return b == SDL.SDL_BUTTON_LEFT ? MouseButton.Left
: b == SDL.SDL_BUTTON_RIGHT ? MouseButton.Right
: b == SDL.SDL_BUTTON_MIDDLE ? MouseButton.Middle
: 0;
}

            static Modifiers MakeModifiers(int raw)                         
            {                                                               
                    return ((raw & (int)SDL.SDL_Keymod.KMOD_ALT) != 0 ? Modifiers.Alt : 0)
                             | ((raw & (int)SDL.SDL_Keymod.KMOD_CTRL) != 0 ? Modifiers.Ctrl : 0)
                             | ((raw & (int)SDL.SDL_Keymod.KMOD_LGUI) != 0 ? Modifiers.Meta : 0)
                             | ((raw & (int)SDL.SDL_Keymod.KMOD_RGUI) != 0 ? Modifiers.Meta : 0)
                             | ((raw & (int)SDL.SDL_Keymod.KMOD_SHIFT) != 0 ? Modifiers.Shift : 0);
            } 

`

A lot of statements to check if the "middle mouse button" + "shift" was pressed.

Executed for each mouse event.

Alternatively you could perhaps use a mapping table, but depending on the values used by SDL it would have to be of size int.

@abcdefg30 abcdefg30 added the Refactor label Oct 4, 2019
@reaperrr reaperrr added the Performance label Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.