diff --git a/Changes.txt b/Changes.txt index 171fa9160..fe4b7207f 100644 --- a/Changes.txt +++ b/Changes.txt @@ -34,6 +34,9 @@ * Fixed autofire bug for trackball controllers. + * Fixed Stelladaptor/2600'daptor devices sometimes not being assigned + correct default mappings. + * Codebase now uses C++17 features. -Have fun! diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index e0ebb55f1..2fd8329fd 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -132,12 +132,13 @@ int PhysicalJoystickHandler::add(const PhysicalJoystickPtr& stick) name << stick->name << " #" << count+1; 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 mySticks[stick->ID] = stick; // Map the stelladaptors we've found according to the specified ports + // The 'type' is also set there if(specialAdaptor) mapStelladaptors(myOSystem.settings().getString("saport")); @@ -236,12 +237,12 @@ void PhysicalJoystickHandler::mapStelladaptors(const string& saport) if(saOrder[saCount] == 1) { _joyptr->name += " (emulates left joystick port)"; - _joyptr->type = PhysicalJoystick::JT_STELLADAPTOR_LEFT; + _joyptr->type = PhysicalJoystick::Type::LEFT_STELLADAPTOR; } else if(saOrder[saCount] == 2) { _joyptr->name += " (emulates right joystick port)"; - _joyptr->type = PhysicalJoystick::JT_STELLADAPTOR_RIGHT; + _joyptr->type = PhysicalJoystick::Type::RIGHT_STELLADAPTOR; } saCount++; } @@ -250,12 +251,12 @@ void PhysicalJoystickHandler::mapStelladaptors(const string& saport) if(saOrder[saCount] == 1) { _joyptr->name += " (emulates left joystick port)"; - _joyptr->type = PhysicalJoystick::JT_2600DAPTOR_LEFT; + _joyptr->type = PhysicalJoystick::Type::LEFT_2600DAPTOR; } else if(saOrder[saCount] == 2) { _joyptr->name += " (emulates right joystick port)"; - _joyptr->type = PhysicalJoystick::JT_2600DAPTOR_RIGHT; + _joyptr->type = PhysicalJoystick::Type::RIGHT_2600DAPTOR; } saCount++; } @@ -313,7 +314,15 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, Event::Type even switch (mode) { 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 for (const auto& item : DefaultLeftJoystickMapping) @@ -323,7 +332,7 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, Event::Type even for (const auto& item : DefaultLeftKeypadMapping) setDefaultAction(stick, item, event, EventMode::kKeypadMode, updateDefaults); } - else // odd sticks + else { // put all controller events into their own mode's mappings for (const auto& item : DefaultRightJoystickMapping) @@ -338,6 +347,7 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, Event::Type even // update running emulation mapping too enableEmulationMappings(); break; + } case EventMode::kMenuMode: 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 //#if defined(RETRON77) {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 {Event::UISelect, 0}, {Event::UIOK, 1}, diff --git a/src/common/PhysicalJoystick.hxx b/src/common/PhysicalJoystick.hxx index cf0456c0e..82b7106a1 100644 --- a/src/common/PhysicalJoystick.hxx +++ b/src/common/PhysicalJoystick.hxx @@ -59,17 +59,13 @@ class PhysicalJoystick int axes, int buttons, int hats, int balls); private: - // TODO: these are not required anymore, delete or keep for future usage? - enum JoyType { - JT_NONE = 0, - JT_REGULAR = 1, - JT_STELLADAPTOR_LEFT = 2, - JT_STELLADAPTOR_RIGHT = 3, - JT_2600DAPTOR_LEFT = 4, - JT_2600DAPTOR_RIGHT = 5 + enum class Type { + REGULAR, + LEFT_STELLADAPTOR, RIGHT_STELLADAPTOR, + LEFT_2600DAPTOR, RIGHT_2600DAPTOR }; - JoyType type{JT_NONE}; + Type type{Type::REGULAR}; int ID{-1}; string name{"None"}; int numAxes{0}, numButtons{0}, numHats{0};