From 96a8ccc814316d88a63768d3abdcf33ca3a4eea7 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Wed, 14 Aug 2019 09:47:34 +0200 Subject: [PATCH] remove some debugging output refactored controller mapping loading --- src/common/PJoystickHandler.cxx | 1 - src/common/PhysicalJoystick.cxx | 41 ++++++++++++++++----------- src/common/PhysicalJoystick.hxx | 1 + src/emucore/EventHandlerConstants.hxx | 13 ++++----- src/gui/DialogContainer.cxx | 2 -- src/gui/EventMappingWidget.cxx | 9 ------ 6 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 4a8cf71ca..6c4fbc0a3 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -665,7 +665,6 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value) if (value != j->axisLastValue[axis]) { #ifdef GUI_SUPPORT - cerr << "axis event" << endl; myHandler.overlay().handleJoyAxisEvent(stick, axis, value, button); #endif j->axisLastValue[axis] = value; diff --git a/src/common/PhysicalJoystick.cxx b/src/common/PhysicalJoystick.cxx index ff5b9b3c4..d36e31cd2 100644 --- a/src/common/PhysicalJoystick.cxx +++ b/src/common/PhysicalJoystick.cxx @@ -67,11 +67,11 @@ void PhysicalJoystick::initialize(int index, const string& desc, axisLastValue[a] = 0; // Erase the mappings + eraseMap(kMenuMode); eraseMap(kJoystickMode); eraseMap(kPaddlesMode); eraseMap(kKeypadMode); - eraseMap(kMenuMode); - + eraseMap(kCommonMode); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -96,24 +96,33 @@ string PhysicalJoystick::getMap() const bool PhysicalJoystick::setMap(const string& mapString) { istringstream buf(mapString); - StringList mappings; string map; + int i = 0; + + // Skip joystick name + getline(buf, map, MODE_DELIM); while (getline(buf, map, MODE_DELIM)) { - // remove leading "|" string - map.erase(0, 2); - mappings.push_back(map); - } - // Error checking - if(mappings.size() != 1 + 5) - return false; + int mode; - joyMap.loadMapping(mappings[1], kMenuMode); - joyMap.loadMapping(mappings[2], kJoystickMode); - joyMap.loadMapping(mappings[3], kPaddlesMode); - joyMap.loadMapping(mappings[4], kKeypadMode); - joyMap.loadMapping(mappings[5], kCommonMode); + // Get event mode + std::replace(map.begin(), map.end(), '|', ' '); + istringstream modeBuf(map); + modeBuf >> mode; + + // Remove leading "|" string + map.erase(0, 2); + + joyMap.loadMapping(map, EventMode(mode)); + i++; + } + // Brief error checking + if(i != 5) + { + cerr << "ERROR: Invalid controller mappings found" << endl; + return false; + } return true; } @@ -146,7 +155,7 @@ void PhysicalJoystick::getValues(const string& list, IntArray& map) const string PhysicalJoystick::about() const { ostringstream buf; - buf << " with: " << numAxes << " axes, " << numButtons << " buttons, " + buf << "'" << name << "' with: " << numAxes << " axes, " << numButtons << " buttons, " << numHats << " hats"; return buf.str(); diff --git a/src/common/PhysicalJoystick.hxx b/src/common/PhysicalJoystick.hxx index 81131d03a..eead7901a 100644 --- a/src/common/PhysicalJoystick.hxx +++ b/src/common/PhysicalJoystick.hxx @@ -56,6 +56,7 @@ 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, diff --git a/src/emucore/EventHandlerConstants.hxx b/src/emucore/EventHandlerConstants.hxx index 78f184654..d0b1e373d 100644 --- a/src/emucore/EventHandlerConstants.hxx +++ b/src/emucore/EventHandlerConstants.hxx @@ -54,7 +54,6 @@ enum class JoyDir { ANALOG = 2 }; - enum class JoyHat { UP = 0, // make sure these are set correctly, DOWN = 1, // since they'll be used as array indices @@ -79,17 +78,15 @@ static const int NUM_JOY_HAT_DIRS = 4; // TODO - make this 'enum class' somehow enum EventMode { - kEmulationMode = 0, // make sure these are set correctly, - kMenuMode = 1, // since they'll be used as array indices - kNumModes = 2, - kJoystickMode = kNumModes, // 5 extra modes for mapping controller keys separately + kEmulationMode, // active mapping used for emulation + kMenuMode, // mapping used for dialogs + kJoystickMode, // 4 extra modes for mapping controller keys separately for emulation mode kPaddlesMode, kKeypadMode, - kCompuMateMode, - kCommonMode + kCompuMateMode, // cannot be remapped + kCommonMode // mapping common between controllers }; - namespace GUI { #ifdef RETRON77 diff --git a/src/gui/DialogContainer.cxx b/src/gui/DialogContainer.cxx index a6056bf32..2a7f8c719 100644 --- a/src/gui/DialogContainer.cxx +++ b/src/gui/DialogContainer.cxx @@ -327,13 +327,11 @@ void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value, int but // Only stop firing events if it's the current stick if(myCurrentAxisDown.stick == stick && value == 0) { - cerr << "handleJoyAxisEvent 0" << endl; myCurrentAxisDown.stick = myCurrentAxisDown.axis = -1; myAxisRepeatTime = 0; } else if(value != 0 && myAxisRepeatTime < myTime) // never repeat the 'off' event; prevent pending repeats after enabling repeat again { - cerr << "handleJoyAxisEvent repeat" << endl; // Now account for repeated axis events (press and hold) myCurrentAxisDown.stick = stick; myCurrentAxisDown.axis = axis; diff --git a/src/gui/EventMappingWidget.cxx b/src/gui/EventMappingWidget.cxx index b1a4085f8..a08c0d455 100644 --- a/src/gui/EventMappingWidget.cxx +++ b/src/gui/EventMappingWidget.cxx @@ -153,7 +153,6 @@ void EventMappingWidget::setDefaults() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventMappingWidget::startRemapping() { - cerr << "startRemapping" << endl; if(myActionSelected < 0 || myRemapStatus) return; @@ -217,7 +216,6 @@ void EventMappingWidget::stopRemapping() { // Turn off remap mode myRemapStatus = false; - cerr << "stopRemapping " << myRemapStatus << endl; // Reset all previous events for determining correct axis/hat values myLastStick = -1; @@ -311,11 +309,9 @@ bool EventMappingWidget::handleKeyUp(StellaKey key, StellaMod mod) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventMappingWidget::handleJoyDown(int stick, int button, bool longPress) { - cerr << "handleJoyDown" << endl; // Remap joystick buttons in remap mode if(myRemapStatus && myActionSelected >= 0) { - cerr << "remap button start " << myRemapStatus << endl; myLastStick = stick; myLastButton = button; } @@ -324,7 +320,6 @@ void EventMappingWidget::handleJoyDown(int stick, int button, bool longPress) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventMappingWidget::handleJoyUp(int stick, int button) { - cerr << "handleJoyUp" << endl; // Remap joystick buttons in remap mode if (myRemapStatus && myActionSelected >= 0) { @@ -333,7 +328,6 @@ void EventMappingWidget::handleJoyUp(int stick, int button) EventHandler& eh = instance().eventHandler(); Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode); - cerr << "remap button stop" << endl; // map either button/hat, solo button or button/axis combinations if(myLastHat != -1) { @@ -350,7 +344,6 @@ void EventMappingWidget::handleJoyUp(int stick, int button) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventMappingWidget::handleJoyAxis(int stick, int axis, int value, int button) { - cerr << "handleJoyAxis:" << axis << ", " << value << ", (" << stick << ", " << myLastStick << "), (" << axis << ", " << myLastAxis << ")" << endl; // Remap joystick axes in remap mode // There are two phases to detection: // First, detect an axis 'on' event @@ -360,7 +353,6 @@ void EventMappingWidget::handleJoyAxis(int stick, int axis, int value, int butto // Detect the first axis event that represents 'on' if((myLastStick == -1 || myLastStick == stick) && myLastAxis == -1 && value != 0) { - cerr << "remap axis start" << endl; myLastStick = stick; myLastAxis = axis; myLastValue = value; @@ -372,7 +364,6 @@ void EventMappingWidget::handleJoyAxis(int stick, int axis, int value, int butto EventHandler& eh = instance().eventHandler(); Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode); - cerr << "remap axis stop" << endl; if (eh.addJoyMapping(event, myEventMode, stick, myLastButton, JoyAxis(axis), myLastValue)) stopRemapping(); }