fixed QuadTari mapping storage

This commit is contained in:
thrust26 2023-06-12 17:45:18 +02:00
parent 0de952b0cb
commit ee13c16930
5 changed files with 128 additions and 62 deletions

View File

@ -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));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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;

View File

@ -221,9 +221,8 @@ 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);
@ -234,9 +233,8 @@ void PhysicalKeyboardHandler::defineControllerMappings(
myRightMode = getMode(properties, PropType::Controller_Right1);
myRight2ndMode = getMode(properties, PropType::Controller_Right2);
}
break;
default:
}
else
{
const EventMode mode = getMode(type);
@ -244,8 +242,6 @@ void PhysicalKeyboardHandler::defineControllerMappings(
myLeftMode = mode;
else
myRightMode = mode;
break;
}
}
}
@ -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));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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<Controller> Console::getControllerPort(
unique_ptr<Controller> controller;
myOSystem.eventHandler().defineKeyControllerMappings(type, port, myProperties);
myOSystem.eventHandler().defineJoyControllerMappings(type, port);
myOSystem.eventHandler().defineJoyControllerMappings(type, port, myProperties);
switch(type)
{

View File

@ -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);
}
/**