add configurable driving controller sensitivity

This commit is contained in:
thrust26 2020-04-05 19:55:45 +02:00
parent f0234c105f
commit 0753972d47
7 changed files with 70 additions and 13 deletions

View File

@ -14,7 +14,9 @@
6.1 to 6.2: (??? ??, 2020)
* Added that paddle centering and sensitivity can be adjusted now (TOOD: Doc)
* Added that paddle centering and sensitivity can be adjusted (TOOD: Doc)
* Added that Driving controller sensitivity can be adjusted (TOOD: Doc)
* Added high scores: Score addresses, game variation etc. can be defined for
a game. This allows the user to save high scores for these games. For each

View File

@ -49,10 +49,6 @@ Driving::Driving(Jack jack, const Event& event, const System& system)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Driving::update()
{
// Make sure direct gray codes from Stelladaptor stay in sync with
// simulated gray codes generated by PC keyboard or PC joystick
myCounter = (myGrayIndex << 2) | (myCounter & 3);
// Digital events (from keyboard or joystick hats & buttons)
setPin(DigitalPin::Six, myEvent.get(myFireEvent) == 0);
int d_axis = myEvent.get(myXAxisValue);
@ -92,8 +88,7 @@ void Driving::update()
}
// Only consider the lower-most bits (corresponding to pins 1 & 2)
myCounter &= 0x0f;
myGrayIndex = myCounter >> 2;
myGrayIndex = Int32(myCounter * SENSITIVITY / 4.0F) & 0b11;
// Stelladaptor is the only controller that should set this
int yaxis = myEvent.get(myYAxisValue);
@ -111,6 +106,10 @@ void Driving::update()
myGrayIndex = 2; // up + down
else /* if(yaxis < 16384-4096) */
myGrayIndex = 0; // no movement
// Make sure direct gray codes from Stelladaptor stay in sync with
// simulated gray codes generated by PC keyboard or PC joystick
myCounter = myGrayIndex / SENSITIVITY * 4.0F;
}
// Gray codes for rotation
@ -154,3 +153,13 @@ bool Driving::setMouseControl(
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Driving::setSensitivity(int sensitivity)
{
BSPF::clamp(sensitivity, 1, 20, 10);
SENSITIVITY = sensitivity / 10.0F;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
float Driving::SENSITIVITY = 1.0;

View File

@ -76,9 +76,18 @@ class Driving : public Controller
bool setMouseControl(
Controller::Type xtype, int xid, Controller::Type ytype, int yid) override;
/**
Sets the sensitivity for digital emulation of driving controlle movement
using a keyboard.
@param sensitivity Value from 1 to 20, with larger values causing
more movement (10 represents the baseline)
*/
static void setSensitivity(int sensitivity);
private:
// Counter to iterate through the gray codes
uInt32 myCounter{0};
Int32 myCounter{0};
// Index into the gray code table
uInt32 myGrayIndex{0};
@ -98,6 +107,10 @@ class Driving : public Controller
// Controllers to emulate in 'specific' mouse axis mode
int myControlIDX{-1}, myControlIDY{-1};
// User-defined sensitivity; adjustable since end-users may prefer different
// speeds
static float SENSITIVITY;
private:
// Following constructors and assignment operators not supported
Driving() = delete;

View File

@ -29,6 +29,7 @@
#include "Paddles.hxx"
#include "Lightgun.hxx"
#include "PointingDevice.hxx"
#include "Driving.hxx"
#include "PropsSet.hxx"
#include "Settings.hxx"
#include "Sound.hxx"
@ -97,6 +98,7 @@ void EventHandler::initialize()
Paddles::setDigitalSensitivity(myOSystem.settings().getInt("dsense"));
Paddles::setMouseSensitivity(myOSystem.settings().getInt("msense"));
PointingDevice::setSensitivity(myOSystem.settings().getInt("tsense"));
Driving::setSensitivity(myOSystem.settings().getInt("dcsense"));
#ifdef GUI_SUPPORT
// Set quick select delay when typing characters in listwidgets

View File

@ -106,6 +106,7 @@ Settings::Settings()
setPermanent("psense", "20");
setPermanent("msense", "10");
setPermanent("tsense", "10");
setPermanent("dcsense", "10");
setPermanent("saport", "lr");
setPermanent("modcombo", "true");
@ -339,6 +340,10 @@ void Settings::validate()
if(i < 1 || i > 20)
setValue("tsense", "10");
i = getInt("dcsense");
if(i < 1 || i > 20)
setValue("dcsense", "10");
i = getInt("ssinterval");
if(i < 1) setValue("ssinterval", "2");
else if(i > 10) setValue("ssinterval", "10");
@ -457,6 +462,8 @@ void Settings::usage() const
<< " -dsense <1-20> Sensitivity of digital emulated paddle movement\n"
<< " -msense <1-20> Sensitivity of mouse emulated paddle movement\n"
<< " -tsense <1-20> Sensitivity of mouse emulated trackball movement\n"
<< " -dcsense <1-20> Sensitivity of digital emulated driving controller\n"
<< " movement\n"
<< " -saport <lr|rl> How to assign virtual ports to multiple\n"
<< " Stelladaptor/2600-daptors\n"
<< " -modcombo <1|0> Enable modifer key combos\n"

View File

@ -22,6 +22,7 @@
#include "Joystick.hxx"
#include "Paddles.hxx"
#include "PointingDevice.hxx"
#include "Driving.hxx"
#include "SaveKey.hxx"
#include "AtariVox.hxx"
#include "Settings.hxx"
@ -156,7 +157,7 @@ void InputDialog::addDevicePortTab()
wid.push_back(myDejitterDiff);
// Add paddle speed (digital emulation)
ypos += lineHeight + VGAP * 4;
ypos += lineHeight + VGAP * 3;
myDPaddleSpeed = new SliderWidget(myTab, _font, HBORDER, ypos - 1, 13 * fontWidth, lineHeight,
"Digital paddle sensitivity",
lwidth, kDPSpeedChanged, 4 * fontWidth, "%");
@ -165,7 +166,7 @@ void InputDialog::addDevicePortTab()
wid.push_back(myDPaddleSpeed);
// Add trackball speed
ypos += lineHeight + VGAP * 2;
ypos += lineHeight + VGAP;
myTrackBallSpeed = new SliderWidget(myTab, _font, HBORDER, ypos - 1, 13 * fontWidth, lineHeight,
"Trackball sensitivity",
lwidth, kTBSpeedChanged, 4 * fontWidth, "%");
@ -173,8 +174,17 @@ void InputDialog::addDevicePortTab()
myTrackBallSpeed->setTickmarkIntervals(4);
wid.push_back(myTrackBallSpeed);
// Add driving controller speed
ypos += lineHeight + VGAP;
myDrivingSpeed = new SliderWidget(myTab, _font, HBORDER, ypos - 1, 13 * fontWidth, lineHeight,
"Driving contr. sensitivity",
lwidth, kDCSpeedChanged, 4 * fontWidth, "%");
myDrivingSpeed->setMinValue(1); myDrivingSpeed->setMaxValue(20);
myDrivingSpeed->setTickmarkIntervals(4);
wid.push_back(myDrivingSpeed);
// Add 'allow all 4 directions' for joystick
ypos += lineHeight + VGAP * 4;
ypos += lineHeight + VGAP * 3;
myAllowAll4 = new CheckboxWidget(myTab, _font, HBORDER, ypos,
"Allow all 4 directions on joystick");
wid.push_back(myAllowAll4);
@ -194,7 +204,7 @@ void InputDialog::addDevicePortTab()
int fwidth;
// Add EEPROM erase (part 1/2)
ypos += VGAP*4;
ypos += VGAP * 3;
fwidth = _font.getStringWidth("AtariVox/SaveKey");
lwidth = _font.getStringWidth("AtariVox/SaveKey");
new StaticTextWidget(myTab, _font, _w - HBORDER - 4 - (fwidth + lwidth) / 2, ypos,
@ -203,7 +213,7 @@ void InputDialog::addDevicePortTab()
// Show joystick database
ypos += lineHeight;
myJoyDlgButton = new ButtonWidget(myTab, _font, HBORDER, ypos, 20,
"Joystick Database" + ELLIPSIS, kDBButtonPressed);
"Joystick Database" + ELLIPSIS, kDBButtonPressed);
wid.push_back(myJoyDlgButton);
// Add EEPROM erase (part 1/2)
@ -319,6 +329,8 @@ void InputDialog::loadConfig()
// Trackball speed
myTrackBallSpeed->setValue(instance().settings().getInt("tsense"));
// Driving controller speed
myDrivingSpeed->setValue(instance().settings().getInt("dcsense"));
// AtariVox serial port
myAVoxPort->setText(instance().settings().getString("avoxport"));
@ -389,6 +401,11 @@ void InputDialog::saveConfig()
instance().settings().setValue("tsense", sensitivity);
PointingDevice::setSensitivity(sensitivity);
// Driving controller speed
sensitivity = myDrivingSpeed->getValue();
instance().settings().setValue("dcsense", sensitivity);
Driving::setSensitivity(sensitivity);
// AtariVox serial port
instance().settings().setValue("avoxport", myAVoxPort->getText());
@ -447,6 +464,7 @@ void InputDialog::setDefaults()
myDejitterBase->setValue(0);
myDejitterDiff->setValue(0);
#endif
myDrivingSpeed->setValue(10);
myTrackBallSpeed->setValue(10);
// AtariVox serial port
@ -621,6 +639,10 @@ void InputDialog::handleCommand(CommandSender* sender, int cmd,
myDPaddleSpeed->setValueLabel(myDPaddleSpeed->getValue() * 10);
break;
case kDCSpeedChanged:
myDrivingSpeed->setValueLabel(myDrivingSpeed->getValue() * 10);
break;
case kTBSpeedChanged:
myTrackBallSpeed->setValueLabel(myTrackBallSpeed->getValue() * 10);
break;

View File

@ -77,6 +77,7 @@ class InputDialog : public Dialog
kDejitterReChanged = 'JRch',
kDPSpeedChanged = 'PDch',
kTBSpeedChanged = 'TBch',
kDCSpeedChanged = 'DCch',
kDBButtonPressed = 'DBbp',
kEEButtonPressed = 'EEbp',
kConfirmEEEraseCmd = 'EEcf',
@ -103,6 +104,7 @@ class InputDialog : public Dialog
SliderWidget* myDPaddleSpeed{nullptr};
SliderWidget* myMPaddleSpeed{nullptr};
SliderWidget* myTrackBallSpeed{nullptr};
SliderWidget* myDrivingSpeed{nullptr};
CheckboxWidget* myAllowAll4{nullptr};
CheckboxWidget* myGrabMouse{nullptr};
CheckboxWidget* myModCombo{nullptr};