mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Rework and simplify VIRTKEY_SPEED_ANALOG
This commit is contained in:
1 parent
ca300a4dfd
commit
fa0fb6eee6
6 files changed
+26
-69
No files matched your search
@@ -849,7 +849,6 @@ static const ConfigSetting graphicsSettings[] = {
|
||||
ConfigSetting("FrameRate", &g_Config.iFpsLimit1, 0, true, true),
|
||||
ConfigSetting("FrameRate2", &g_Config.iFpsLimit2, -1, true, true),
|
||||
ConfigSetting("AnalogFrameRate", &g_Config.iAnalogFpsLimit, 240, true, true),
|
||||
ConfigSetting("AnalogFrameRateMode", &g_Config.iAnalogFpsMode, 0, true, true),
|
||||
ConfigSetting("UnthrottlingMode", &g_Config.iFastForwardMode, &DefaultFastForwardMode, &FastForwardModeToString, &FastForwardModeFromString, true, true),
|
||||
#if defined(USING_WIN_UI)
|
||||
ConfigSetting("RestartRequired", &g_Config.bRestartRequired, false, false),
|
||||
|
||||
@@ -220,7 +220,6 @@ public:
|
||||
int iFpsLimit1;
|
||||
int iFpsLimit2;
|
||||
int iAnalogFpsLimit;
|
||||
int iAnalogFpsMode; // 0 = auto, 1 = single direction, 2 = mapped to opposite
|
||||
int iMaxRecent;
|
||||
int iCurrentStateSlot;
|
||||
int iRewindSnapshotInterval;
|
||||
|
||||
@@ -132,12 +132,6 @@ enum class BackgroundAnimation {
|
||||
MOVING_BACKGROUND = 4,
|
||||
};
|
||||
|
||||
enum class AnalogFpsMode {
|
||||
AUTO = 0,
|
||||
MAPPED_DIRECTION = 1,
|
||||
MAPPED_DIR_TO_OPPOSITE_DIR = 2,
|
||||
};
|
||||
|
||||
// for Config.iShowStatusFlags
|
||||
enum class ShowStatusFlags {
|
||||
FPS_COUNTER = 1 << 1,
|
||||
|
||||
@@ -365,62 +365,3 @@ void ControlMapper::onVKey(int vkey, bool down) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ControlMapper::ProcessAnalogSpeed(const AxisInput &axis, bool opposite) {
|
||||
static constexpr float DEADZONE_THRESHOLD = 0.15f;
|
||||
static constexpr float DEADZONE_SCALE = 1.0f / (1.0f - DEADZONE_THRESHOLD);
|
||||
|
||||
FPSLimit &limitMode = PSP_CoreParameter().fpsLimit;
|
||||
// If we're using an alternate speed already, let that win.
|
||||
if (limitMode != FPSLimit::NORMAL && limitMode != FPSLimit::ANALOG)
|
||||
return;
|
||||
// Don't even try if the limit is invalid.
|
||||
if (g_Config.iAnalogFpsLimit <= 0)
|
||||
return;
|
||||
|
||||
AnalogFpsMode mode = (AnalogFpsMode)g_Config.iAnalogFpsMode;
|
||||
float value = axis.value;
|
||||
if (mode == AnalogFpsMode::AUTO) {
|
||||
// TODO: Consider the pad name for better auto? KeyMap::PadName(axis.deviceId);
|
||||
switch (axis.axisId) {
|
||||
case JOYSTICK_AXIS_X:
|
||||
case JOYSTICK_AXIS_Y:
|
||||
case JOYSTICK_AXIS_Z:
|
||||
case JOYSTICK_AXIS_RX:
|
||||
case JOYSTICK_AXIS_RY:
|
||||
case JOYSTICK_AXIS_RZ:
|
||||
// These, at least on directinput, can be used for triggers that go from mapped to opposite.
|
||||
mode = AnalogFpsMode::MAPPED_DIR_TO_OPPOSITE_DIR;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Other axises probably don't go from negative to positive.
|
||||
mode = AnalogFpsMode::MAPPED_DIRECTION;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Okay, now let's map it as appropriate.
|
||||
if (mode == AnalogFpsMode::MAPPED_DIRECTION) {
|
||||
value = fabsf(value);
|
||||
// Clamp to 0 in this case if we're processing the opposite direction.
|
||||
if (opposite)
|
||||
value = 0.0f;
|
||||
} else if (mode == AnalogFpsMode::MAPPED_DIR_TO_OPPOSITE_DIR) {
|
||||
value = fabsf(value);
|
||||
if (opposite)
|
||||
value = -value;
|
||||
value = 0.5f - value * 0.5f;
|
||||
}
|
||||
|
||||
// Apply a small deadzone (against the resting position.)
|
||||
value = std::max(0.0f, (value - DEADZONE_THRESHOLD) * DEADZONE_SCALE);
|
||||
|
||||
// If target is above 60, value is how much to speed up over 60. Otherwise, it's how much slower.
|
||||
// So normalize the target.
|
||||
int target = g_Config.iAnalogFpsLimit - 60;
|
||||
PSP_CoreParameter().analogFpsLimit = 60 + (int)(target * value);
|
||||
|
||||
// If we've reset back to normal, turn it off.
|
||||
limitMode = PSP_CoreParameter().analogFpsLimit == 60 ? FPSLimit::NORMAL : FPSLimit::ANALOG;
|
||||
}
|
||||
@@ -36,8 +36,6 @@ private:
|
||||
|
||||
void SetPSPAxis(int deviceId, int stick, char axis, float value);
|
||||
|
||||
void ProcessAnalogSpeed(const AxisInput &axis, bool opposite);
|
||||
|
||||
void onVKey(int vkey, bool down);
|
||||
void onVKeyAnalog(int deviceId, int vkey, float value);
|
||||
|
||||
|
||||
@@ -764,7 +764,33 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
|
||||
}
|
||||
|
||||
void EmuScreen::onVKeyAnalog(int virtualKeyCode, float value) {
|
||||
if (virtualKeyCode != VIRTKEY_SPEED_ANALOG) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We only handle VIRTKEY_SPEED_ANALOG here.
|
||||
|
||||
static constexpr float DEADZONE_THRESHOLD = 0.15f;
|
||||
static constexpr float DEADZONE_SCALE = 1.0f / (1.0f - DEADZONE_THRESHOLD);
|
||||
|
||||
FPSLimit &limitMode = PSP_CoreParameter().fpsLimit;
|
||||
// If we're using an alternate speed already, let that win.
|
||||
if (limitMode != FPSLimit::NORMAL && limitMode != FPSLimit::ANALOG)
|
||||
return;
|
||||
// Don't even try if the limit is invalid.
|
||||
if (g_Config.iAnalogFpsLimit <= 0)
|
||||
return;
|
||||
|
||||
// Apply a small deadzone (against the resting position.)
|
||||
value = std::max(0.0f, (value - DEADZONE_THRESHOLD) * DEADZONE_SCALE);
|
||||
|
||||
// If target is above 60, value is how much to speed up over 60. Otherwise, it's how much slower.
|
||||
// So normalize the target.
|
||||
int target = g_Config.iAnalogFpsLimit - 60;
|
||||
PSP_CoreParameter().analogFpsLimit = 60 + (int)(target * value);
|
||||
|
||||
// If we've reset back to normal, turn it off.
|
||||
limitMode = PSP_CoreParameter().analogFpsLimit == 60 ? FPSLimit::NORMAL : FPSLimit::ANALOG;
|
||||
}
|
||||
|
||||
bool EmuScreen::key(const KeyInput &key) {
|
||||
|
||||
Reference in new issue
Block a user