diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 86e6a299c..83d90b5aa 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -485,45 +485,69 @@ void PhysicalJoystickHandler::setDefaultMapping(Event::Type event, EventMode mod } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PhysicalJoystickHandler::defineControllerMappings(const Controller::Type type, Controller::Jack port) +void PhysicalJoystickHandler::defineControllerMappings(const Controller::Type type, Controller::Jack port, + const Properties& properties) +{ + // Determine controller events to use + if(type == Controller::Type::QuadTari) + { + if(port == Controller::Jack::Left) + { + myLeftMode = getMode(properties, PropType::Controller_Left1); + myLeft2ndMode = getMode(properties, PropType::Controller_Left2); + } + else + { + myRightMode = getMode(properties, PropType::Controller_Right1); + myRight2ndMode = getMode(properties, PropType::Controller_Right2); + } + } + else + { + const EventMode mode = getMode(type); + + if(port == Controller::Jack::Left) + myLeftMode = mode; + else + myRightMode = mode; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +EventMode PhysicalJoystickHandler::getMode(const Properties& properties, + const PropType propType) +{ + const string& propName = properties.get(propType); + + if(!propName.empty()) + return getMode(Controller::getType(propName)); + + return EventMode::kJoystickMode; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +EventMode PhysicalJoystickHandler::getMode(const Controller::Type type) { - // determine controller events to use switch(type) { case Controller::Type::Keyboard: case Controller::Type::KidVid: - if(port == Controller::Jack::Left) - myLeftMode = EventMode::kKeyboardMode; - else - myRightMode = EventMode::kKeyboardMode; - break; + return EventMode::kKeyboardMode; case Controller::Type::Paddles: case Controller::Type::PaddlesIAxDr: case Controller::Type::PaddlesIAxis: - if(port == Controller::Jack::Left) - myLeftMode = EventMode::kPaddlesMode; - else - myRightMode = EventMode::kPaddlesMode; - break; + return EventMode::kPaddlesMode; case Controller::Type::CompuMate: - myLeftMode = myRightMode = EventMode::kCompuMateMode; - break; + return EventMode::kCompuMateMode; case Controller::Type::Driving: - if(port == Controller::Jack::Left) - myLeftMode = EventMode::kDrivingMode; - else - myRightMode = EventMode::kDrivingMode; - break; + return EventMode::kDrivingMode; default: // let's use joystick then - if(port == Controller::Jack::Left) - myLeftMode = EventMode::kJoystickMode; - else - myRightMode = EventMode::kJoystickMode; + return EventMode::kJoystickMode; } } @@ -540,6 +564,36 @@ void PhysicalJoystickHandler::enableEmulationMappings() enableCommonMappings(); + // Process in increasing priority order, so that in case of mapping clashes + // the higher priority controller has preference + switch(myRight2ndMode) + { + case EventMode::kPaddlesMode: + enableMappings(QTPaddles4Events, EventMode::kPaddlesMode); + break; + + case EventMode::kEmulationMode: // no QuadTari + break; + + default: + enableMappings(QTJoystick4Events, EventMode::kJoystickMode); + break; + } + + switch(myLeft2ndMode) + { + case EventMode::kPaddlesMode: + enableMappings(QTPaddles3Events, EventMode::kPaddlesMode); + break; + + case EventMode::kEmulationMode: // no QuadTari + break; + + default: + enableMappings(QTJoystick3Events, EventMode::kJoystickMode); + break; + } + // enable right mode first, so that in case of mapping clashes the left controller has preference switch (myRightMode) { @@ -644,14 +698,18 @@ EventMode PhysicalJoystickHandler::getEventMode(const Event::Type event, bool PhysicalJoystickHandler::isJoystickEvent(const Event::Type event) { return LeftJoystickEvents.find(event) != LeftJoystickEvents.end() - || RightJoystickEvents.find(event) != RightJoystickEvents.end(); + || QTJoystick3Events.find(event) != QTJoystick3Events.end() + || RightJoystickEvents.find(event) != RightJoystickEvents.end() + || QTJoystick4Events.find(event) != QTJoystick4Events.end(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool PhysicalJoystickHandler::isPaddleEvent(const Event::Type event) { return LeftPaddlesEvents.find(event) != LeftPaddlesEvents.end() - || RightPaddlesEvents.find(event) != RightPaddlesEvents.end(); + || QTPaddles3Events.find(event) != QTPaddles3Events.end() + || RightPaddlesEvents.find(event) != RightPaddlesEvents.end() + || QTPaddles4Events.find(event) != QTPaddles4Events.end(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -671,7 +729,8 @@ bool PhysicalJoystickHandler::isDrivingEvent(const Event::Type event) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool PhysicalJoystickHandler::isCommonEvent(const Event::Type event) { - return !(isJoystickEvent(event) || isPaddleEvent(event) || isKeyboardEvent(event) || isDrivingEvent(event)); + return !(isJoystickEvent(event) || isPaddleEvent(event) + || isKeyboardEvent(event) || isDrivingEvent(event)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/PJoystickHandler.hxx b/src/common/PJoystickHandler.hxx index 6b95910be..cbba9b0c0 100644 --- a/src/common/PJoystickHandler.hxx +++ b/src/common/PJoystickHandler.hxx @@ -79,10 +79,16 @@ class PhysicalJoystickHandler void setDefaultMapping(Event::Type event, EventMode mode); /** define mappings for current controllers */ - void defineControllerMappings(const Controller::Type type, Controller::Jack port); + void defineControllerMappings(const Controller::Type type, Controller::Jack port, + const Properties& properties); /** enable mappings for emulation mode */ void enableEmulationMappings(); + /** return event mode for given property */ + EventMode getMode(const Properties& properties, const PropType propType); + /** return event mode for given controller type */ + EventMode getMode(const Controller::Type type); + void eraseMapping(Event::Type event, EventMode mode); void saveMapping(); string getMappingDesc(Event::Type, EventMode mode) const; @@ -196,6 +202,9 @@ class PhysicalJoystickHandler private: EventMode myLeftMode{EventMode::kEmulationMode}; EventMode myRightMode{EventMode::kEmulationMode}; + // Additional modes for QuadTari controller + EventMode myLeft2ndMode{EventMode::kEmulationMode}; + EventMode myRight2ndMode{EventMode::kEmulationMode}; // Controller menu and common emulation mappings static EventMappingArray DefaultMenuMapping; diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index e66ca015d..832558175 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -221,31 +221,27 @@ void PhysicalKeyboardHandler::defineControllerMappings( const Controller::Type type, Controller::Jack port, const Properties& properties) { // Determine controller events to use - switch(type) // NOLINT (could be written as IF/ELSE) + if(type == Controller::Type::QuadTari) { - case Controller::Type::QuadTari: - if(port == Controller::Jack::Left) - { - myLeftMode = getMode(properties, PropType::Controller_Left1); - myLeft2ndMode = getMode(properties, PropType::Controller_Left2); - } - else - { - myRightMode = getMode(properties, PropType::Controller_Right1); - myRight2ndMode = getMode(properties, PropType::Controller_Right2); - } - break; - - default: + if(port == Controller::Jack::Left) { - const EventMode mode = getMode(type); - - if(port == Controller::Jack::Left) - myLeftMode = mode; - else - myRightMode = mode; - break; + myLeftMode = getMode(properties, PropType::Controller_Left1); + myLeft2ndMode = getMode(properties, PropType::Controller_Left2); } + else + { + myRightMode = getMode(properties, PropType::Controller_Right1); + myRight2ndMode = getMode(properties, PropType::Controller_Right2); + } + } + else + { + const EventMode mode = getMode(type); + + if(port == Controller::Jack::Left) + myLeftMode = mode; + else + myRightMode = mode; } } @@ -258,7 +254,7 @@ EventMode PhysicalKeyboardHandler::getMode(const Properties& properties, if(!propName.empty()) return getMode(Controller::getType(propName)); - return getMode(Controller::Type::Joystick); + return EventMode::kJoystickMode; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -446,13 +442,6 @@ bool PhysicalKeyboardHandler::isPaddleEvent(const Event::Type event) || QTPaddles4Events.find(event) != QTPaddles4Events.end(); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool PhysicalKeyboardHandler::isDrivingEvent(const Event::Type event) -{ - return LeftDrivingEvents.find(event) != LeftDrivingEvents.end() - || RightDrivingEvents.find(event) != RightDrivingEvents.end(); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool PhysicalKeyboardHandler::isKeyboardEvent(const Event::Type event) { @@ -460,10 +449,18 @@ bool PhysicalKeyboardHandler::isKeyboardEvent(const Event::Type event) || RightKeyboardEvents.find(event) != RightKeyboardEvents.end(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool PhysicalKeyboardHandler::isDrivingEvent(const Event::Type event) +{ + return LeftDrivingEvents.find(event) != LeftDrivingEvents.end() + || RightDrivingEvents.find(event) != RightDrivingEvents.end(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool PhysicalKeyboardHandler::isCommonEvent(const Event::Type event) { - return !(isJoystickEvent(event) || isPaddleEvent(event) || isKeyboardEvent(event)); + return !(isJoystickEvent(event) || isPaddleEvent(event) + || isKeyboardEvent(event) || isDrivingEvent(event)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 22ccd847f..d5c2bfd81 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -856,7 +856,7 @@ void Console::setControllers(string_view romMd5) myOSystem.eventHandler().defineKeyControllerMappings( Controller::Type::CompuMate, Controller::Jack::Left, myProperties); myOSystem.eventHandler().defineJoyControllerMappings( - Controller::Type::CompuMate, Controller::Jack::Left); + Controller::Type::CompuMate, Controller::Jack::Left, myProperties); } else { @@ -947,7 +947,7 @@ unique_ptr Console::getControllerPort( unique_ptr controller; myOSystem.eventHandler().defineKeyControllerMappings(type, port, myProperties); - myOSystem.eventHandler().defineJoyControllerMappings(type, port); + myOSystem.eventHandler().defineJoyControllerMappings(type, port, myProperties); switch(type) { diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index 93e64acd1..d3956ec9d 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -279,8 +279,9 @@ class EventHandler /** Enable controller specific keyboard event mappings. */ - void defineJoyControllerMappings(const Controller::Type type, Controller::Jack port) { - myPJoyHandler->defineControllerMappings(type, port); + void defineJoyControllerMappings(const Controller::Type type, Controller::Jack port, + const Properties& properties) { + myPJoyHandler->defineControllerMappings(type, port, properties); } /**