[Scummvm-git-logs] scummvm master -> dafadbc8c77fe89d0504ddfdef159e1c37491f81
bgK
bastien.bouclet at gmail.com
Tue Dec 26 21:11:53 CET 2017
This automated email contains information about 8 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
ac78058fcd SDL: Initial support for game controllers
6fb50d562f PS3: Remove gamepad button mapping
1fb748e974 SDL: Move the non analog joystick code to the Symbian port
ee4ff8ca08 SDL: Cleanup joystick deadzone handling
5838894f24 PSP2: Remove identical to base class joystick axis event handling
a86eae6323 SDL: Only enable joystick related features when joysticks are enabled
1522fc8e2f SDL: Add support for joystick hotplug
dafadbc8c7 PSP2: Add controller config, remove joystick event handling
Commit: ac78058fcdf5d0e98522edf837ce250130e45eaa
https://github.com/scummvm/scummvm/commit/ac78058fcdf5d0e98522edf837ce250130e45eaa
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2017-12-26T21:11:04+01:00
Commit Message:
SDL: Initial support for game controllers
The button mapping is that of the Vita port
Co-Authored-By: rsn8887 <rsn8887 at users.noreply.github.com>
Changed paths:
backends/events/sdl/sdl-events.cpp
backends/events/sdl/sdl-events.h
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index d01d9c6..0953067 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -77,7 +77,7 @@ static uint32 convUTF8ToUTF32(const char *src) {
SdlEventSource::SdlEventSource()
: EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0), _queuedFakeMouseMove(false)
#if SDL_VERSION_ATLEAST(2, 0, 0)
- , _queuedFakeKeyUp(false), _fakeKeyUp()
+ , _queuedFakeKeyUp(false), _fakeKeyUp(), _controller(nullptr)
#endif
{
// Reset mouse state
@@ -90,16 +90,30 @@ SdlEventSource::SdlEventSource()
error("Could not initialize SDL: %s", SDL_GetError());
}
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1) {
+ error("Could not initialize SDL: %s", SDL_GetError());
+ }
+#endif
+
// Enable joystick
if (SDL_NumJoysticks() > joystick_num) {
- _joystick = SDL_JoystickOpen(joystick_num);
- debug("Using joystick: %s",
#if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_JoystickName(_joystick)
+ if (SDL_IsGameController(joystick_num)) {
+ _controller = SDL_GameControllerOpen(joystick_num);
+ debug("Using game controller: %s", SDL_GameControllerName(_controller));
+ } else
+#endif
+ {
+ _joystick = SDL_JoystickOpen(joystick_num);
+ debug("Using joystick: %s",
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ SDL_JoystickName(_joystick)
#else
- SDL_JoystickName(joystick_num)
+ SDL_JoystickName(joystick_num)
#endif
- );
+ );
+ }
} else {
warning("Invalid joystick: %d", joystick_num);
}
@@ -107,6 +121,10 @@ SdlEventSource::SdlEventSource()
}
SdlEventSource::~SdlEventSource() {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (_controller)
+ SDL_GameControllerClose(_controller);
+#endif
if (_joystick)
SDL_JoystickClose(_joystick);
}
@@ -541,12 +559,6 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
return handleMouseButtonDown(ev, event);
case SDL_MOUSEBUTTONUP:
return handleMouseButtonUp(ev, event);
- case SDL_JOYBUTTONDOWN:
- return handleJoyButtonDown(ev, event);
- case SDL_JOYBUTTONUP:
- return handleJoyButtonUp(ev, event);
- case SDL_JOYAXISMOTION:
- return handleJoyAxisMotion(ev, event);
#if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_MOUSEWHEEL: {
@@ -630,6 +642,30 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
}
+ if (_joystick) {
+ switch (ev.type) {
+ case SDL_JOYBUTTONDOWN:
+ return handleJoyButtonDown(ev, event);
+ case SDL_JOYBUTTONUP:
+ return handleJoyButtonUp(ev, event);
+ case SDL_JOYAXISMOTION:
+ return handleJoyAxisMotion(ev, event);
+ }
+ }
+
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (_controller) {
+ switch (ev.type) {
+ case SDL_CONTROLLERBUTTONDOWN:
+ return handleControllerButton(ev, event, false);
+ case SDL_CONTROLLERBUTTONUP:
+ return handleControllerButton(ev, event, true);
+ case SDL_CONTROLLERAXISMOTION:
+ return handleControllerAxisMotion(ev, event);
+ }
+ }
+#endif
+
return false;
}
@@ -867,70 +903,178 @@ bool SdlEventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
}
bool SdlEventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) {
+ if (ev.jaxis.axis == JOY_XAXIS) {
+ _km.joy_x = ev.jaxis.value;
+ return handleAxisToMouseMotion(_km.joy_x, _km.joy_y);
+ } else if (ev.jaxis.axis == JOY_YAXIS) {
+ _km.joy_y = ev.jaxis.value;
+ return handleAxisToMouseMotion(_km.joy_x, _km.joy_y);
+ }
- int axis = ev.jaxis.value;
-#ifdef JOY_ANALOG
- // conversion factor between keyboard mouse and joy axis value
- int vel_to_axis = (1500 / MULTIPLIER);
+ return false;
+}
+
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+bool SdlEventSource::handleControllerButton(const SDL_Event &ev, Common::Event &event, bool buttonUp) {
+ using namespace Common;
+
+ struct ControllerEventMapping {
+ EventType normalType;
+ KeyState normalKeystate;
+ EventType modifierType;
+ KeyState modifierKeystate;
+ };
+
+ static const ControllerEventMapping mapping[] = {
+ // SDL_CONTROLLER_BUTTON_A: Left mouse button
+ { EVENT_LBUTTONDOWN, KeyState(), EVENT_LBUTTONDOWN, KeyState() },
+ // SDL_CONTROLLER_BUTTON_B: Right mouse button
+ { EVENT_RBUTTONDOWN, KeyState(), EVENT_RBUTTONDOWN, KeyState() },
+ // SDL_CONTROLLER_BUTTON_X: Period (+R_trigger: Space)
+ { EVENT_KEYDOWN, KeyState(KEYCODE_PERIOD, '.'), EVENT_KEYDOWN, KeyState(KEYCODE_SPACE, ASCII_SPACE) },
+ // SDL_CONTROLLER_BUTTON_Y: Escape (+R_trigger: Return)
+ { EVENT_KEYDOWN, KeyState(KEYCODE_ESCAPE, ASCII_ESCAPE), EVENT_KEYDOWN, KeyState(KEYCODE_RETURN, ASCII_RETURN) },
+ // SDL_CONTROLLER_BUTTON_BACK: Virtual keyboard (+R_trigger: Predictive Input Dialog)
+#ifdef ENABLE_VKEYBD
+ { EVENT_VIRTUAL_KEYBOARD, KeyState(), EVENT_PREDICTIVE_DIALOG, KeyState() },
#else
- if (axis > JOY_DEADZONE) {
- axis -= JOY_DEADZONE;
- } else if (axis < -JOY_DEADZONE) {
- axis += JOY_DEADZONE;
- } else
- axis = 0;
+ { EVENT_INVALID, KeyState(), EVENT_PREDICTIVE_DIALOG, KeyState() },
#endif
+ // SDL_CONTROLLER_BUTTON_GUIDE: Unmapped
+ { EVENT_INVALID, KeyState(), EVENT_INVALID, KeyState() },
+ // SDL_CONTROLLER_BUTTON_START: ScummVM in game menu
+ { EVENT_MAINMENU, KeyState(), EVENT_MAINMENU, KeyState() },
+ // SDL_CONTROLLER_BUTTON_LEFTSTICK: Unmapped
+ { EVENT_INVALID, KeyState(), EVENT_INVALID, KeyState() },
+ // SDL_CONTROLLER_BUTTON_RIGHTSTICK: Unmapped
+ { EVENT_INVALID, KeyState(), EVENT_INVALID, KeyState() },
+ // SDL_CONTROLLER_BUTTON_LEFTSHOULDER: Game menu
+ { EVENT_KEYDOWN, KeyState(KEYCODE_F5, ASCII_F5), EVENT_KEYDOWN, KeyState(KEYCODE_F5, ASCII_F5) },
+ // SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: Modifier + Shift
+ { EVENT_KEYDOWN, KeyState(KEYCODE_INVALID, 0, KBD_SHIFT), EVENT_KEYDOWN, KeyState(KEYCODE_INVALID, 0, 0) },
+ // SDL_CONTROLLER_BUTTON_DPAD_UP: Up (+R_trigger: Up+Right)
+ { EVENT_KEYDOWN, KeyState(KEYCODE_KP8, 0), EVENT_KEYDOWN, KeyState(KEYCODE_KP9, 0) },
+ // SDL_CONTROLLER_BUTTON_DPAD_DOWN: Down (+R_trigger: Down+Left)
+ { EVENT_KEYDOWN, KeyState(KEYCODE_KP2, 0), EVENT_KEYDOWN, KeyState(KEYCODE_KP1, 0) },
+ // SDL_CONTROLLER_BUTTON_DPAD_LEFT: Left (+R_trigger: Up+Left)
+ { EVENT_KEYDOWN, KeyState(KEYCODE_KP4, 0), EVENT_KEYDOWN, KeyState(KEYCODE_KP7, 0) },
+ // SDL_CONTROLLER_BUTTON_DPAD_RIGHT: Right (+R_trigger: Down+Right)
+ { EVENT_KEYDOWN, KeyState(KEYCODE_KP6, 0), EVENT_KEYDOWN, KeyState(KEYCODE_KP3, 0) }
+ };
+
+ if (ev.cbutton.button > SDL_CONTROLLER_BUTTON_DPAD_RIGHT) {
+ warning("Unknown SDL controller button: '%d'", ev.cbutton.button);
+ return false;
+ }
- if (ev.jaxis.axis == JOY_XAXIS) {
-#ifdef JOY_ANALOG
- _km.joy_x = axis;
-#else
- if (axis != 0) {
- _km.x_vel = (axis > 0) ? 1 * MULTIPLIER:-1 * MULTIPLIER;
- _km.x_down_count = 1;
+ if (!_km.modifier) {
+ event.type = mapping[ev.cbutton.button].normalType;
+ event.kbd = mapping[ev.cbutton.button].normalKeystate;
+ } else {
+ event.type = mapping[ev.cbutton.button].modifierType;
+ event.kbd = mapping[ev.cbutton.button].modifierKeystate;
+ }
+
+ // Setting the mouse speed modifier after filling the event structure above
+ // ensures that the shift key events are correctly handled
+ if (ev.cbutton.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) {
+ // Right shoulder is the modifier button that makes the mouse go slower
+ // and allows access to an extended layout while pressed.
+ _km.modifier = !buttonUp;
+ }
+
+ if (event.type == EVENT_LBUTTONDOWN || event.type == EVENT_RBUTTONDOWN) {
+ processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
+ }
+
+ if (buttonUp) {
+ // The event mapping table is for button down events. If we received a button up event,
+ // transform the event type to the corresponding up type.
+ if (event.type == EVENT_KEYDOWN) {
+ event.type = EVENT_KEYUP;
+ } else if (event.type == EVENT_LBUTTONDOWN) {
+ event.type = EVENT_LBUTTONUP;
+ } else if (event.type == EVENT_RBUTTONDOWN) {
+ event.type = EVENT_RBUTTONUP;
} else {
- _km.x_vel = 0;
- _km.x_down_count = 0;
+ // Handled in key down
+ event.type = EVENT_INVALID;
}
+ }
+
+ return event.type != EVENT_INVALID;
+}
+
+bool SdlEventSource::handleControllerAxisMotion(const SDL_Event &ev, Common::Event &event) {
+ if (ev.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX) {
+ _km.joy_x = ev.caxis.value;
+ return handleAxisToMouseMotion(_km.joy_x, _km.joy_y);
+ } else if (ev.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY) {
+ _km.joy_y = ev.caxis.value;
+ return handleAxisToMouseMotion(_km.joy_x, _km.joy_y);
+ }
+
+ return false;
+}
#endif
- } else if (ev.jaxis.axis == JOY_YAXIS) {
-#ifndef JOY_INVERT_Y
- axis = -axis;
-#endif
-#ifdef JOY_ANALOG
- _km.joy_y = -axis;
-#else
- if (axis != 0) {
- _km.y_vel = (-axis > 0) ? 1 * MULTIPLIER: -1 * MULTIPLIER;
- _km.y_down_count = 1;
- } else {
- _km.y_vel = 0;
- _km.y_down_count = 0;
- }
+
+bool SdlEventSource::handleAxisToMouseMotion(int16 xAxis, int16 yAxis) {
+#ifdef JOY_INVERT_Y
+ yAxis = -yAxis;
#endif
- }
+
#ifdef JOY_ANALOG
- // radial and scaled analog joystick deadzone
- float analogX = (float)_km.joy_x;
- float analogY = (float)_km.joy_y;
+ // conversion factor between keyboard mouse and joy axis value
+ int vel_to_axis = (1500 / MULTIPLIER);
+
+ // radial and scaled deadzone
+
+ float analogX = (float)xAxis;
+ float analogY = (float)yAxis;
float deadZone = (float)JOY_DEADZONE;
if (g_system->hasFeature(OSystem::kFeatureJoystickDeadzone))
deadZone = (float)ConfMan.getInt("joystick_deadzone") * 1000.0f;
- float scalingFactor = 1.0f;
- float magnitude = 0.0f;
- magnitude = sqrt(analogX * analogX + analogY * analogY);
+ float magnitude = sqrt(analogX * analogX + analogY * analogY);
if (magnitude >= deadZone) {
_km.x_down_count = 0;
_km.y_down_count = 0;
- scalingFactor = 1.0f / magnitude * (magnitude - deadZone) / (32769.0f - deadZone);
+ float scalingFactor = 1.0f / magnitude * (magnitude - deadZone) / (32769.0f - deadZone);
_km.x_vel = (int16)(analogX * scalingFactor * 32768.0f / vel_to_axis);
_km.y_vel = (int16)(analogY * scalingFactor * 32768.0f / vel_to_axis);
} else {
_km.x_vel = 0;
_km.y_vel = 0;
}
+#else
+ if (xAxis > JOY_DEADZONE) {
+ xAxis -= JOY_DEADZONE;
+ } else if (xAxis < -JOY_DEADZONE) {
+ xAxis += JOY_DEADZONE;
+ } else
+ xAxis = 0;
+ if (yAxis > JOY_DEADZONE) {
+ yAxis -= JOY_DEADZONE;
+ } else if (yAxis < -JOY_DEADZONE) {
+ yAxis += JOY_DEADZONE;
+ } else
+ yAxis = 0;
+
+ if (xAxis != 0) {
+ _km.x_vel = (xAxis > 0) ? 1 * MULTIPLIER:-1 * MULTIPLIER;
+ _km.x_down_count = 1;
+ } else {
+ _km.x_vel = 0;
+ _km.x_down_count = 0;
+ }
+ if (yAxis != 0) {
+ _km.y_vel = (yAxis > 0) ? 1 * MULTIPLIER: -1 * MULTIPLIER;
+ _km.y_down_count = 1;
+ } else {
+ _km.y_vel = 0;
+ _km.y_down_count = 0;
+ }
#endif
return false;
diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h
index 5fd3cb7..cea944f 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -80,6 +80,11 @@ protected:
/** Joystick */
SDL_Joystick *_joystick;
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ /** Game controller */
+ SDL_GameController *_controller;
+#endif
+
/** Last screen id for checking if it was modified */
int _lastScreenID;
@@ -117,9 +122,19 @@ protected:
virtual bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event);
virtual bool handleKbdMouse(Common::Event &event);
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ virtual bool handleControllerButton(const SDL_Event &ev, Common::Event &event, bool buttonUp);
+ virtual bool handleControllerAxisMotion(const SDL_Event &ev, Common::Event &event);
+#endif
+
//@}
/**
+ * Update the virtual mouse according to a joystick or game controller axis position change
+ */
+ bool handleAxisToMouseMotion(int16 xAxis, int16 yAxis);
+
+ /**
* Assigns the mouse coords to the mouse event. Furthermore notify the
* graphics manager about the position change.
*/
Commit: 6fb50d562f9716a930ecb4fe3d20047d506e4ed5
https://github.com/scummvm/scummvm/commit/6fb50d562f9716a930ecb4fe3d20047d506e4ed5
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2017-12-26T21:11:04+01:00
Commit Message:
PS3: Remove gamepad button mapping
SDL_PSL1GHT now supports the GameController API. ScummVM's default
mapping is now used.
Changed paths:
backends/events/ps3sdl/ps3sdl-events.cpp
backends/events/ps3sdl/ps3sdl-events.h
dists/ps3/readme-ps3.md
diff --git a/backends/events/ps3sdl/ps3sdl-events.cpp b/backends/events/ps3sdl/ps3sdl-events.cpp
index 01cdc2f..5065559 100644
--- a/backends/events/ps3sdl/ps3sdl-events.cpp
+++ b/backends/events/ps3sdl/ps3sdl-events.cpp
@@ -31,96 +31,6 @@
#include "common/util.h"
#include "common/events.h"
-enum {
- BTN_LEFT = 0,
- BTN_DOWN = 1,
- BTN_RIGHT = 2,
- BTN_UP = 3,
-
- BTN_START = 4,
- BTN_R3 = 5,
- BTN_L3 = 6,
- BTN_SELECT = 7,
-
- BTN_SQUARE = 8,
- BTN_CROSS = 9,
- BTN_CIRCLE = 10,
- BTN_TRIANGLE = 11,
-
- BTN_R1 = 12,
- BTN_L1 = 13,
- BTN_R2 = 14,
- BTN_L2 = 15
-};
-
-bool PS3SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
-
- event.kbd.flags = 0;
-
- switch (ev.jbutton.button) {
- case BTN_CROSS: // Left mouse button
- event.type = Common::EVENT_LBUTTONDOWN;
- processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
- break;
- case BTN_CIRCLE: // Right mouse button
- event.type = Common::EVENT_RBUTTONDOWN;
- processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
- break;
- case BTN_TRIANGLE: // Game menu
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_F5;
- event.kbd.ascii = mapKey(SDLK_F5, (SDLMod) ev.key.keysym.mod, 0);
- break;
- case BTN_SELECT: // Virtual keyboard
-#ifdef ENABLE_VKEYBD
- event.type = Common::EVENT_VIRTUAL_KEYBOARD;
-#endif
- break;
- case BTN_SQUARE: // Escape
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_ESCAPE;
- event.kbd.ascii = mapKey(SDLK_ESCAPE, (SDLMod) ev.key.keysym.mod, 0);
- break;
- case BTN_L1: // Predictive input dialog
- event.type = Common::EVENT_PREDICTIVE_DIALOG;
- break;
- case BTN_START: // ScummVM in game menu
- event.type = Common::EVENT_MAINMENU;
- break;
- }
- return true;
-}
-
-bool PS3SdlEventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
-
- event.kbd.flags = 0;
-
- switch (ev.jbutton.button) {
- case BTN_CROSS: // Left mouse button
- event.type = Common::EVENT_LBUTTONUP;
- processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
- break;
- case BTN_CIRCLE: // Right mouse button
- event.type = Common::EVENT_RBUTTONUP;
- processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
- break;
- case BTN_TRIANGLE: // Game menu
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_F5;
- event.kbd.ascii = mapKey(SDLK_F5, (SDLMod) ev.key.keysym.mod, 0);
- break;
- case BTN_SELECT: // Virtual keyboard
- // Handled in key down
- break;
- case BTN_SQUARE: // Escape
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_ESCAPE;
- event.kbd.ascii = mapKey(SDLK_ESCAPE, (SDLMod) ev.key.keysym.mod, 0);
- break;
- }
- return true;
-}
-
/**
* The XMB (PS3 in game menu) needs the screen buffers to be constantly flip while open.
* This pauses execution and keeps redrawing the screen until the XMB is closed.
diff --git a/backends/events/ps3sdl/ps3sdl-events.h b/backends/events/ps3sdl/ps3sdl-events.h
index d28ce7f..340af49 100644
--- a/backends/events/ps3sdl/ps3sdl-events.h
+++ b/backends/events/ps3sdl/ps3sdl-events.h
@@ -31,8 +31,6 @@
class PS3SdlEventSource : public SdlEventSource {
protected:
void preprocessEvents(SDL_Event *event);
- bool handleJoyButtonDown(SDL_Event &ev, Common::Event &event);
- bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event);
};
#endif /* BACKEND_EVENTS_PS3_H */
diff --git a/dists/ps3/readme-ps3.md b/dists/ps3/readme-ps3.md
index 8290f87..d0a1382 100644
--- a/dists/ps3/readme-ps3.md
+++ b/dists/ps3/readme-ps3.md
@@ -21,14 +21,21 @@ Savegames are wrote in the /hdd0/game/SCUM12000/saves folder.
Joypad button mapping
=====================
-- Left stick => Mouse
-- Cross => Left mouse button
-- Circle => Right mouse button
-- Triangle => Game menu (F5)
-- Square => Escape
-- Start => ScummVM's in global game menu
-- Select => Toggle virtual keyboard
-- L1 => AGI predictive input dialog
+- Left stick => Mouse
+- R1 + Left stick => Slow Mouse
+- Cross => Left mouse button
+- Circle => Right mouse button
+- DPad => Cursor Keys (useful for character motion)
+- R1 + DPad => Diagonal Cursor Keys
+- L1 => Game menu (F5)
+- R1 => Shift (used to enable Mass Add in menu)
+- Square => Period '.' (used to skip dialog lines)
+- R1 + Square => Space ' '
+- Triangle => Escape (used to skip cutscenes)
+- R1 + Triangle => Return
+- Start => ScummVM's global in-game menu
+- Select => Toggle virtual keyboard
+- R1 + Select => AGI predictive input dialog
Disclaimer
==========
Commit: 1fb748e97480dc64ed27ebe75490c1b938cdbed4
https://github.com/scummvm/scummvm/commit/1fb748e97480dc64ed27ebe75490c1b938cdbed4
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2017-12-26T21:11:04+01:00
Commit Message:
SDL: Move the non analog joystick code to the Symbian port
Symbian was the only user of that code.
Changed paths:
backends/events/psp2sdl/psp2sdl-events.cpp
backends/events/sdl/sdl-events.cpp
backends/events/sdl/sdl-events.h
backends/events/symbiansdl/symbiansdl-events.cpp
backends/events/symbiansdl/symbiansdl-events.h
backends/platform/sdl/sdl.cpp
backends/platform/symbian/src/SymbianOS.cpp
backends/platform/symbian/src/SymbianOS.h
diff --git a/backends/events/psp2sdl/psp2sdl-events.cpp b/backends/events/psp2sdl/psp2sdl-events.cpp
index e58e49d..f555459 100644
--- a/backends/events/psp2sdl/psp2sdl-events.cpp
+++ b/backends/events/psp2sdl/psp2sdl-events.cpp
@@ -37,7 +37,6 @@
#include "math.h"
#define JOY_DEADZONE 2000
-#define JOY_ANALOG
#define JOY_XAXIS 0
#define JOY_YAXIS 1
#define JOY_XAXISR 2
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index 0953067..6d48b8d 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -30,18 +30,10 @@
#include "common/config-manager.h"
#include "common/textconsole.h"
-#ifdef JOY_ANALOG
-#include "math.h"
-#endif
-
// FIXME move joystick defines out and replace with confile file options
// we should really allow users to map any key to a joystick button
#define JOY_DEADZONE 3200
-#ifndef __SYMBIAN32__ // Symbian wants dialog joystick i.e cursor for movement/selection
- #define JOY_ANALOG
-#endif
-
// #define JOY_INVERT_Y
#define JOY_XAXIS 0
#define JOY_YAXIS 1
@@ -1023,7 +1015,6 @@ bool SdlEventSource::handleAxisToMouseMotion(int16 xAxis, int16 yAxis) {
yAxis = -yAxis;
#endif
-#ifdef JOY_ANALOG
// conversion factor between keyboard mouse and joy axis value
int vel_to_axis = (1500 / MULTIPLIER);
@@ -1047,35 +1038,6 @@ bool SdlEventSource::handleAxisToMouseMotion(int16 xAxis, int16 yAxis) {
_km.x_vel = 0;
_km.y_vel = 0;
}
-#else
- if (xAxis > JOY_DEADZONE) {
- xAxis -= JOY_DEADZONE;
- } else if (xAxis < -JOY_DEADZONE) {
- xAxis += JOY_DEADZONE;
- } else
- xAxis = 0;
- if (yAxis > JOY_DEADZONE) {
- yAxis -= JOY_DEADZONE;
- } else if (yAxis < -JOY_DEADZONE) {
- yAxis += JOY_DEADZONE;
- } else
- yAxis = 0;
-
- if (xAxis != 0) {
- _km.x_vel = (xAxis > 0) ? 1 * MULTIPLIER:-1 * MULTIPLIER;
- _km.x_down_count = 1;
- } else {
- _km.x_vel = 0;
- _km.x_down_count = 0;
- }
- if (yAxis != 0) {
- _km.y_vel = (yAxis > 0) ? 1 * MULTIPLIER: -1 * MULTIPLIER;
- _km.y_down_count = 1;
- } else {
- _km.y_vel = 0;
- _km.y_down_count = 0;
- }
-#endif
return false;
}
diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h
index cea944f..33d971a 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -132,7 +132,7 @@ protected:
/**
* Update the virtual mouse according to a joystick or game controller axis position change
*/
- bool handleAxisToMouseMotion(int16 xAxis, int16 yAxis);
+ virtual bool handleAxisToMouseMotion(int16 xAxis, int16 yAxis);
/**
* Assigns the mouse coords to the mouse event. Furthermore notify the
diff --git a/backends/events/symbiansdl/symbiansdl-events.cpp b/backends/events/symbiansdl/symbiansdl-events.cpp
index 4649f9f..0ae5824 100644
--- a/backends/events/symbiansdl/symbiansdl-events.cpp
+++ b/backends/events/symbiansdl/symbiansdl-events.cpp
@@ -31,6 +31,8 @@
#include <bautils.h>
+#define JOY_DEADZONE 3200
+
SymbianSdlEventSource::zoneDesc SymbianSdlEventSource::_zones[TOTAL_ZONES] = {
{ 0, 0, 320, 145 },
{ 0, 145, 150, 55 },
@@ -200,4 +202,38 @@ bool SymbianSdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
return false;
}
+bool SymbianSdlEventSource::handleAxisToMouseMotion(int16 xAxis, int16 yAxis) {
+ // Symbian wants dialog joystick i.e cursor for movement/selection
+
+ if (xAxis > JOY_DEADZONE) {
+ xAxis -= JOY_DEADZONE;
+ } else if (xAxis < -JOY_DEADZONE) {
+ xAxis += JOY_DEADZONE;
+ } else
+ xAxis = 0;
+ if (yAxis > JOY_DEADZONE) {
+ yAxis -= JOY_DEADZONE;
+ } else if (yAxis < -JOY_DEADZONE) {
+ yAxis += JOY_DEADZONE;
+ } else
+ yAxis = 0;
+
+ if (xAxis != 0) {
+ _km.x_vel = (xAxis > 0) ? 1 * MULTIPLIER:-1 * MULTIPLIER;
+ _km.x_down_count = 1;
+ } else {
+ _km.x_vel = 0;
+ _km.x_down_count = 0;
+ }
+ if (yAxis != 0) {
+ _km.y_vel = (yAxis > 0) ? 1 * MULTIPLIER: -1 * MULTIPLIER;
+ _km.y_down_count = 1;
+ } else {
+ _km.y_vel = 0;
+ _km.y_down_count = 0;
+ }
+
+ return false;
+}
+
#endif
diff --git a/backends/events/symbiansdl/symbiansdl-events.h b/backends/events/symbiansdl/symbiansdl-events.h
index 2664bc2..0393e39 100644
--- a/backends/events/symbiansdl/symbiansdl-events.h
+++ b/backends/events/symbiansdl/symbiansdl-events.h
@@ -50,6 +50,8 @@ protected:
static zoneDesc _zones[TOTAL_ZONES];
virtual bool remapKey(SDL_Event &ev, Common::Event &event);
+
+ virtual bool handleAxisToMouseMotion(int16 xAxis, int16 yAxis);
};
#endif
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index f6ab180..68499b1 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -180,9 +180,7 @@ bool OSystem_SDL::hasFeature(Feature f) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (f == kFeatureClipboardSupport) return true;
#endif
-#ifdef JOY_ANALOG
if (f == kFeatureJoystickDeadzone) return true;
-#endif
if (f == kFeatureKbdMouseSpeed) return true;
return ModularBackend::hasFeature(f);
}
@@ -293,12 +291,10 @@ void OSystem_SDL::initBackend() {
ConfMan.registerDefault("kbdmouse_speed", 3);
ConfMan.setInt("kbdmouse_speed", 3);
}
-#ifdef JOY_ANALOG
if (!ConfMan.hasKey("joystick_deadzone")) {
ConfMan.registerDefault("joystick_deadzone", 3);
ConfMan.setInt("joystick_deadzone", 3);
}
-#endif
ModularBackend::initBackend();
// We have to initialize the graphics manager before the event manager
diff --git a/backends/platform/symbian/src/SymbianOS.cpp b/backends/platform/symbian/src/SymbianOS.cpp
index 4d417b5..87e1c09 100644
--- a/backends/platform/symbian/src/SymbianOS.cpp
+++ b/backends/platform/symbian/src/SymbianOS.cpp
@@ -173,6 +173,13 @@ Common::String OSystem_SDL_Symbian::getDefaultConfigFileName() {
return configFile;
}
+bool OSystem_SDL_Symbian::hasFeature(Feature f) {
+ if (f == kFeatureJoystickDeadzone) return false;
+
+ return OSystem_SDL::hasFeature(f);
+}
+
+
RFs& OSystem_SDL_Symbian::FsSession() {
return *_RFs;
}
diff --git a/backends/platform/symbian/src/SymbianOS.h b/backends/platform/symbian/src/SymbianOS.h
index 6175409..fea1ebc 100644
--- a/backends/platform/symbian/src/SymbianOS.h
+++ b/backends/platform/symbian/src/SymbianOS.h
@@ -39,6 +39,7 @@ public:
virtual void engineDone();
virtual bool setGraphicsMode(const char *name);
virtual Common::String getDefaultConfigFileName();
+ virtual bool hasFeature(Feature f);
/**
* Returns reference to File session
Commit: ee4ff8ca08faf2bfbc14fe4a905b311d48049cf6
https://github.com/scummvm/scummvm/commit/ee4ff8ca08faf2bfbc14fe4a905b311d48049cf6
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2017-12-26T21:11:04+01:00
Commit Message:
SDL: Cleanup joystick deadzone handling
Changed paths:
backends/events/sdl/sdl-events.cpp
backends/platform/sdl/psp2/psp2.cpp
backends/platform/sdl/sdl.cpp
gui/options.cpp
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index 6d48b8d..d4e8956 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -32,7 +32,6 @@
// FIXME move joystick defines out and replace with confile file options
// we should really allow users to map any key to a joystick button
-#define JOY_DEADZONE 3200
// #define JOY_INVERT_Y
#define JOY_XAXIS 0
@@ -1022,9 +1021,7 @@ bool SdlEventSource::handleAxisToMouseMotion(int16 xAxis, int16 yAxis) {
float analogX = (float)xAxis;
float analogY = (float)yAxis;
- float deadZone = (float)JOY_DEADZONE;
- if (g_system->hasFeature(OSystem::kFeatureJoystickDeadzone))
- deadZone = (float)ConfMan.getInt("joystick_deadzone") * 1000.0f;
+ float deadZone = (float)ConfMan.getInt("joystick_deadzone") * 1000.0f;
float magnitude = sqrt(analogX * analogX + analogY * analogY);
diff --git a/backends/platform/sdl/psp2/psp2.cpp b/backends/platform/sdl/psp2/psp2.cpp
index 94b06e6..f323db7 100644
--- a/backends/platform/sdl/psp2/psp2.cpp
+++ b/backends/platform/sdl/psp2/psp2.cpp
@@ -94,12 +94,6 @@ void OSystem_PSP2::initBackend() {
if (!ConfMan.hasKey("filtering")) {
ConfMan.setBool("filtering", true);
}
- if (!ConfMan.hasKey("kbdmouse_speed")) {
- ConfMan.setInt("kbdmouse_speed", 3);
- }
- if (!ConfMan.hasKey("joystick_deadzone")) {
- ConfMan.setInt("joystick_deadzone", 2);
- }
if (!ConfMan.hasKey("shader")) {
ConfMan.setInt("shader", 2);
}
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 68499b1..360baf9 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -90,6 +90,8 @@ OSystem_SDL::OSystem_SDL()
_eventSource(0),
_window(0) {
+ ConfMan.registerDefault("kbdmouse_speed", 3);
+ ConfMan.registerDefault("joystick_deadzone", 3);
}
OSystem_SDL::~OSystem_SDL() {
@@ -287,14 +289,6 @@ void OSystem_SDL::initBackend() {
_inited = true;
- if (!ConfMan.hasKey("kbdmouse_speed")) {
- ConfMan.registerDefault("kbdmouse_speed", 3);
- ConfMan.setInt("kbdmouse_speed", 3);
- }
- if (!ConfMan.hasKey("joystick_deadzone")) {
- ConfMan.registerDefault("joystick_deadzone", 3);
- ConfMan.setInt("joystick_deadzone", 3);
- }
ModularBackend::initBackend();
// We have to initialize the graphics manager before the event manager
diff --git a/gui/options.cpp b/gui/options.cpp
index f1ca21a..0ffcee4 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -240,21 +240,17 @@ void OptionsDialog::build() {
}
}
if (g_system->hasFeature(OSystem::kFeatureKbdMouseSpeed)) {
- if (ConfMan.hasKey("kbdmouse_speed", _domain)) {
- int value = ConfMan.getInt("kbdmouse_speed", _domain);
- if (_kbdMouseSpeedSlider && value < ARRAYSIZE(kbdMouseSpeedLabels) - 1 && value >= 0) {
- _kbdMouseSpeedSlider->setValue(value);
- _kbdMouseSpeedLabel->setLabel(_(kbdMouseSpeedLabels[value]));
- }
+ int value = ConfMan.getInt("kbdmouse_speed", _domain);
+ if (_kbdMouseSpeedSlider && value < ARRAYSIZE(kbdMouseSpeedLabels) - 1 && value >= 0) {
+ _kbdMouseSpeedSlider->setValue(value);
+ _kbdMouseSpeedLabel->setLabel(_(kbdMouseSpeedLabels[value]));
}
}
if (g_system->hasFeature(OSystem::kFeatureJoystickDeadzone)) {
- if (ConfMan.hasKey("joystick_deadzone", _domain)) {
- int value = ConfMan.getInt("joystick_deadzone", _domain);
- if (_joystickDeadzoneSlider != 0) {
- _joystickDeadzoneSlider->setValue(value);
- _joystickDeadzoneLabel->setValue(value);
- }
+ int value = ConfMan.getInt("joystick_deadzone", _domain);
+ if (_joystickDeadzoneSlider != 0) {
+ _joystickDeadzoneSlider->setValue(value);
+ _joystickDeadzoneLabel->setValue(value);
}
}
Commit: 5838894f2434b027003a876ce795e2662597ce97
https://github.com/scummvm/scummvm/commit/5838894f2434b027003a876ce795e2662597ce97
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2017-12-26T21:11:04+01:00
Commit Message:
PSP2: Remove identical to base class joystick axis event handling
Changed paths:
backends/events/psp2sdl/psp2sdl-events.cpp
backends/events/psp2sdl/psp2sdl-events.h
diff --git a/backends/events/psp2sdl/psp2sdl-events.cpp b/backends/events/psp2sdl/psp2sdl-events.cpp
index f555459..ac3115a 100644
--- a/backends/events/psp2sdl/psp2sdl-events.cpp
+++ b/backends/events/psp2sdl/psp2sdl-events.cpp
@@ -272,46 +272,6 @@ bool PSP2EventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
return true;
}
-bool PSP2EventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) {
-
- int axis = ev.jaxis.value;
-
- // conversion factor between keyboard mouse and joy axis value
- int vel_to_axis = (1500 / MULTIPLIER);
-
- if (ev.jaxis.axis == JOY_XAXIS) {
- _km.joy_x = axis;
- } else if (ev.jaxis.axis == JOY_YAXIS) {
- axis = -axis;
- _km.joy_y = -axis;
- }
-
- // radial and scaled deadzone
-
- float analogX = (float)_km.joy_x;
- float analogY = (float)_km.joy_y;
- float deadZone = (float)JOY_DEADZONE;
- if (g_system->hasFeature(OSystem::kFeatureJoystickDeadzone))
- deadZone = (float)ConfMan.getInt("joystick_deadzone") * 1000.0f;
- float scalingFactor = 1.0f;
- float magnitude = 0.0f;
-
- magnitude = sqrt(analogX * analogX + analogY * analogY);
-
- if (magnitude >= deadZone) {
- _km.x_down_count = 0;
- _km.y_down_count = 0;
- scalingFactor = 1.0f / magnitude * (magnitude - deadZone) / (32769.0f - deadZone);
- _km.x_vel = (int16)(analogX * scalingFactor * 32768.0f / (float) vel_to_axis);
- _km.y_vel = (int16)(analogY * scalingFactor * 32768.0f / (float) vel_to_axis);
- } else {
- _km.x_vel = 0;
- _km.y_vel = 0;
- }
-
- return false;
-}
-
void PSP2EventSource::preprocessEvents(SDL_Event *event) {
// prevent suspend (scummvm games contains a lot of cutscenes..)
diff --git a/backends/events/psp2sdl/psp2sdl-events.h b/backends/events/psp2sdl/psp2sdl-events.h
index 001312e..e01a3b9 100644
--- a/backends/events/psp2sdl/psp2sdl-events.h
+++ b/backends/events/psp2sdl/psp2sdl-events.h
@@ -32,7 +32,6 @@ class PSP2EventSource : public SdlEventSource {
protected:
bool handleJoyButtonDown(SDL_Event &ev, Common::Event &event);
bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event);
- bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event);
void preprocessEvents(SDL_Event *event);
};
Commit: a86eae63235357c942a55f2b320187880ebe823e
https://github.com/scummvm/scummvm/commit/a86eae63235357c942a55f2b320187880ebe823e
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2017-12-26T21:11:05+01:00
Commit Message:
SDL: Only enable joystick related features when joysticks are enabled
Fixes #9714.
Changed paths:
backends/platform/sdl/sdl.cpp
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 360baf9..3082a69 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -182,8 +182,10 @@ bool OSystem_SDL::hasFeature(Feature f) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (f == kFeatureClipboardSupport) return true;
#endif
- if (f == kFeatureJoystickDeadzone) return true;
- if (f == kFeatureKbdMouseSpeed) return true;
+ if (f == kFeatureJoystickDeadzone || f == kFeatureKbdMouseSpeed) {
+ bool joystickSupportEnabled = ConfMan.getInt("joystick_num") >= 0;
+ return joystickSupportEnabled;
+ }
return ModularBackend::hasFeature(f);
}
Commit: 1522fc8e2f109229d9947158a1cd2ccc8c4642e1
https://github.com/scummvm/scummvm/commit/1522fc8e2f109229d9947158a1cd2ccc8c4642e1
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2017-12-26T21:11:05+01:00
Commit Message:
SDL: Add support for joystick hotplug
Fixes #10366.
Changed paths:
backends/events/sdl/sdl-events.cpp
backends/events/sdl/sdl-events.h
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index d4e8956..8a59aeb 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -87,37 +87,12 @@ SdlEventSource::SdlEventSource()
}
#endif
- // Enable joystick
- if (SDL_NumJoysticks() > joystick_num) {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- if (SDL_IsGameController(joystick_num)) {
- _controller = SDL_GameControllerOpen(joystick_num);
- debug("Using game controller: %s", SDL_GameControllerName(_controller));
- } else
-#endif
- {
- _joystick = SDL_JoystickOpen(joystick_num);
- debug("Using joystick: %s",
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_JoystickName(_joystick)
-#else
- SDL_JoystickName(joystick_num)
-#endif
- );
- }
- } else {
- warning("Invalid joystick: %d", joystick_num);
- }
+ openJoystick(joystick_num);
}
}
SdlEventSource::~SdlEventSource() {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- if (_controller)
- SDL_GameControllerClose(_controller);
-#endif
- if (_joystick)
- SDL_JoystickClose(_joystick);
+ closeJoystick();
}
int SdlEventSource::mapKey(SDLKey sdlKey, SDLMod mod, Uint16 unicode) {
@@ -617,6 +592,12 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
default:
return false;
}
+
+ case SDL_JOYDEVICEADDED:
+ return handleJoystickAdded(ev.jdevice);
+
+ case SDL_JOYDEVICEREMOVED:
+ return handleJoystickRemoved(ev.jdevice);
#else
case SDL_VIDEOEXPOSE:
if (_graphicsManager)
@@ -831,6 +812,42 @@ bool SdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) {
return processMouseEvent(event, ev.button.x, ev.button.y);
}
+void SdlEventSource::openJoystick(int joystickIndex) {
+ if (SDL_NumJoysticks() > joystickIndex) {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (SDL_IsGameController(joystickIndex)) {
+ _controller = SDL_GameControllerOpen(joystickIndex);
+ debug("Using game controller: %s", SDL_GameControllerName(_controller));
+ } else
+#endif
+ {
+ _joystick = SDL_JoystickOpen(joystickIndex);
+ debug("Using joystick: %s",
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ SDL_JoystickName(_joystick)
+#else
+ SDL_JoystickName(joystickIndex)
+#endif
+ );
+ }
+ } else {
+ warning("Invalid joystick: %d", joystickIndex);
+ }
+}
+
+void SdlEventSource::closeJoystick() {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (_controller) {
+ SDL_GameControllerClose(_controller);
+ _controller = nullptr;
+ }
+#endif
+ if (_joystick) {
+ SDL_JoystickClose(_joystick);
+ _joystick = nullptr;
+ }
+}
+
bool SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
event.type = Common::EVENT_LBUTTONDOWN;
@@ -906,6 +923,35 @@ bool SdlEventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) {
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
+bool SdlEventSource::handleJoystickAdded(const SDL_JoyDeviceEvent &device) {
+ int joystick_num = ConfMan.getInt("joystick_num");
+ if (joystick_num == device.which) {
+ closeJoystick();
+ openJoystick(joystick_num);
+ }
+
+ return false;
+}
+
+bool SdlEventSource::handleJoystickRemoved(const SDL_JoyDeviceEvent &device) {
+ SDL_Joystick *joystick;
+ if (_controller) {
+ joystick = SDL_GameControllerGetJoystick(_controller);
+ } else {
+ joystick = _joystick;
+ }
+
+ if (!joystick) {
+ return false;
+ }
+
+ if (SDL_JoystickInstanceID(joystick) == device.which) {
+ closeJoystick();
+ }
+
+ return false;
+}
+
bool SdlEventSource::handleControllerButton(const SDL_Event &ev, Common::Event &event, bool buttonUp) {
using namespace Common;
diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h
index 33d971a..f5bbfeb 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -94,6 +94,21 @@ protected:
SdlGraphicsManager *_graphicsManager;
/**
+ * Open the SDL joystick with the specified index
+ *
+ * After this function completes successfully, SDL sends events for the device.
+ *
+ * If the joystick is also a SDL game controller, open it as a controller
+ * so an extended button mapping can be used.
+ */
+ void openJoystick(int joystickIndex);
+
+ /**
+ * Close the currently open joystick if any
+ */
+ void closeJoystick();
+
+ /**
* Pre process an event before it is dispatched.
*/
virtual void preprocessEvents(SDL_Event *event) {}
@@ -123,6 +138,8 @@ protected:
virtual bool handleKbdMouse(Common::Event &event);
#if SDL_VERSION_ATLEAST(2, 0, 0)
+ virtual bool handleJoystickAdded(const SDL_JoyDeviceEvent &event);
+ virtual bool handleJoystickRemoved(const SDL_JoyDeviceEvent &device);
virtual bool handleControllerButton(const SDL_Event &ev, Common::Event &event, bool buttonUp);
virtual bool handleControllerAxisMotion(const SDL_Event &ev, Common::Event &event);
#endif
Commit: dafadbc8c77fe89d0504ddfdef159e1c37491f81
https://github.com/scummvm/scummvm/commit/dafadbc8c77fe89d0504ddfdef159e1c37491f81
Author: rsn8887 (rsn8887 at users.noreply.github.com)
Date: 2017-12-26T21:11:05+01:00
Commit Message:
PSP2: Add controller config, remove joystick event handling
Changed paths:
backends/events/psp2sdl/psp2sdl-events.cpp
backends/events/psp2sdl/psp2sdl-events.h
backends/platform/sdl/psp2/psp2.cpp
diff --git a/backends/events/psp2sdl/psp2sdl-events.cpp b/backends/events/psp2sdl/psp2sdl-events.cpp
index ac3115a..4ea528b 100644
--- a/backends/events/psp2sdl/psp2sdl-events.cpp
+++ b/backends/events/psp2sdl/psp2sdl-events.cpp
@@ -36,242 +36,6 @@
#include "math.h"
-#define JOY_DEADZONE 2000
-#define JOY_XAXIS 0
-#define JOY_YAXIS 1
-#define JOY_XAXISR 2
-#define JOY_YAXISR 3
-
-enum {
- BTN_LEFT = 7,
- BTN_DOWN = 6,
- BTN_RIGHT = 9,
- BTN_UP = 8,
-
- BTN_START = 11,
- BTN_SELECT = 10,
-
- BTN_SQUARE = 3,
- BTN_CROSS = 2,
- BTN_CIRCLE = 1,
- BTN_TRIANGLE = 0,
-
- BTN_R1 = 5,
- BTN_L1 = 4
-};
-
-bool PSP2EventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
-
- event.kbd.flags = 0;
-
- switch (ev.jbutton.button) {
-// Dpad
- case BTN_LEFT: // Left (+R_trigger: Up+Left)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_KP4;
- event.kbd.ascii = mapKey(SDLK_KP4, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_KP7;
- event.kbd.ascii = mapKey(SDLK_KP7, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
- case BTN_RIGHT: // Right (+R_trigger: Down+Right)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_KP6;
- event.kbd.ascii = mapKey(SDLK_KP6, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_KP3;
- event.kbd.ascii = mapKey(SDLK_KP3, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
- case BTN_UP: // Up (+R_trigger: Up+Right)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_KP8;
- event.kbd.ascii = mapKey(SDLK_KP8, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_KP9;
- event.kbd.ascii = mapKey(SDLK_KP9, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
- case BTN_DOWN: // Down (+R_trigger: Down+Left)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_KP2;
- event.kbd.ascii = mapKey(SDLK_KP2, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_KP1;
- event.kbd.ascii = mapKey(SDLK_KP1, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
-// Buttons
- case BTN_CROSS: // Left mouse button
- event.type = Common::EVENT_LBUTTONDOWN;
- processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
- break;
- case BTN_CIRCLE: // Right mouse button
- event.type = Common::EVENT_RBUTTONDOWN;
- processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
- break;
- case BTN_TRIANGLE: // Escape (+R_trigger: Return)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_ESCAPE;
- event.kbd.ascii = mapKey(SDLK_ESCAPE, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_RETURN;
- event.kbd.ascii = mapKey(SDLK_RETURN, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
- case BTN_SQUARE: // Period (+R_trigger: Space)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_PERIOD;
- event.kbd.ascii = mapKey(SDLK_PERIOD, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_SPACE;
- event.kbd.ascii = mapKey(SDLK_SPACE, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
- case BTN_L1: // Game menu
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_F5;
- event.kbd.ascii = mapKey(SDLK_F5, (SDLMod) ev.key.keysym.mod, 0);
- break;
- case BTN_R1: // Modifier + Shift
- _km.modifier=true; // slow mouse
- event.type = Common::EVENT_KEYDOWN;
- event.kbd.keycode = Common::KEYCODE_INVALID;
- event.kbd.ascii = 0;
- event.kbd.flags = Common::KBD_SHIFT;
- break;
- case BTN_START: // ScummVM in game menu
- event.type = Common::EVENT_MAINMENU;
- break;
- case BTN_SELECT: // Virtual keyboard (+R_trigger: Predictive Input Dialog)
- if (!_km.modifier) {
-#ifdef ENABLE_VKEYBD
- event.type = Common::EVENT_VIRTUAL_KEYBOARD;
-#endif
- } else {
- event.type = Common::EVENT_PREDICTIVE_DIALOG;
- }
- break;
- }
- return true;
-}
-
-bool PSP2EventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
-
- event.kbd.flags = 0;
-
- switch (ev.jbutton.button) {
-// Dpad
- case BTN_LEFT: // Left (+R_trigger: Up+Left)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_KP4;
- event.kbd.ascii = mapKey(SDLK_KP4, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_KP7;
- event.kbd.ascii = mapKey(SDLK_KP7, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
- case BTN_RIGHT: // Right (+R_trigger: Down+Right)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_KP6;
- event.kbd.ascii = mapKey(SDLK_KP6, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_KP3;
- event.kbd.ascii = mapKey(SDLK_KP3, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
- case BTN_UP: // Up (+R_trigger: Up+Right)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_KP8;
- event.kbd.ascii = mapKey(SDLK_KP8, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_KP9;
- event.kbd.ascii = mapKey(SDLK_KP9, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
- case BTN_DOWN: // Down (+R_trigger: Down+Left)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_KP2;
- event.kbd.ascii = mapKey(SDLK_KP2, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_KP1;
- event.kbd.ascii = mapKey(SDLK_KP1, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
-// Buttons
- case BTN_CROSS: // Left mouse button
- event.type = Common::EVENT_LBUTTONUP;
- processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
- break;
- case BTN_CIRCLE: // Right mouse button
- event.type = Common::EVENT_RBUTTONUP;
- processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
- break;
- case BTN_TRIANGLE: // Escape (+R_trigger: Return)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_ESCAPE;
- event.kbd.ascii = mapKey(SDLK_ESCAPE, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_RETURN;
- event.kbd.ascii = mapKey(SDLK_RETURN, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
- case BTN_SQUARE: // Period (+R_trigger: Space)
- if (!_km.modifier) {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_PERIOD;
- event.kbd.ascii = mapKey(SDLK_PERIOD, (SDLMod) ev.key.keysym.mod, 0);
- } else {
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_SPACE;
- event.kbd.ascii = mapKey(SDLK_SPACE, (SDLMod) ev.key.keysym.mod, 0);
- }
- break;
- case BTN_L1: // Game menu
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_F5;
- event.kbd.ascii = mapKey(SDLK_F5, (SDLMod) ev.key.keysym.mod, 0);
- break;
- case BTN_R1: // Modifier + SHIFT Key
- _km.modifier = false; // slow mouse
- event.type = Common::EVENT_KEYUP;
- event.kbd.keycode = Common::KEYCODE_INVALID;
- event.kbd.ascii = 0;
- event.kbd.flags = 0;
- break;
- case BTN_START: // ScummVM in game menu
- // Handled in key down
- break;
- case BTN_SELECT: // Virtual keyboard (+R_trigger: Predictive Input Dialog)
- // Handled in key down
- break;
- }
- return true;
-}
-
void PSP2EventSource::preprocessEvents(SDL_Event *event) {
// prevent suspend (scummvm games contains a lot of cutscenes..)
diff --git a/backends/events/psp2sdl/psp2sdl-events.h b/backends/events/psp2sdl/psp2sdl-events.h
index e01a3b9..5593e8a 100644
--- a/backends/events/psp2sdl/psp2sdl-events.h
+++ b/backends/events/psp2sdl/psp2sdl-events.h
@@ -30,8 +30,6 @@
*/
class PSP2EventSource : public SdlEventSource {
protected:
- bool handleJoyButtonDown(SDL_Event &ev, Common::Event &event);
- bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event);
void preprocessEvents(SDL_Event *event);
};
diff --git a/backends/platform/sdl/psp2/psp2.cpp b/backends/platform/sdl/psp2/psp2.cpp
index f323db7..12154ba 100644
--- a/backends/platform/sdl/psp2/psp2.cpp
+++ b/backends/platform/sdl/psp2/psp2.cpp
@@ -102,6 +102,14 @@ void OSystem_PSP2::initBackend() {
if (_savefileManager == 0)
_savefileManager = new DefaultSaveFileManager("ux0:data/scummvm/saves");
+ // Controller mappings for Vita, various names have been used in various SDL versions
+ SDL_GameControllerAddMapping("50535669746120436f6e74726f6c6c65,PSVita Controller,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
+ SDL_GameControllerAddMapping("50535669746120636f6e74726f6c6c65,PSVita controller,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
+ SDL_GameControllerAddMapping("50535669746120636f6e74726f6c6c65,PSVita controller 2,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
+ SDL_GameControllerAddMapping("50535669746120636f6e74726f6c6c65,PSVita controller 3,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
+ SDL_GameControllerAddMapping("50535669746120636f6e74726f6c6c65,PSVita controller 4,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
+ SDL_GameControllerAddMapping("505356697461206275696c74696e206a,PSVita builtin joypad,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
+
// Event source
if (_eventSource == 0)
_eventSource = new PSP2EventSource();
More information about the Scummvm-git-logs
mailing list