From bba449b830b92a92893c1190f36e7a54d75c1a15 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Thu, 9 Sep 2021 18:11:38 +0200 Subject: [PATCH] added preliminary dead zone code for analog events changed some wording --- src/common/PJoystickHandler.cxx | 57 +++++++++++++++++++++------------ src/common/PJoystickHandler.hxx | 4 +-- src/emucore/Control.cxx | 14 ++++---- src/emucore/Control.hxx | 22 ++++++------- src/emucore/EventHandler.cxx | 22 ++++++------- src/gui/InputDialog.cxx | 15 +++++---- 6 files changed, 75 insertions(+), 59 deletions(-) diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 0909ad646..d5d2ff3c6 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -789,7 +789,22 @@ void PhysicalJoystickHandler::handleRegularAxisEvent(const PhysicalJoystickPtr j if((abs(j->axisLastValue[axis] - value) < 30000) && (eventAxisAnalog = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::ANALOG)) != Event::Type::NoType) { - myHandler.handleEvent(eventAxisAnalog, value); + // TODO: TEST!!! + if(abs(value) > Controller::analogDeadZone()) + myHandler.handleEvent(eventAxisAnalog, value); + else + { + // Treat any dead zone value as zero + value = 0; + + // Now filter out consecutive, similar values + // (only pass on the event if the state has changed) + if(j->axisLastValue[axis] != value) + { + // Turn off events + myHandler.handleEvent(eventAxisAnalog, 0); + } + } } else { @@ -798,13 +813,13 @@ void PhysicalJoystickHandler::handleRegularAxisEvent(const PhysicalJoystickPtr j Event::Type eventAxisNeg = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::NEG); Event::Type eventAxisPos = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::POS); - if(value > Controller::digitalDeadzone()) + if(value > Controller::digitalDeadZone()) myHandler.handleEvent(eventAxisPos); - else if(value < -Controller::digitalDeadzone()) + else if(value < -Controller::digitalDeadZone()) myHandler.handleEvent(eventAxisNeg); else { - // Treat any deadzone value as zero + // Treat any dead zone value as zero value = 0; // Now filter out consecutive, similar values @@ -813,8 +828,8 @@ void PhysicalJoystickHandler::handleRegularAxisEvent(const PhysicalJoystickPtr j { // Turn off both events, since we don't know exactly which one // was previously activated. - myHandler.handleEvent(eventAxisNeg, false); - myHandler.handleEvent(eventAxisPos, false); + myHandler.handleEvent(eventAxisNeg, 0); + myHandler.handleEvent(eventAxisPos, 0); } } } @@ -824,13 +839,13 @@ void PhysicalJoystickHandler::handleRegularAxisEvent(const PhysicalJoystickPtr j else if(myHandler.hasOverlay()) { // A value change lower than Controller::digitalDeadzone indicates analog input which is ignored - if((abs(j->axisLastValue[axis] - value) > Controller::digitalDeadzone())) + if((abs(j->axisLastValue[axis] - value) > Controller::digitalDeadZone())) { // First, clamp the values to simulate digital input // (the only thing that the underlying code understands) - if(value > Controller::digitalDeadzone()) + if(value > Controller::digitalDeadZone()) value = 32000; - else if(value < -Controller::digitalDeadzone()) + else if(value < -Controller::digitalDeadZone()) value = -32000; else value = 0; @@ -945,33 +960,33 @@ ostream& operator<<(ostream& os, const PhysicalJoystickHandler& jh) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PhysicalJoystickHandler::changeDigitalDeadzone(int direction) +void PhysicalJoystickHandler::changeDigitalDeadZone(int direction) { - int deadzone = BSPF::clamp(myOSystem.settings().getInt("joydeadzone") + direction, + int deadZone = BSPF::clamp(myOSystem.settings().getInt("joydeadzone") + direction, Controller::MIN_DIGITAL_DEADZONE, Controller::MAX_DIGITAL_DEADZONE); - myOSystem.settings().setValue("joydeadzone", deadzone); + myOSystem.settings().setValue("joydeadzone", deadZone); - Controller::setDigitalDeadZone(deadzone); + Controller::setDigitalDeadZone(deadZone); ostringstream ss; - ss << std::round(Controller::digitalDeadzoneValue(deadzone) * 100.F / 32768) << "%"; + ss << std::round(Controller::digitalDeadZoneValue(deadZone) * 100.F / 32768) << "%"; - myOSystem.frameBuffer().showGaugeMessage("Digital controller dead zone", ss. str(), deadzone, + myOSystem.frameBuffer().showGaugeMessage("Digital controller dead zone", ss. str(), deadZone, Controller::MIN_DIGITAL_DEADZONE, Controller::MAX_DIGITAL_DEADZONE); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PhysicalJoystickHandler::changeAnalogPaddleDeadzone(int direction) +void PhysicalJoystickHandler::changeAnalogPaddleDeadZone(int direction) { - int deadzone = BSPF::clamp(myOSystem.settings().getInt("adeadzone") + direction * 500, + int deadZone = BSPF::clamp(myOSystem.settings().getInt("adeadzone") + direction * 500, Controller::MIN_ANALOG_DEADZONE, Controller::MAX_ANALOG_DEADZONE); - myOSystem.settings().setValue("adeadzone", deadzone); + myOSystem.settings().setValue("adeadzone", deadZone); - Controller::setAnalogDeadzone(deadzone); + Controller::setAnalogDeadZone(deadZone); ostringstream ss; - ss << std::round(deadzone * 100.F / 32768) << "%"; + ss << std::round(deadZone * 100.F / 32768) << "%"; - myOSystem.frameBuffer().showGaugeMessage("Analog controller dead zone", ss.str(), deadzone, + myOSystem.frameBuffer().showGaugeMessage("Analog controller dead zone", ss.str(), deadZone, Controller::MIN_ANALOG_DEADZONE, Controller::MAX_ANALOG_DEADZONE); } diff --git a/src/common/PJoystickHandler.hxx b/src/common/PJoystickHandler.hxx index 3b99a88de..522dfbd26 100644 --- a/src/common/PJoystickHandler.hxx +++ b/src/common/PJoystickHandler.hxx @@ -110,8 +110,8 @@ class PhysicalJoystickHandler /** Returns a list of pairs consisting of joystick name and associated ID. */ VariantList database() const; - void changeDigitalDeadzone(int direction = +1); - void changeAnalogPaddleDeadzone(int direction = +1); + void changeDigitalDeadZone(int direction = +1); + void changeAnalogPaddleDeadZone(int direction = +1); void changeAnalogPaddleSensitivity(int direction = +1); void changeAnalogPaddleAcceleration(int direction = +1); void changePaddleDejitterAveraging(int direction = +1); diff --git a/src/emucore/Control.cxx b/src/emucore/Control.cxx index 39f310ccb..b83616de7 100644 --- a/src/emucore/Control.cxx +++ b/src/emucore/Control.cxx @@ -149,23 +149,23 @@ Controller::Type Controller::getType(const string& propName) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Controller::setDigitalDeadZone(int deadzone) +void Controller::setDigitalDeadZone(int deadZone) { - DIGITAL_DEAD_ZONE = digitalDeadzoneValue(deadzone); + DIGITAL_DEAD_ZONE = digitalDeadZoneValue(deadZone); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int Controller::digitalDeadzoneValue(int deadzone) +int Controller::digitalDeadZoneValue(int deadZone) { - deadzone = BSPF::clamp(deadzone, MIN_DIGITAL_DEADZONE, MAX_DIGITAL_DEADZONE); + deadZone = BSPF::clamp(deadZone, MIN_DIGITAL_DEADZONE, MAX_DIGITAL_DEADZONE); - return 3200 + deadzone * 1000; + return 3200 + deadZone * 1000; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Controller::setAnalogDeadzone(int deadzone) +void Controller::setAnalogDeadZone(int deadZone) { - ANALOG_DEAD_ZONE = BSPF::clamp(deadzone, MIN_ANALOG_DEADZONE, MAX_ANALOG_DEADZONE); + ANALOG_DEAD_ZONE = BSPF::clamp(deadZone, MIN_ANALOG_DEADZONE, MAX_ANALOG_DEADZONE); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Control.hxx b/src/emucore/Control.hxx index 32e60824a..8e90706d0 100644 --- a/src/emucore/Control.hxx +++ b/src/emucore/Control.hxx @@ -281,27 +281,27 @@ class Controller : public Serializable static Type getType(const string& propName); /** - Sets the deadzone amount for real analog joysticks. - Technically, this isn't really used by the Joystick class at all, - but it seemed like the best place to put it. + Sets the dead zone amount for real analog joysticks. + + @param deadZone Value from 0 to 29 */ - static void setDigitalDeadZone(int deadzone); + static void setDigitalDeadZone(int deadZone); /** - Sets the deadzone for analog paddles. + Sets the dead zone for analog paddles. - @param deadzone Value from 0 to 16500 + @param deadZone Value from 0 to 16500 */ - static void setAnalogDeadzone(int deadzone); + static void setAnalogDeadZone(int deadZone); /** - Retrieves the effective digital deadzone value + Retrieves the effective digital dead zone value */ - static int digitalDeadzoneValue(int deadzone); + static int digitalDeadZoneValue(int deadZone); - inline static int digitalDeadzone() { return DIGITAL_DEAD_ZONE; } + inline static int digitalDeadZone() { return DIGITAL_DEAD_ZONE; } - inline static int analogDeadzone() { return ANALOG_DEAD_ZONE; } + inline static int analogDeadZone() { return ANALOG_DEAD_ZONE; } /** Sets the sensitivity for analog emulation movement diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 31c08f892..24e1e3dc7 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -100,7 +100,7 @@ void EventHandler::initialize() setActionMappings(EventMode::kMenuMode); Controller::setDigitalDeadZone(myOSystem.settings().getInt("joydeadzone")); - Controller::setAnalogDeadzone(myOSystem.settings().getInt("adeadzone")); + Controller::setAnalogDeadZone(myOSystem.settings().getInt("adeadzone")); Paddles::setAnalogAccel(myOSystem.settings().getInt("paccel")); Paddles::setDejitterDiff(myOSystem.settings().getInt("dejitter.diff")); Paddles::setDejitterBase(myOSystem.settings().getInt("dejitter.base")); @@ -596,8 +596,8 @@ AdjustFunction EventHandler::getAdjustSetting(AdjustSetting setting) std::bind(&Console::toggleInter, &myOSystem.console(), _1), // *** Input settings *** - std::bind(&PhysicalJoystickHandler::changeDigitalDeadzone, &joyHandler(), _1), - std::bind(&PhysicalJoystickHandler::changeAnalogPaddleDeadzone, &joyHandler(), _1), + std::bind(&PhysicalJoystickHandler::changeDigitalDeadZone, &joyHandler(), _1), + std::bind(&PhysicalJoystickHandler::changeAnalogPaddleDeadZone, &joyHandler(), _1), std::bind(&PhysicalJoystickHandler::changeAnalogPaddleSensitivity, &joyHandler(), _1), std::bind(&PhysicalJoystickHandler::changeAnalogPaddleAcceleration, &joyHandler(), _1), std::bind(&PhysicalJoystickHandler::changePaddleDejitterAveraging, &joyHandler(), _1), @@ -1364,7 +1364,7 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated) case Event::DecreaseDeadzone: if(pressed) { - myPJoyHandler->changeDigitalDeadzone(-1); + myPJoyHandler->changeDigitalDeadZone(-1); myAdjustSetting = AdjustSetting::DEADZONE; myAdjustActive = true; } @@ -1373,7 +1373,7 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated) case Event::IncreaseDeadzone: if(pressed) { - myPJoyHandler->changeDigitalDeadzone(+1); + myPJoyHandler->changeDigitalDeadZone(+1); myAdjustSetting = AdjustSetting::DEADZONE; myAdjustActive = true; } @@ -1382,7 +1382,7 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated) case Event::DecAnalogDeadzone: if(pressed) { - myPJoyHandler->changeAnalogPaddleDeadzone(-1); + myPJoyHandler->changeAnalogPaddleDeadZone(-1); myAdjustSetting = AdjustSetting::ANALOG_DEADZONE; myAdjustActive = true; } @@ -1391,7 +1391,7 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated) case Event::IncAnalogDeadzone: if(pressed) { - myPJoyHandler->changeAnalogPaddleDeadzone(+1); + myPJoyHandler->changeAnalogPaddleDeadZone(+1); myAdjustSetting = AdjustSetting::ANALOG_DEADZONE; myAdjustActive = true; } @@ -3322,10 +3322,10 @@ EventHandler::EmulActionList EventHandler::ourEmulActionList = { { { Event::VolumeDecrease, "Decrease volume", "" }, { Event::VolumeIncrease, "Increase volume", "" }, - { Event::DecreaseDeadzone, "Decrease joystick deadzone", "" }, - { Event::IncreaseDeadzone, "Increase joystick deadzone", "" }, - { Event::DecAnalogDeadzone, "Decrease analog paddle deadzone", "" }, - { Event::IncAnalogDeadzone, "Increase analog paddle deadzone", "" }, + { Event::DecreaseDeadzone, "Decrease digital dead zone", "" }, + { Event::IncreaseDeadzone, "Increase digital dead zone", "" }, + { Event::DecAnalogDeadzone, "Decrease analog dead zone", "" }, + { Event::IncAnalogDeadzone, "Increase analog dead zone", "" }, { Event::DecAnalogSense, "Decrease analog paddle sensitivity", "" }, { Event::IncAnalogSense, "Increase analog paddle sensitivity", "" }, { Event::DecAnalogAccel, "Decrease analog paddle acceleration", "" }, diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index 6ab997a36..76d2bbac2 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -160,6 +160,7 @@ void InputDialog::addDevicePortTab() myPaddleAccel->setMaxValue(Paddles::MAX_ANALOG_ACCEL); myPaddleAccel->setStepValue(5); myPaddleAccel->setTickmarkIntervals(4); + myPaddleAccel->setToolTip("Adjust fast paddle movement acceleration."); wid.push_back(myPaddleAccel); // Add dejitter (analog paddles) @@ -434,13 +435,13 @@ void InputDialog::saveConfig() // *** Device & Ports *** // Digital dead zone - int deadzone = myDigitalDeadzone->getValue(); - settings.setValue("joydeadzone", deadzone); - Controller::setDigitalDeadZone(deadzone); + int deadZone = myDigitalDeadzone->getValue(); + settings.setValue("joydeadzone", deadZone); + Controller::setDigitalDeadZone(deadZone); // Analog dead zone - deadzone = myAnalogDeadzone->getValue(); - settings.setValue("adeadzone", deadzone); - Controller::setAnalogDeadzone(deadzone); + deadZone = myAnalogDeadzone->getValue(); + settings.setValue("adeadzone", deadZone); + Controller::setAnalogDeadZone(deadZone); // Paddle speed (analog) int sensitivity = myPaddleSpeed->getValue(); @@ -699,7 +700,7 @@ void InputDialog::handleCommand(CommandSender* sender, int cmd, break; case kDDeadzoneChanged: - myDigitalDeadzone->setValueLabel(std::round(Controller::digitalDeadzoneValue(myDigitalDeadzone->getValue()) * 100.f / 32768)); + myDigitalDeadzone->setValueLabel(std::round(Controller::digitalDeadZoneValue(myDigitalDeadzone->getValue()) * 100.f / 32768)); break; case kADeadzoneChanged: