use event version check for joymap too

This commit is contained in:
thrust26 2019-05-30 11:16:07 +02:00
parent d231da4558
commit be1a51b5b4
2 changed files with 30 additions and 18 deletions

View File

@ -34,13 +34,14 @@ PhysicalJoystickHandler::PhysicalJoystickHandler(
myHandler(handler), myHandler(handler),
myEvent(event) myEvent(event)
{ {
Int32 version = myOSystem.settings().getInt("event_ver");
// Load previously saved joystick mapping (if any) from settings // Load previously saved joystick mapping (if any) from settings
istringstream buf(myOSystem.settings().getString("joymap")); istringstream buf(myOSystem.settings().getString("joymap"));
string joymap, joyname; string joymap, joyname;
// First check the event type, and disregard the entire mapping if it's invalid // First compare if event list version has changed, and disregard the entire mapping if true
getline(buf, joymap, '^'); getline(buf, joymap, '^'); // event list size, ignore
if(atoi(joymap.c_str()) == Event::LastType) if(version != Event::VERSION)
{ {
// Otherwise, put each joystick mapping entry into the database // Otherwise, put each joystick mapping entry into the database
while(getline(buf, joymap, '^')) while(getline(buf, joymap, '^'))
@ -250,10 +251,10 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
{ {
bool eraseAll = (event == Event::NoType); bool eraseAll = (event == Event::NoType);
auto setDefaultAxis = [&](int a_stick, int a_axis, int a_value, Event::Type a_event) auto setDefaultAxis = [&](int a_stick, JoyAxis a_axis, JoyDir a_value, Event::Type a_event)
{ {
if(eraseAll || a_event == event) if(eraseAll || a_event == event)
myHandler.addJoyAxisMapping(a_event, mode, a_stick, a_axis, a_value, false); myHandler.addJoyAxisMapping(a_event, mode, a_stick, int(a_axis), int(a_value), false);
}; };
auto setDefaultBtn = [&](int b_stick, int b_button, Event::Type b_event) auto setDefaultBtn = [&](int b_stick, int b_button, Event::Type b_event)
{ {
@ -274,11 +275,11 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
case 0: case 0:
case 2: case 2:
// Left joystick left/right directions (assume joystick zero or two) // Left joystick left/right directions (assume joystick zero or two)
setDefaultAxis(stick, 0, 0, Event::JoystickZeroLeft); setDefaultAxis(stick, JoyAxis::X, JoyDir::NEG, Event::JoystickZeroLeft);
setDefaultAxis(stick, 0, 1, Event::JoystickZeroRight); setDefaultAxis(stick, JoyAxis::X, JoyDir::POS, Event::JoystickZeroRight);
// Left joystick up/down directions (assume joystick zero or two) // Left joystick up/down directions (assume joystick zero or two)
setDefaultAxis(stick, 1, 0, Event::JoystickZeroUp); setDefaultAxis(stick, JoyAxis::Y, JoyDir::NEG, Event::JoystickZeroUp);
setDefaultAxis(stick, 1, 1, Event::JoystickZeroDown); setDefaultAxis(stick, JoyAxis::Y, JoyDir::POS, Event::JoystickZeroDown);
// Left joystick (assume joystick zero or two, buttons zero..two) // Left joystick (assume joystick zero or two, buttons zero..two)
setDefaultBtn(stick, 0, Event::JoystickZeroFire); setDefaultBtn(stick, 0, Event::JoystickZeroFire);
setDefaultBtn(stick, 1, Event::JoystickZeroFire5); setDefaultBtn(stick, 1, Event::JoystickZeroFire5);
@ -299,11 +300,11 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
case 1: case 1:
case 3: case 3:
// Right joystick left/right directions (assume joystick one or three) // Right joystick left/right directions (assume joystick one or three)
setDefaultAxis(stick, 0, 0, Event::JoystickOneLeft); setDefaultAxis(stick, JoyAxis::X, JoyDir::NEG, Event::JoystickOneLeft);
setDefaultAxis(stick, 0, 1, Event::JoystickOneRight); setDefaultAxis(stick, JoyAxis::X, JoyDir::POS, Event::JoystickOneRight);
// Right joystick left/right directions (assume joystick one or three) // Right joystick left/right directions (assume joystick one or three)
setDefaultAxis(stick, 1, 0, Event::JoystickOneUp); setDefaultAxis(stick, JoyAxis::Y, JoyDir::NEG, Event::JoystickOneUp);
setDefaultAxis(stick, 1, 1, Event::JoystickOneDown); setDefaultAxis(stick, JoyAxis::Y, JoyDir::POS, Event::JoystickOneDown);
// Right joystick (assume joystick one or three, buttons zero..two) // Right joystick (assume joystick one or three, buttons zero..two)
setDefaultBtn(stick, 0, Event::JoystickOneFire); setDefaultBtn(stick, 0, Event::JoystickOneFire);
setDefaultBtn(stick, 1, Event::JoystickOneFire5); setDefaultBtn(stick, 1, Event::JoystickOneFire5);
@ -330,10 +331,10 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
break; break;
case kMenuMode: // Default menu/UI events case kMenuMode: // Default menu/UI events
setDefaultAxis( stick, 0, 0, Event::UINavPrev ); setDefaultAxis( stick, JoyAxis::X, JoyDir::NEG, Event::UINavPrev );
setDefaultAxis( stick, 0, 1, Event::UINavNext ); setDefaultAxis( stick, JoyAxis::X, JoyDir::POS, Event::UINavNext );
setDefaultAxis( stick, 1, 0, Event::UIUp ); setDefaultAxis( stick, JoyAxis::Y, JoyDir::NEG, Event::UIUp );
setDefaultAxis( stick, 1, 1, Event::UIDown ); setDefaultAxis( stick, JoyAxis::Y, JoyDir::POS, Event::UIDown );
// joystick (assume buttons zero..three) // joystick (assume buttons zero..three)
setDefaultBtn( stick, 0, Event::UISelect ); setDefaultBtn( stick, 0, Event::UISelect );
@ -465,7 +466,7 @@ bool PhysicalJoystickHandler::addAxisMapping(Event::Type event, EventMode mode,
const PhysicalJoystickPtr j = joy(stick); const PhysicalJoystickPtr j = joy(stick);
if(j) if(j)
{ {
if(axis >= 0 && axis < j->numAxes && event < Event::LastType) if(int(axis) >= 0 && int(axis) < j->numAxes && event < Event::LastType)
{ {
// This confusing code is because each axis has two associated values, // This confusing code is because each axis has two associated values,
// but analog events only affect one of the axis. // but analog events only affect one of the axis.

View File

@ -38,6 +38,17 @@ enum class MouseButton {
NONE NONE
}; };
enum class JoyAxis {
X = 0,
Y = 1,
};
enum class JoyDir {
NEG = 0,
POS = 1,
};
enum class JoyHat { enum class JoyHat {
UP = 0, // make sure these are set correctly, UP = 0, // make sure these are set correctly,
DOWN = 1, // since they'll be used as array indices DOWN = 1, // since they'll be used as array indices