added new paddle options (TODO: deadzone and testing with real controllers, remove test code)

This commit is contained in:
Thomas Jentzsch 2021-09-07 11:39:33 +02:00
parent d809a4983d
commit 0f39ddd85e
13 changed files with 307 additions and 76 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -1584,6 +1584,17 @@
<td>Control + F1</td>
</tr>
<tr>
<td><i>Decrease</i> analog paddle deadzone</td>
<td>Shift-Control-Alt + F1</td>
<td>Shift-Control-Cmd + F1</td>
</tr>
<tr>
<td><i>Increase</i> analog paddle deadzone</td>
<td>Control-Alt + F1</td>
<td>Control-Cmd + F1</td>
</tr>
<tr>
<td><i>Decrease</i> analog paddle sensitivity</td>
<td>Shift-Control + F2</td>
@ -1595,6 +1606,17 @@
<td>Control + F2</td>
</tr>
<tr>
<td><i>Decrease</i> analog paddle acceleration</td>
<td>Shift-Control-Alt + F2</td>
<td>Shift-Control-Cmd + F2</td>
</tr>
<tr>
<td><i>Increase</i> analog paddle acceleration</td>
<td>Control-Alt + F2</td>
<td>Control-Cmd + F2</td>
</tr>
<tr>
<td><i>Decrease</i> analog paddle dejitter averaging</td>
<td>Shift-Control + F3</td>
@ -1933,8 +1955,9 @@
</table>
<p><b><a name="GlobalKeys">Global Keys</a> (can be remapped)</b></p>
<p>These keys allow selecting and changing settings without having to remember the
dedicated keys. They keys are grouped by 'Audio & Video', 'Input Device & Ports' and 'Debug' settings.</p>
<p>These keys allow selecting and changing settings without having to remember
the dedicated hotkeys. The global keys are grouped by 'Audio & Video',
'Input Devices & Ports' and 'Debug' settings.</p>
<table BORDER=2 cellpadding=4>
<tr>
<th>Function</th>
@ -1976,8 +1999,8 @@
<ul>
<li>Only available if UI messages are enabled.</li>
<li>Currently not available settings are automatically skipped.</li>
<li>If a setting was previously selected via a dedicated key, its value can also be changed with the
global keys.</li>
<li>If a setting was previously selected via a dedicated hotkey, its
value can also be directly changed with the global keys.</li>
</ul>
</p>
@ -2947,6 +2970,13 @@
range from 3200 to 32200.</td>
</tr>
<tr>
<td><pre>-pdeadzone &lt;0 - 15000&gt;</pre></td>
<td>Set the deadzone area for analog paddles. All values within the
deadzone are treated as zero-axis values, while only those values
outside are registered as valid input.</td>
</tr>
<tr>
<td><pre>-psense &lt;number&gt;</pre></td>
<td>Sensitivity for emulation of paddles when using analog paddles.
@ -2954,14 +2984,19 @@
faster movement.</td>
</tr>
<tr>
<td><pre>-paccel &lt;0 - 100&gt;</pre></td>
<td>Acceleration of analog paddles when moving them fast.</td>
</tr>
<tr>
<td><pre>-dejitter.base &lt;0 - 10&gt;</pre></td>
<td>Strength of paddle input averaging.</td>
<td>Strength of analog paddle input averaging.</td>
</tr>
<tr>
<td><pre>-dejitter.diff &lt;0 - 10&gt;</pre></td>
<td>Impact of fast paddle movement on input averaging.</td>
<td>Impact of fast analog paddle movement on input averaging.</td>
</tr>
<tr>
@ -2990,7 +3025,7 @@
when you want to disable them.</br>
E.g. a 2-player game is using either the 'F' or 'R' keys for movement,
and pressing Control (for Fire) will perform an unwanted action
associated with 'Control + R' or 'Control + F' default keys.</td>
associated with 'Control + F' or 'Control + R' default keys.</td>
</tr>
<tr>
@ -3989,7 +4024,9 @@
<table border="1" cellpadding="4">
<tr><th>Item</th><th>Brief description</th><th>For more information,<br>see <a href="#CommandLine">Command Line</a></th></tr>
<tr><td>Joystick deadzone size</td><td>Deadzone area for axes on joysticks/gamepads</td><td>-joydeadzone</td></tr>
<tr><td>(Analog paddle) Deadzone size</td><td>Deadzone area for analog paddles</td><td>-pdeadzone</td></tr>
<tr><td>(Analog paddle) Sensitivity</td><td>Sensitivity of an analog paddle</td><td>-psense</td></tr>
<tr><td>(Analog paddle) Acceleration</td><td>Acceleration of analog paddles when moving them fast</td><td>-paccel</td></tr>
<tr><td>(Analog paddle) Dejitter averaging</td><td>Strength of paddle input averaging, suppresses paddle jitter.<br>
Note: The 2600-daptor has built-in dejitter, so there should be no need to use Stella's dejitter.
</td><td>-dejitter.base</td></tr>

