ihhub / fheroes2

fheroes2 is a recreation of Heroes of Might and Magic II game engine.
https://ihhub.github.io/fheroes2/
GNU General Public License v2.0
2.69k stars 375 forks source link

Abstract event processing code to be able to use any other library for this purpose #8798

Closed ihhub closed 3 months ago

ihhub commented 4 months ago

!!!ATTENTION!!! This change is massive and touches every platform we support. In-depth testing is required for each platform to verify that all inputs (keyboard, mouse, touchscreen, gamepad buttons) still work correctly. !!!ATTENTION!!!

This pull request abstracts our current SDL2 event handling library from the rest of the code. It is needed to avoid extra dependency from SDL and in the future flawlessly move to SDL 3 or any other library for event handling. Also, LocalEvent class was such a mess so it is hard to maintain it and understand what's going on inside.

Changes made:

The biggest mess in the code was regarding Vita and Switch button mapping. Here how it was:

SDL button Value Switch mapping Action
Switch      
SDL_CONTROLLER_BUTTON_A 0 SWITCH_BUTTON_B mouse right
SDL_CONTROLLER_BUTTON_B 1 SWITCH_BUTTON_A mouse left
SDL_CONTROLLER_BUTTON_X 2 SWITCH_BUTTON_Y KEY_ENTER
SDL_CONTROLLER_BUTTON_Y 3 SWITCH_BUTTON_X KEY_ESCAPE
SDL_CONTROLLER_BUTTON_BACK 4 SWITCH_BUTTON_MINUS KEY_E
SDL_CONTROLLER_BUTTON_GUIDE 5    
SDL_CONTROLLER_BUTTON_START 6 SWITCH_BUTTON_PLUS KEY_C
SDL_CONTROLLER_BUTTON_LEFTSTICK 7    
SDL_CONTROLLER_BUTTON_RIGHTSTICK 8    
SDL_CONTROLLER_BUTTON_LEFTSHOULDER 9 SWITCH_BUTTON_L KEY_H
SDL_CONTROLLER_BUTTON_RIGHTSHOULDER 10 SWITCH_BUTTON_R KEY_T
SDL_CONTROLLER_BUTTON_DPAD_UP 11 11  
SDL_CONTROLLER_BUTTON_DPAD_DOWN 12 12  
SDL_CONTROLLER_BUTTON_DPAD_LEFT 13 13  
SDL_CONTROLLER_BUTTON_DPAD_RIGHT 14 14  
Vita      
SDL_CONTROLLER_BUTTON_A 0   mouse left
SDL_CONTROLLER_BUTTON_B 1   mouse right
SDL_CONTROLLER_BUTTON_X 2   KEY_E
SDL_CONTROLLER_BUTTON_Y 3   KEY_C
SDL_CONTROLLER_BUTTON_BACK 4   KEY_F
SDL_CONTROLLER_BUTTON_GUIDE 5    
SDL_CONTROLLER_BUTTON_START 6   KEY_ENTER
SDL_CONTROLLER_BUTTON_LEFTSTICK 7    
SDL_CONTROLLER_BUTTON_RIGHTSTICK 8    
SDL_CONTROLLER_BUTTON_LEFTSHOULDER 9    
SDL_CONTROLLER_BUTTON_RIGHTSHOULDER 10    
SDL_CONTROLLER_BUTTON_DPAD_UP 11    
SDL_CONTROLLER_BUTTON_DPAD_DOWN 12   KEY_SPACE
SDL_CONTROLLER_BUTTON_DPAD_LEFT 13   KEY_H
SDL_CONTROLLER_BUTTON_DPAD_RIGHT 14   KEY_T

The only key was not present in Vita is KEY_ESCAPE which I use for CONTROLLER_BUTTON_GUIDE.

Things to do after this pull request:

sonarcloud[bot] commented 4 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

ihhub commented 4 months ago

A table of completed testing for each platform (will be updated upon testing):

Platform Keyboard Mouse Touchscreen Gamepad
Windows + +
Ubuntu + +
macOS + +
Android + +
Vita + +
Switch
ihhub commented 4 months ago

Hi @oleg-derevenetz , if you don't mind can you please test macOS build for at least keyboard and mouse?

ihhub commented 4 months ago

Hi @Northfear , can you please check Vita build that these changes don't break input controls?

Hi @dimag0g , can you please do the same for Switch build?

oleg-derevenetz commented 3 months ago

Hi @ihhub

if you don't mind can you please test macOS build for at least keyboard and mouse?

Sure, just checked this PR on macOS, no issues with the keyboard or mouse were found.

Northfear commented 3 months ago

@ihhub I did a quick test and everything seems to be working fine on Vita

ihhub commented 3 months ago

Thank you, @oleg-derevenetz and @Northfear !