Skip to content

Commit 4704105

Browse files
committed
Handle L and R buttons in code
1 parent 41f1a36 commit 4704105

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

CMake/platforms/dreamcast.cmake

+3-12
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/threads-stub")
2424
list(APPEND DEVILUTIONX_PLATFORM_COMPILE_DEFINITIONS __DREAMCAST__)
2525
add_compile_options(-fpermissive)
2626

27-
#SDL Joystick axis mapping (circle-pad/C-stick)
28-
set(JOY_AXIS_LEFTX 11)
29-
set(JOY_AXIS_LEFTY 9)
30-
set(JOY_AXIS_RIGHTX 12)
31-
set(JOY_AXIS_RIGHTY 10)
32-
3327
#SDL Joystick hat mapping (D-pad)
3428
set(JOY_HAT_DPAD_UP_HAT 0)
3529
set(JOY_HAT_DPAD_RIGHT_HAT 0)
@@ -39,17 +33,14 @@ set(JOY_HAT_DPAD_UP 1)
3933
set(JOY_HAT_DPAD_RIGHT 2)
4034
set(JOY_HAT_DPAD_DOWN 4)
4135
set(JOY_HAT_DPAD_LEFT 8)
42-
#SDL Joystick button mapping (A / B and X / Y inverted)
36+
37+
#SDL Joystick button mapping
4338
set(JOY_BUTTON_A 2)
4439
set(JOY_BUTTON_B 1)
4540
set(JOY_BUTTON_X 5)
4641
set(JOY_BUTTON_Y 6)
47-
#set(JOY_BUTTON_LEFTSHOULDER 5)
48-
#set(JOY_BUTTON_RIGHTSHOULDER 6)
49-
set(JOY_BUTTON_BACK 7)
42+
5043
set(JOY_BUTTON_START 3)
51-
set(JOY_BUTTON_TRIGGERLEFT 8)
52-
set(JOY_BUTTON_TRIGGERRIGHT 9)
5344

5445
#GPF SDL files
5546
set(SDL_INCLUDE_DIR /usr/include/SDL/)

Source/controls/devices/joystick.cpp

+46-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ StaticVector<ControllerButtonEvent, 4> Joystick::ToControllerButtonEvents(const
4646
return { ControllerButtonEvent { ControllerButton_BUTTON_RIGHTSTICK, up } };
4747
#endif
4848
#ifdef JOY_BUTTON_LEFTSHOULDER
49-
case JOY_BUTTON_LEFTSHOULDER:
49+
case JOY_BUTTON_LEFTSHOULDER: {
50+
Log("ToControllerButtonEvents JOY_BUTTON_LEFTSHOULDER pressed");
5051
return { ControllerButtonEvent { ControllerButton_BUTTON_LEFTSHOULDER, up } };
52+
}
5153
#endif
5254
#ifdef JOY_BUTTON_RIGHTSHOULDER
5355
case JOY_BUTTON_RIGHTSHOULDER:
@@ -101,6 +103,20 @@ StaticVector<ControllerButtonEvent, 4> Joystick::ToControllerButtonEvents(const
101103
}
102104
case SDL_JOYAXISMOTION:
103105
case SDL_JOYBALLMOTION:
106+
#ifdef __DREAMCAST__
107+
if(event.jaxis.axis == 3) {
108+
Log("BUTTON_LEFTSHOULDER detected");
109+
Log("event.jbutton.button = {}", event.jbutton.button);
110+
Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED);
111+
return { ControllerButtonEvent { ControllerButton_BUTTON_LEFTSHOULDER, event.jaxis.value < 255 } };
112+
}
113+
if(event.jaxis.axis == 2) {
114+
Log("BUTTON_RIGHTSHOULDER detected");
115+
Log("event.jbutton.button = {}", event.jbutton.button);
116+
Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED);
117+
return { ControllerButtonEvent { ControllerButton_BUTTON_RIGHTSHOULDER, event.jaxis.value < 255 } };
118+
}
119+
#endif
104120
// ProcessAxisMotion() requires a ControllerButtonEvent parameter
105121
// so provide one here using ControllerButton_NONE
106122
return { ControllerButtonEvent { ControllerButton_NONE, false } };
@@ -211,8 +227,10 @@ int Joystick::ToSdlJoyButton(ControllerButton button)
211227
return JOY_BUTTON_RIGHTSTICK;
212228
#endif
213229
#ifdef JOY_BUTTON_LEFTSHOULDER
214-
case ControllerButton_BUTTON_LEFTSHOULDER:
230+
case ControllerButton_BUTTON_LEFTSHOULDER: {
231+
Log("ToSdlJoyButton JOY_BUTTON_LEFTSHOULDER pressed");
215232
return JOY_BUTTON_LEFTSHOULDER;
233+
}
216234
#endif
217235
#ifdef JOY_BUTTON_RIGHTSHOULDER
218236
case ControllerButton_BUTTON_RIGHTSHOULDER:
@@ -292,6 +310,31 @@ bool Joystick::IsPressed(ControllerButton button) const
292310
return joyButton < numButtons && SDL_JoystickGetButton(sdl_joystick_, joyButton) != 0;
293311
}
294312

313+
#ifdef __DREAMCAST__
314+
bool Joystick::ProcessAxisMotion(const SDL_Event &event)
315+
{
316+
if (event.type != SDL_JOYAXISMOTION)
317+
return false;
318+
319+
Log("ProcessAxisMotion event.jaxis.axis = {}", event.jaxis.axis);
320+
Log("ProcessAxisMotion event.jaxis.value = {}", event.jaxis.value);
321+
Log("ProcessAxisMotion event.jbutton.button = {}", event.jbutton.button);
322+
Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED);
323+
324+
switch (event.jaxis.axis) {
325+
case 0: //horizontal
326+
leftStickXUnscaled = event.jaxis.value;
327+
leftStickNeedsScaling = true;
328+
return true;
329+
case 1: //vertical
330+
leftStickYUnscaled = event.jaxis.value;
331+
leftStickNeedsScaling = true;
332+
return true;
333+
default:
334+
return false;
335+
}
336+
}
337+
#else //!ifdef __DREAMCAST__
295338
bool Joystick::ProcessAxisMotion(const SDL_Event &event)
296339
{
297340
if (event.type != SDL_JOYAXISMOTION)
@@ -330,6 +373,7 @@ bool Joystick::ProcessAxisMotion(const SDL_Event &event)
330373
return false;
331374
#endif
332375
}
376+
#endif
333377

334378
void Joystick::Add(int deviceIndex)
335379
{

0 commit comments

Comments
 (0)