View File

@ -664,7 +664,6 @@ bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, i
{
EventMode evMode = getEventMode(event, mode);
// This confusing code is because each axis has two associated values,
// but analog events only affect one of the axis.
if (Event::isAnalog(event))
@ -956,7 +955,20 @@ void PhysicalJoystickHandler::changeDeadzone(int direction)
int value = Joystick::deadZoneValue(deadzone);
myOSystem.frameBuffer().showGaugeMessage("Joystick deadzone", std::to_string(value),
value, 3200, 32200);
deadzone, Joystick::DEAD_ZONE_MIN, Joystick::DEAD_ZONE_MAX);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalJoystickHandler::changeAnalogPaddleDeadzone(int direction)
{
int deadzone = BSPF::clamp(myOSystem.settings().getInt("pdeadzone") + direction * 500,
Paddles::MIN_ANALOG_DEADZONE, Paddles::MAX_ANALOG_DEADZONE);
myOSystem.settings().setValue("pdeadzone", deadzone);
Paddles::setAnalogDeadzone(deadzone);
myOSystem.frameBuffer().showGaugeMessage("Analog paddle deadzone", std::to_string(deadzone), deadzone,
Paddles::MIN_ANALOG_DEADZONE, Paddles::MAX_ANALOG_DEADZONE);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -970,10 +982,30 @@ void PhysicalJoystickHandler::changeAnalogPaddleSensitivity(int direction)
ostringstream ss;
ss << std::round(Paddles::analogSensitivityValue(sense) * 100.F) << "%";
myOSystem.frameBuffer().showGaugeMessage("Analog paddle sensitivity", ss.str(), sense,
Paddles::MIN_ANALOG_SENSE, Paddles::MAX_ANALOG_SENSE);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalJoystickHandler::changeAnalogPaddleAcceleration(int direction)
{
int accel = BSPF::clamp(myOSystem.settings().getInt("paccel") + direction * 5,
Paddles::MIN_ANALOG_ACCEL, Paddles::MAX_ANALOG_ACCEL);
myOSystem.settings().setValue("paccel", accel);
Paddles::setAnalogAccel(accel);
ostringstream ss;
if(accel)
ss << accel << "%";
else
ss << "Off";
myOSystem.frameBuffer().showGaugeMessage("Analog paddle acceleration", ss.str(), accel,
Paddles::MIN_ANALOG_ACCEL, Paddles::MAX_ANALOG_ACCEL);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalJoystickHandler::changePaddleDejitterAveraging(int direction)
{

View File

@ -111,7 +111,9 @@ class PhysicalJoystickHandler
VariantList database() const;
void changeDeadzone(int direction = +1);
void changeAnalogPaddleDeadzone(int direction = +1);
void changeAnalogPaddleSensitivity(int direction = +1);
void changeAnalogPaddleAcceleration(int direction = +1);
void changePaddleDejitterAveraging(int direction = +1);
void changePaddleDejitterReaction(int direction = +1);
void changeDigitalPaddleSensitivity(int direction = +1);

View File

@ -689,8 +689,12 @@ PhysicalKeyboardHandler::DefaultCommonMapping = {
{ Event::DecreaseDeadzone, KBDK_F1, KBDM_CTRL | KBDM_SHIFT },
{ Event::IncreaseDeadzone, KBDK_F1, KBDM_CTRL },
{ Event::DecAnalogDeadzone, KBDK_F1, KBDM_CTRL | MOD3 | KBDM_SHIFT},
{ Event::IncAnalogDeadzone, KBDK_F1, KBDM_CTRL | MOD3},
{ Event::DecAnalogSense, KBDK_F2, KBDM_CTRL | KBDM_SHIFT },
{ Event::IncAnalogSense, KBDK_F2, KBDM_CTRL },
{ Event::DecAnalogAccel, KBDK_F2, KBDM_CTRL | MOD3 | KBDM_SHIFT},
{ Event::IncAnalogAccel, KBDK_F2, KBDM_CTRL | MOD3},
{ Event::DecDejtterAveraging, KBDK_F3, KBDM_CTRL | KBDM_SHIFT },
{ Event::IncDejtterAveraging, KBDK_F3, KBDM_CTRL },
{ Event::DecDejtterReaction, KBDK_F4, KBDM_CTRL | KBDM_SHIFT },

View File

@ -195,8 +195,12 @@ NLOHMANN_JSON_SERIALIZE_ENUM(Event::Type, {
{Event::DecreaseDeadzone, "DecreaseDeadzone"},
{Event::IncreaseDeadzone, "IncreaseDeadzone"},
{Event::DecAnalogDeadzone, "DecAnalogDeadzone"},
{Event::IncAnalogDeadzone, "IncAnalogDeadzone"},
{Event::DecAnalogSense, "DecAnalogSense"},
{Event::IncAnalogSense, "IncAnalogSense"},
{Event::DecAnalogAccel, "DecAnalogAccel"},
{Event::IncAnalogAccel, "IncAnalogAccel"},
{Event::DecDejtterAveraging, "DecDejtterAveraging"},
{Event::IncDejtterAveraging, "IncDejtterAveraging"},
{Event::DecDejtterReaction, "DecDejtterReaction"},

View File

@ -147,7 +147,9 @@ class Event
HighScoresMenuMode,
// Input settings
DecreaseDeadzone, IncreaseDeadzone,
DecAnalogDeadzone, IncAnalogDeadzone,
DecAnalogSense, IncAnalogSense,
DecAnalogAccel, IncAnalogAccel,
DecDejtterAveraging, IncDejtterAveraging,
DecDejtterReaction, IncDejtterReaction,
DecDigitalSense, IncDigitalSense,

View File

@ -99,6 +99,9 @@ void EventHandler::initialize()
setActionMappings(EventMode::kMenuMode);
Joystick::setDeadZone(myOSystem.settings().getInt("joydeadzone"));
Paddles::setAnalogDeadzone(myOSystem.settings().getInt("pdeadzone"));
Paddles::setAnalogAccel(myOSystem.settings().getInt("paccel"));
Paddles::setDejitterDiff(myOSystem.settings().getInt("dejitter.diff"));
Paddles::setDejitterBase(myOSystem.settings().getInt("dejitter.base"));
Paddles::setDejitterDiff(myOSystem.settings().getInt("dejitter.diff"));
Paddles::setDigitalSensitivity(myOSystem.settings().getInt("dsense"));
@ -455,7 +458,9 @@ bool EventHandler::skipInputSetting() const
&& (myAdjustSetting == AdjustSetting::DEADZONE
|| myAdjustSetting == AdjustSetting::FOUR_DIRECTIONS))
|| (!paddle
&& (myAdjustSetting == AdjustSetting::ANALOG_SENSITIVITY
&& (myAdjustSetting == AdjustSetting::ANALOG_DEADZONE
|| myAdjustSetting == AdjustSetting::ANALOG_SENSITIVITY
|| myAdjustSetting == AdjustSetting::ANALOG_ACCEL
|| myAdjustSetting == AdjustSetting::DEJITTER_AVERAGING
|| myAdjustSetting == AdjustSetting::DEJITTER_REACTION
|| myAdjustSetting == AdjustSetting::DIGITAL_SENSITIVITY
@ -591,7 +596,9 @@ AdjustFunction EventHandler::getAdjustSetting(AdjustSetting setting)
// *** Input settings ***
std::bind(&PhysicalJoystickHandler::changeDeadzone, &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),
std::bind(&PhysicalJoystickHandler::changePaddleDejitterReaction, &joyHandler(), _1),
std::bind(&PhysicalJoystickHandler::changeDigitalPaddleSensitivity, &joyHandler(), _1),
@ -1371,11 +1378,29 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated)
}
return;
case Event::DecAnalogDeadzone:
if(pressed)
{
myPJoyHandler->changeAnalogPaddleDeadzone(-1);
myAdjustSetting = AdjustSetting::ANALOG_DEADZONE;
myAdjustActive = true;
}
return;
case Event::IncAnalogDeadzone:
if(pressed)
{
myPJoyHandler->changeAnalogPaddleDeadzone(+1);
myAdjustSetting = AdjustSetting::ANALOG_DEADZONE;
myAdjustActive = true;
}
return;
case Event::DecAnalogSense:
if(pressed)
{
myPJoyHandler->changeAnalogPaddleSensitivity(-1);
myAdjustSetting = AdjustSetting::PADDLE_SENSITIVITY;
myAdjustSetting = AdjustSetting::ANALOG_SENSITIVITY;
myAdjustActive = true;
}
return;
@ -1384,10 +1409,27 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated)
if(pressed)
{
myPJoyHandler->changeAnalogPaddleSensitivity(+1);
myAdjustSetting = AdjustSetting::PADDLE_SENSITIVITY;
myAdjustSetting = AdjustSetting::ANALOG_SENSITIVITY;
myAdjustActive = true;
}
return;
case Event::DecAnalogAccel:
if(pressed)
{
myPJoyHandler->changeAnalogPaddleAcceleration(-1);
myAdjustSetting = AdjustSetting::ANALOG_ACCEL;
myAdjustActive = true;
}
return;
case Event::IncAnalogAccel:
if(pressed)
{
myPJoyHandler->changeAnalogPaddleAcceleration(+1);
myAdjustSetting = AdjustSetting::ANALOG_ACCEL;
myAdjustActive = true;
}
return;
case Event::DecDejtterAveraging:
@ -3279,11 +3321,14 @@ 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::DecAnalogSense, "Decrease analog paddle sensitivity", "" },
{ Event::IncAnalogSense, "Increase analog paddle sensitivity", "" },
{ Event::DecAnalogAccel, "Decrease analog paddle acceleration", "" },
{ Event::IncAnalogAccel, "Increase analog paddle acceleration", "" },
{ Event::DecDejtterAveraging, "Decrease paddle dejitter averaging", "" },
{ Event::IncDejtterAveraging, "Increase paddle dejitter averaging", "" },
{ Event::DecDejtterReaction, "Decrease paddle dejitter reaction", "" },
@ -3467,7 +3512,9 @@ const Event::EventSet EventHandler::KeyboardEvents = {
const Event::EventSet EventHandler::DevicesEvents = {
Event::DecreaseDeadzone, Event::IncreaseDeadzone,
Event::DecAnalogDeadzone, Event::IncAnalogDeadzone,
Event::DecAnalogSense, Event::IncAnalogSense,
Event::DecAnalogAccel, Event::IncAnalogAccel,
Event::DecDejtterAveraging, Event::IncDejtterAveraging,
Event::DecDejtterReaction, Event::IncDejtterReaction,
Event::DecDigitalSense, Event::IncDigitalSense,

View File

@ -473,7 +473,9 @@ class EventHandler
INTERPOLATION,
// *** Input group ***
DEADZONE,
ANALOG_DEADZONE,
ANALOG_SENSITIVITY,
ANALOG_ACCEL,
DEJITTER_AVERAGING,
DEJITTER_REACTION,
DIGITAL_SENSITIVITY,
@ -645,7 +647,7 @@ class EventHandler
#else
REFRESH_SIZE = 0,
#endif
EMUL_ACTIONLIST_SIZE = 212 + PNG_SIZE + COMBO_SIZE + REFRESH_SIZE,
EMUL_ACTIONLIST_SIZE = 216 + PNG_SIZE + COMBO_SIZE + REFRESH_SIZE,
MENU_ACTIONLIST_SIZE = 19
;

View File

@ -510,7 +510,7 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum,
}
// Check for first PlusROM start
if(myConsole->cartridge().isPlusROM() &&
settings().getString("plusroms.nick") == EmptyString)
settings().getString("plusroms.id") == EmptyString)
{
myEventHandler->changeStateByEvent(Event::PlusRomsSetupMode);
}

View File

@ -195,6 +195,45 @@ void Paddles::update()
setPin(DigitalPin::Three, !getAutoFireStateP1(firePressedB));
}
AnalogReadout::Connection Paddles::getReadOut(int lastAxis, int& newAxis, int center)
{
static constexpr std::array<double, MAX_DEJITTER - MIN_DEJITTER + 1> bFac = {
// higher values mean more dejitter strength
0, // off
0.50, 0.59, 0.67, 0.74, 0.80,
0.85, 0.89, 0.92, 0.94, 0.95
};
static constexpr std::array<double, MAX_DEJITTER - MIN_DEJITTER + 1> dFac = {
// lower values mean more dejitter strength
1, // off
1.0 / 181, 1.0 / 256, 1.0 / 362, 1.0 / 512, 1.0 / 724,
1.0 / 1024, 1.0 / 1448, 1.0 / 2048, 1.0 / 2896, 1.0 / 4096
};
const double baseFactor = bFac[DEJITTER_BASE];
const double diffFactor = dFac[DEJITTER_DIFF];
// dejitter, suppress small changes only
double dejitter = pow(baseFactor, abs(newAxis - lastAxis) * diffFactor);
int newVal = newAxis * (1 - dejitter) + lastAxis * dejitter;
// only use new dejittered value for larger differences
if(abs(newVal - newAxis) > 10)
newAxis = newVal;
// TODO: deadzone
// here or in PJoystickhandler?
// accelerate, reduces sensitivity accordingly
int diff = newAxis - lastAxis;
float factor = diff ? pow(abs(diff), ACCEL) / abs(diff) : 0;
newAxis = lastAxis - diff * factor * pow(MOUSE_SENSITIVITY, 1.f/ACCEL); // TODO: predefine pow(...)
// scale result
return AnalogReadout::connectToVcc(MAX_RESISTANCE *
(BSPF::clamp(32768 - Int32(Int32(newAxis) * SENSITIVITY + center), 0, 65536) / 65536.0));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Paddles::updateAnalogAxes()
{
@ -206,20 +245,20 @@ bool Paddles::updateAnalogAxes()
// previous values by a pre-defined amount)
// Otherwise, it would always override input from digital and mouse
static constexpr std::array<double, MAX_DEJITTER - MIN_DEJITTER + 1> bFac = {
// higher values mean more dejitter strength
0, // off
0.50, 0.59, 0.67, 0.74, 0.80,
0.85, 0.89, 0.92, 0.94, 0.95
};
static constexpr std::array<double, MAX_DEJITTER - MIN_DEJITTER + 1> dFac = {
// lower values mean more dejitter strength
1, // off
1.0 / 181, 1.0 / 256, 1.0 / 362, 1.0 / 512, 1.0 / 724,
1.0 / 1024, 1.0 / 1448, 1.0 / 2048, 1.0 / 2896, 1.0 / 4096
};
const double baseFactor = bFac[DEJITTER_BASE];
const double diffFactor = dFac[DEJITTER_DIFF];
//static constexpr std::array<double, MAX_DEJITTER - MIN_DEJITTER + 1> bFac = {
// // higher values mean more dejitter strength
// 0, // off
// 0.50, 0.59, 0.67, 0.74, 0.80,
// 0.85, 0.89, 0.92, 0.94, 0.95
//};
//static constexpr std::array<double, MAX_DEJITTER - MIN_DEJITTER + 1> dFac = {
// // lower values mean more dejitter strength
// 1, // off
// 1.0 / 181, 1.0 / 256, 1.0 / 362, 1.0 / 512, 1.0 / 724,
// 1.0 / 1024, 1.0 / 1448, 1.0 / 2048, 1.0 / 2896, 1.0 / 4096
//};
//const double baseFactor = bFac[DEJITTER_BASE];
//const double diffFactor = dFac[DEJITTER_DIFF];
int sa_xaxis = myEvent.get(myAAxisValue);
int sa_yaxis = myEvent.get(myBAxisValue);
@ -227,31 +266,34 @@ bool Paddles::updateAnalogAxes()
if(abs(myLastAxisX - sa_xaxis) > 10)
{
// dejitter, suppress small changes only
double dejitter = std::pow(baseFactor, abs(sa_xaxis - myLastAxisX) * diffFactor);
int new_val = sa_xaxis * (1 - dejitter) + myLastAxisX * dejitter;
// only use new dejittered value for larger differences
if(abs(new_val - sa_xaxis) > 10)
sa_xaxis = new_val;
//// dejitter, suppress small changes only
//double dejitter = pow(baseFactor, abs(sa_xaxis - myLastAxisX) * diffFactor);
//int new_val = sa_xaxis * (1 - dejitter) + myLastAxisX * dejitter;
setPin(AnalogPin::Nine, AnalogReadout::connectToVcc(MAX_RESISTANCE *
(BSPF::clamp(32768 - Int32(Int32(sa_xaxis) * SENSITIVITY + XCENTER), 0, 65536) / 65536.0)));
//// only use new dejittered value for larger differences
//if(abs(new_val - sa_xaxis) > 10)
// sa_xaxis = new_val;
//setPin(AnalogPin::Nine, AnalogReadout::connectToVcc(MAX_RESISTANCE *
// (BSPF::clamp(32768 - Int32(Int32(sa_xaxis) * SENSITIVITY + XCENTER), 0, 65536) / 65536.0)));
setPin(AnalogPin::Nine, getReadOut(myLastAxisX, sa_xaxis, XCENTER));
sa_changed = true;
}
if(abs(myLastAxisY - sa_yaxis) > 10)
{
// dejitter, suppress small changes only
double dejitter = std::pow(baseFactor, abs(sa_yaxis - myLastAxisY) * diffFactor);
int new_val = sa_yaxis * (1 - dejitter) + myLastAxisY * dejitter;
//// dejitter, suppress small changes only
//double dejitter = pow(baseFactor, abs(sa_yaxis - myLastAxisY) * diffFactor);
//int new_val = sa_yaxis * (1 - dejitter) + myLastAxisY * dejitter;
// only use new dejittered value for larger differences
if(abs(new_val - sa_yaxis) > 10)
sa_yaxis = new_val;
//// only use new dejittered value for larger differences
//if(abs(new_val - sa_yaxis) > 10)
// sa_yaxis = new_val;
setPin(AnalogPin::Five, AnalogReadout::connectToVcc(MAX_RESISTANCE *
(BSPF::clamp(32768 - Int32(Int32(sa_yaxis) * SENSITIVITY + YCENTER), 0, 65536) / 65536.0)));
//setPin(AnalogPin::Five, AnalogReadout::connectToVcc(MAX_RESISTANCE *
// (BSPF::clamp(32768 - Int32(Int32(sa_yaxis) * SENSITIVITY + YCENTER), 0, 65536) / 65536.0)));
setPin(AnalogPin::Nine, getReadOut(myLastAxisY, sa_yaxis, YCENTER));
sa_changed = true;
}
myLastAxisX = sa_xaxis;
@ -271,6 +313,7 @@ void Paddles::updateMouse(bool& firePressedA, bool& firePressedB)
myCharge[myMPaddleID] = BSPF::clamp(myCharge[myMPaddleID] -
(myEvent.get(myAxisMouseMotion) * MOUSE_SENSITIVITY),
TRIGMIN, TRIGRANGE);
if(myMPaddleID == 0)
firePressedA = firePressedA
|| myEvent.get(Event::MouseButtonLeftValue)
@ -286,9 +329,20 @@ void Paddles::updateMouse(bool& firePressedA, bool& firePressedB)
// mapped to a separate paddle
if(myMPaddleIDX > -1)
{
myCharge[myMPaddleIDX] = BSPF::clamp(myCharge[myMPaddleIDX] -
// TODO: REMOVE! Test for 2600-daptor paddles only!
// deadzone
// TODO
//
// accelerate
int diff = myEvent.get(myAxisMouseMotion);
float factor = diff ? pow(abs(diff), ACCEL) / abs(diff) : 0;
int newVal = myCharge[myMPaddleIDX] - diff * factor * pow(MOUSE_SENSITIVITY, 1.f/ACCEL);
myCharge[myMPaddleIDX] = BSPF::clamp(newVal, TRIGMIN, TRIGRANGE);
/* myCharge[myMPaddleIDX] = BSPF::clamp(myCharge[myMPaddleIDX] -
(myEvent.get(Event::MouseAxisXMove) * MOUSE_SENSITIVITY),
TRIGMIN, TRIGRANGE);
TRIGMIN, TRIGRANGE);*/
if(myMPaddleIDX == 0)
firePressedA = firePressedA
|| myEvent.get(Event::MouseButtonLeftValue);
@ -424,6 +478,17 @@ float Paddles::analogSensitivityValue(int sensitivity)
static_cast<float>(BSPF::clamp(sensitivity, MIN_ANALOG_SENSE, MAX_ANALOG_SENSE)));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Paddles::setAnalogDeadzone(int deadzone)
{
DEADZONE = BSPF::clamp(deadzone, MIN_ANALOG_DEADZONE, MAX_ANALOG_DEADZONE);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Paddles::setAnalogAccel(int accel)
{
ACCEL = 1.f + BSPF::clamp(accel, MIN_ANALOG_ACCEL, MAX_ANALOG_ACCEL) / 100.f;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Paddles::setDejitterBase(int strength)
{
@ -460,10 +525,12 @@ void Paddles::setDigitalPaddleRange(int range)
int Paddles::XCENTER = 0;
int Paddles::YCENTER = 0;
float Paddles::SENSITIVITY = 1.0;
int Paddles::DEADZONE = 0;
float Paddles::ACCEL = 0;
int Paddles::DEJITTER_BASE = 0;
int Paddles::DEJITTER_DIFF = 0;
int Paddles::TRIGRANGE = Paddles::TRIGMAX;
int Paddles::DIGITAL_SENSITIVITY = -1;
int Paddles::DIGITAL_DISTANCE = -1;
int Paddles::MOUSE_SENSITIVITY = -1;
int Paddles::DEJITTER_BASE = 0;
int Paddles::DEJITTER_DIFF = 0;

View File

@ -48,9 +48,13 @@ class Paddles : public Controller
~Paddles() override = default;
public:
static constexpr int MIN_ANALOG_DEADZONE = 0;
static constexpr int MAX_ANALOG_DEADZONE = 15000;
static constexpr float BASE_ANALOG_SENSE = 0.148643628F;
static constexpr int MIN_ANALOG_SENSE = 0;
static constexpr int MAX_ANALOG_SENSE = 30;
static constexpr int MIN_ANALOG_ACCEL = 0;
static constexpr int MAX_ANALOG_ACCEL = 100;
static constexpr int MIN_ANALOG_CENTER = -10;
static constexpr int MAX_ANALOG_CENTER = 30;
static constexpr int MIN_DIGITAL_SENSE = 1;
@ -111,6 +115,20 @@ class Paddles : public Controller
*/
static void setAnalogYCenter(int ycenter);
/**
Sets the deadzone for analog paddles.
@param deadzone Value from 0 to 15000
*/
static void setAnalogDeadzone(int deadzone);
/**
Sets the acceleration for analog paddles.
@param accel Value from 100 to 300
*/
static void setAnalogAccel(int accel);
/**
Sets the sensitivity for analog paddles.
@ -121,6 +139,7 @@ class Paddles : public Controller
static float analogSensitivityValue(int sensitivity);
/**
@param strength Value from 0 to 10
*/
@ -192,10 +211,10 @@ class Paddles : public Controller
static int XCENTER;
static int YCENTER;
static float SENSITIVITY;
static float SENSITIVITY, ACCEL;
static int DIGITAL_SENSITIVITY, DIGITAL_DISTANCE;
static int DEJITTER_BASE, DEJITTER_DIFF;
static int DEADZONE, DEJITTER_BASE, DEJITTER_DIFF;
static int MOUSE_SENSITIVITY;
/**
@ -203,6 +222,8 @@ class Paddles : public Controller
*/
void swapEvents(Event::Type& event1, Event::Type& event2);
AnalogReadout::Connection getReadOut(int lastAxis, int& newAxis, int center);
/**
Update the axes pin state according to the events currently set.
*/

View File

@ -22,6 +22,7 @@
#include "Logger.hxx"
#include "AudioSettings.hxx"
#include "PaletteHandler.hxx"
#include "Joystick.hxx"
#include "Paddles.hxx"
#ifdef DEBUGGER_SUPPORT
@ -114,6 +115,8 @@ Settings::Settings()
setPermanent("usemouse", "analog");
setPermanent("grabmouse", "true");
setPermanent("cursor", "2");
setPermanent("pdeadzone", "0");
setPermanent("paccel", "100");
setPermanent("dejitter.base", "0");
setPermanent("dejitter.diff", "0");
setPermanent("dsense", "10");
@ -354,26 +357,34 @@ void Settings::validate()
AudioSettings::normalize(*this);
#endif
i = getInt("joydeadzone");
if(i < 0) setValue("joydeadzone", "0");
else if(i > 29) setValue("joydeadzone", "29");
setValue("joydeadzone", BSPF::clamp(getInt("joydeadzone"),
Joystick::DEAD_ZONE_MIN, Joystick::DEAD_ZONE_MAX));
setValue("pdeadzone", BSPF::clamp(getInt("pdeadzone"),
Paddles::MIN_ANALOG_DEADZONE, Paddles::MAX_ANALOG_DEADZONE));
setValue("psense", BSPF::clamp(getInt("psense"),
Paddles::MIN_ANALOG_SENSE, Paddles::MAX_ANALOG_SENSE));
setValue("paccel", BSPF::clamp(getInt("paccel"),
Paddles::MIN_ANALOG_ACCEL, Paddles::MAX_ANALOG_ACCEL));
setValue("dejitter.base", BSPF::clamp(getInt("dejitter.base"),
Paddles::MIN_DEJITTER, Paddles::MAX_DEJITTER));
setValue("dejitter.diff", BSPF::clamp(getInt("dejitter.diff"),
Paddles::MIN_DEJITTER, Paddles::MAX_DEJITTER));
setValue("dsense", BSPF::clamp(getInt("dsense"),
Paddles::MIN_DIGITAL_SENSE, Paddles::MAX_DIGITAL_SENSE));
setValue("msense", BSPF::clamp(getInt("msense"),
Paddles::MIN_MOUSE_SENSE, Paddles::MAX_MOUSE_SENSE));
i = getInt("cursor");
if(i < 0 || i > 3)
setValue("cursor", "2");
i = getInt("psense");
if(i < Paddles::MIN_ANALOG_SENSE || i > Paddles::MAX_ANALOG_SENSE)
setValue("psense", "20");
i = getInt("dsense");
if(i < Paddles::MIN_DIGITAL_SENSE || i > Paddles::MAX_DIGITAL_SENSE)
setValue("dsense", "10");
i = getInt("msense");
if(i < 1 || i > 20)
setValue("msense", "10");
i = getInt("tsense");
if(i < 1 || i > 20)
setValue("tsense", "10");
@ -510,15 +521,17 @@ void Settings::usage() const
<< " analog|\n"
<< " never> Use mouse as a controller as specified by ROM\n"
<< " properties in given mode(see manual)\n"
<< " -grabmouse <1|0> Locks the mouse cursor in the TIA window\n"
<< " -cursor <0,1,2,3> Set cursor state in UI/emulation modes\n"
<< " -dejitter.base <0-10> Strength of analog paddle value averaging\n"
<< " -dejitter.diff <0-10> Strength of analog paddle reaction to fast movements\n"
<< " -psense <0-30> Sensitivity of analog paddle movement\n"
<< " -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"
<< " -grabmouse <1|0> Locks the mouse cursor in the TIA window\n"
<< " -cursor <0,1,2,3> Set cursor state in UI/emulation modes\n"
<< " -pdeadzone <number> Sets 'deadzone' area for analog paddles (0-15000)\n"
<< " -paccel <0-100> Sets paddle acceleration strength\n"
<< " -dejitter.base <0-10> Strength of analog paddle value averaging\n"
<< " -dejitter.diff <0-10> Strength of analog paddle reaction to fast movements\n"
<< " -psense <0-30> Sensitivity of analog paddle movement\n"
<< " -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"
<< " -autofirerate <0-30> Set fire button's autofire rate (0 means off)\n"
<< " -saport <lr|rl> How to assign virtual ports to multiple\n"