Fix 'daptor devices sometimes not getting correct default mappings (fixes #685).

This commit is contained in:
Stephen Anthony 2020-12-14 15:34:05 -03:30
parent dfa15f0086
commit e7715aea9d
3 changed files with 29 additions and 18 deletions

View File

@ -34,6 +34,9 @@
* Fixed autofire bug for trackball controllers. * Fixed autofire bug for trackball controllers.
* Fixed Stelladaptor/2600'daptor devices sometimes not being assigned
correct default mappings.
* Codebase now uses C++17 features. * Codebase now uses C++17 features.
-Have fun! -Have fun!

View File

@ -132,12 +132,13 @@ int PhysicalJoystickHandler::add(const PhysicalJoystickPtr& stick)
name << stick->name << " #" << count+1; name << stick->name << " #" << count+1;
stick->name = name.str(); stick->name = name.str();
} }
stick->type = PhysicalJoystick::JT_REGULAR; stick->type = PhysicalJoystick::Type::REGULAR;
} }
// The stick *must* be inserted here, since it may be used below // The stick *must* be inserted here, since it may be used below
mySticks[stick->ID] = stick; mySticks[stick->ID] = stick;
// Map the stelladaptors we've found according to the specified ports // Map the stelladaptors we've found according to the specified ports
// The 'type' is also set there
if(specialAdaptor) if(specialAdaptor)
mapStelladaptors(myOSystem.settings().getString("saport")); mapStelladaptors(myOSystem.settings().getString("saport"));
@ -236,12 +237,12 @@ void PhysicalJoystickHandler::mapStelladaptors(const string& saport)
if(saOrder[saCount] == 1) if(saOrder[saCount] == 1)
{ {
_joyptr->name += " (emulates left joystick port)"; _joyptr->name += " (emulates left joystick port)";
_joyptr->type = PhysicalJoystick::JT_STELLADAPTOR_LEFT; _joyptr->type = PhysicalJoystick::Type::LEFT_STELLADAPTOR;
} }
else if(saOrder[saCount] == 2) else if(saOrder[saCount] == 2)
{ {
_joyptr->name += " (emulates right joystick port)"; _joyptr->name += " (emulates right joystick port)";
_joyptr->type = PhysicalJoystick::JT_STELLADAPTOR_RIGHT; _joyptr->type = PhysicalJoystick::Type::RIGHT_STELLADAPTOR;
} }
saCount++; saCount++;
} }
@ -250,12 +251,12 @@ void PhysicalJoystickHandler::mapStelladaptors(const string& saport)
if(saOrder[saCount] == 1) if(saOrder[saCount] == 1)
{ {
_joyptr->name += " (emulates left joystick port)"; _joyptr->name += " (emulates left joystick port)";
_joyptr->type = PhysicalJoystick::JT_2600DAPTOR_LEFT; _joyptr->type = PhysicalJoystick::Type::LEFT_2600DAPTOR;
} }
else if(saOrder[saCount] == 2) else if(saOrder[saCount] == 2)
{ {
_joyptr->name += " (emulates right joystick port)"; _joyptr->name += " (emulates right joystick port)";
_joyptr->type = PhysicalJoystick::JT_2600DAPTOR_RIGHT; _joyptr->type = PhysicalJoystick::Type::RIGHT_2600DAPTOR;
} }
saCount++; saCount++;
} }
@ -313,7 +314,15 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, Event::Type even
switch (mode) switch (mode)
{ {
case EventMode::kEmulationMode: case EventMode::kEmulationMode:
if((stick % 2) == 0) // even sticks {
// A regular joystick defaults to left or right based on the
// stick number being even or odd; 'daptor joysticks request a
// specific port
const bool useLeftMappings =
j->type == PhysicalJoystick::Type::REGULAR ? ((stick % 2) == 0) :
(j->type == PhysicalJoystick::Type::LEFT_STELLADAPTOR ||
j->type == PhysicalJoystick::Type::LEFT_2600DAPTOR);
if(useLeftMappings)
{ {
// put all controller events into their own mode's mappings // put all controller events into their own mode's mappings
for (const auto& item : DefaultLeftJoystickMapping) for (const auto& item : DefaultLeftJoystickMapping)
@ -323,7 +332,7 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, Event::Type even
for (const auto& item : DefaultLeftKeypadMapping) for (const auto& item : DefaultLeftKeypadMapping)
setDefaultAction(stick, item, event, EventMode::kKeypadMode, updateDefaults); setDefaultAction(stick, item, event, EventMode::kKeypadMode, updateDefaults);
} }
else // odd sticks else
{ {
// put all controller events into their own mode's mappings // put all controller events into their own mode's mappings
for (const auto& item : DefaultRightJoystickMapping) for (const auto& item : DefaultRightJoystickMapping)
@ -338,6 +347,7 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, Event::Type even
// update running emulation mapping too // update running emulation mapping too
enableEmulationMappings(); enableEmulationMappings();
break; break;
}
case EventMode::kMenuMode: case EventMode::kMenuMode:
for (const auto& item : DefaultMenuMapping) for (const auto& item : DefaultMenuMapping)
@ -953,7 +963,8 @@ PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultRight
}; };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultCommonMapping = { PhysicalJoystickHandler::EventMappingArray
PhysicalJoystickHandler::DefaultCommonMapping = {
// valid for all joysticks // valid for all joysticks
//#if defined(RETRON77) //#if defined(RETRON77)
{Event::CmdMenuMode, 3}, // Note: buttons 0..2 are used by controllers! {Event::CmdMenuMode, 3}, // Note: buttons 0..2 are used by controllers!
@ -966,7 +977,8 @@ PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultCommo
}; };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultMenuMapping = { PhysicalJoystickHandler::EventMappingArray
PhysicalJoystickHandler::DefaultMenuMapping = {
// valid for all joysticks // valid for all joysticks
{Event::UISelect, 0}, {Event::UISelect, 0},
{Event::UIOK, 1}, {Event::UIOK, 1},

View File

@ -59,17 +59,13 @@ class PhysicalJoystick
int axes, int buttons, int hats, int balls); int axes, int buttons, int hats, int balls);
private: private:
// TODO: these are not required anymore, delete or keep for future usage? enum class Type {
enum JoyType { REGULAR,
JT_NONE = 0, LEFT_STELLADAPTOR, RIGHT_STELLADAPTOR,
JT_REGULAR = 1, LEFT_2600DAPTOR, RIGHT_2600DAPTOR
JT_STELLADAPTOR_LEFT = 2,
JT_STELLADAPTOR_RIGHT = 3,
JT_2600DAPTOR_LEFT = 4,
JT_2600DAPTOR_RIGHT = 5
}; };
JoyType type{JT_NONE}; Type type{Type::REGULAR};
int ID{-1}; int ID{-1};
string name{"None"}; string name{"None"};
int numAxes{0}, numButtons{0}, numHats{0}; int numAxes{0}, numButtons{0}, numHats{0};