diff --git a/CMake/platforms/dreamcast.cmake b/CMake/platforms/dreamcast.cmake index 7409b65f675..4b97cc3a253 100644 --- a/CMake/platforms/dreamcast.cmake +++ b/CMake/platforms/dreamcast.cmake @@ -24,12 +24,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/threads-stub") list(APPEND DEVILUTIONX_PLATFORM_COMPILE_DEFINITIONS __DREAMCAST__) add_compile_options(-fpermissive) -#SDL Joystick axis mapping (circle-pad/C-stick) -set(JOY_AXIS_LEFTX 11) -set(JOY_AXIS_LEFTY 9) -set(JOY_AXIS_RIGHTX 12) -set(JOY_AXIS_RIGHTY 10) - #SDL Joystick hat mapping (D-pad) set(JOY_HAT_DPAD_UP_HAT 0) set(JOY_HAT_DPAD_RIGHT_HAT 0) @@ -39,17 +33,14 @@ set(JOY_HAT_DPAD_UP 1) set(JOY_HAT_DPAD_RIGHT 2) set(JOY_HAT_DPAD_DOWN 4) set(JOY_HAT_DPAD_LEFT 8) -#SDL Joystick button mapping (A / B and X / Y inverted) + +#SDL Joystick button mapping set(JOY_BUTTON_A 2) set(JOY_BUTTON_B 1) set(JOY_BUTTON_X 5) set(JOY_BUTTON_Y 6) -#set(JOY_BUTTON_LEFTSHOULDER 5) -#set(JOY_BUTTON_RIGHTSHOULDER 6) -set(JOY_BUTTON_BACK 7) + set(JOY_BUTTON_START 3) -set(JOY_BUTTON_TRIGGERLEFT 8) -set(JOY_BUTTON_TRIGGERRIGHT 9) #GPF SDL files set(SDL_INCLUDE_DIR /usr/include/SDL/) diff --git a/Source/controls/devices/joystick.cpp b/Source/controls/devices/joystick.cpp index 3770e595cfd..f1ac60bcfc4 100644 --- a/Source/controls/devices/joystick.cpp +++ b/Source/controls/devices/joystick.cpp @@ -46,8 +46,10 @@ StaticVector Joystick::ToControllerButtonEvents(const return { ControllerButtonEvent { ControllerButton_BUTTON_RIGHTSTICK, up } }; #endif #ifdef JOY_BUTTON_LEFTSHOULDER - case JOY_BUTTON_LEFTSHOULDER: + case JOY_BUTTON_LEFTSHOULDER: { + Log("ToControllerButtonEvents JOY_BUTTON_LEFTSHOULDER pressed"); return { ControllerButtonEvent { ControllerButton_BUTTON_LEFTSHOULDER, up } }; + } #endif #ifdef JOY_BUTTON_RIGHTSHOULDER case JOY_BUTTON_RIGHTSHOULDER: @@ -101,6 +103,20 @@ StaticVector Joystick::ToControllerButtonEvents(const } case SDL_JOYAXISMOTION: case SDL_JOYBALLMOTION: +#ifdef __DREAMCAST__ + if(event.jaxis.axis == 3) { + Log("BUTTON_LEFTSHOULDER detected"); + Log("event.jbutton.button = {}", event.jbutton.button); + Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED); + return { ControllerButtonEvent { ControllerButton_BUTTON_LEFTSHOULDER, event.jaxis.value < 255 } }; + } + if(event.jaxis.axis == 2) { + Log("BUTTON_RIGHTSHOULDER detected"); + Log("event.jbutton.button = {}", event.jbutton.button); + Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED); + return { ControllerButtonEvent { ControllerButton_BUTTON_RIGHTSHOULDER, event.jaxis.value < 255 } }; + } +#endif // ProcessAxisMotion() requires a ControllerButtonEvent parameter // so provide one here using ControllerButton_NONE return { ControllerButtonEvent { ControllerButton_NONE, false } }; @@ -211,8 +227,10 @@ int Joystick::ToSdlJoyButton(ControllerButton button) return JOY_BUTTON_RIGHTSTICK; #endif #ifdef JOY_BUTTON_LEFTSHOULDER - case ControllerButton_BUTTON_LEFTSHOULDER: + case ControllerButton_BUTTON_LEFTSHOULDER: { + Log("ToSdlJoyButton JOY_BUTTON_LEFTSHOULDER pressed"); return JOY_BUTTON_LEFTSHOULDER; + } #endif #ifdef JOY_BUTTON_RIGHTSHOULDER case ControllerButton_BUTTON_RIGHTSHOULDER: @@ -292,6 +310,31 @@ bool Joystick::IsPressed(ControllerButton button) const return joyButton < numButtons && SDL_JoystickGetButton(sdl_joystick_, joyButton) != 0; } +#ifdef __DREAMCAST__ +bool Joystick::ProcessAxisMotion(const SDL_Event &event) +{ + if (event.type != SDL_JOYAXISMOTION) + return false; + + Log("ProcessAxisMotion event.jaxis.axis = {}", event.jaxis.axis); + Log("ProcessAxisMotion event.jaxis.value = {}", event.jaxis.value); + Log("ProcessAxisMotion event.jbutton.button = {}", event.jbutton.button); + Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED); + + switch (event.jaxis.axis) { + case 0: //horizontal + leftStickXUnscaled = event.jaxis.value; + leftStickNeedsScaling = true; + return true; + case 1: //vertical + leftStickYUnscaled = event.jaxis.value; + leftStickNeedsScaling = true; + return true; + default: + return false; + } +} +#else //!ifdef __DREAMCAST__ bool Joystick::ProcessAxisMotion(const SDL_Event &event) { if (event.type != SDL_JOYAXISMOTION) @@ -330,6 +373,7 @@ bool Joystick::ProcessAxisMotion(const SDL_Event &event) return false; #endif } +#endif void Joystick::Add(int deviceIndex) {