Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the "Test Analogs" screen with a new screen that lets you directly try the settings. #14596

Merged
merged 7 commits into from
Jul 9, 2021
8 changes: 4 additions & 4 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ static ConfigSetting controlSettings[] = {
ConfigSetting("TouchButtonOpacity", &g_Config.iTouchButtonOpacity, 65, true, true),
ConfigSetting("TouchButtonHideSeconds", &g_Config.iTouchButtonHideSeconds, 20, true, true),
ConfigSetting("AutoCenterTouchAnalog", &g_Config.bAutoCenterTouchAnalog, false, true, true),
ConfigSetting("AnalogAutoRotSpeed", &g_Config.fAnalogAutoRotSpeed, 15.0f, true, true),
ConfigSetting("AnalogAutoRotSpeed", &g_Config.fAnalogAutoRotSpeed, 8.0f, true, true),

// Snap touch control position
ConfigSetting("TouchSnapToGrid", &g_Config.bTouchSnapToGrid, false, true, true),
Expand Down Expand Up @@ -962,10 +962,10 @@ static ConfigSetting controlSettings[] = {
ConfigSetting("AnalogRotationCWKeyX", "AnalogRotationKeyCWY", "AnalogRotationKeyCWScale", "ShowAnalogRotationCWKey", &g_Config.touchAnalogRotationCWKey, defaultTouchPosHide, true, true),
ConfigSetting("AnalogRotationCCWKeyX", "AnalogRotationKeyCCWY", "AnalogRotationKeyCCWScale", "ShowAnalogRotationCCWKey", &g_Config.touchAnalogRotationCCWKey, defaultTouchPosHide, true, true),

ConfigSetting("AnalogDeadzone", &g_Config.fAnalogDeadzone, 0.0f, true, true),
ConfigSetting("AnalogDeadzone", &g_Config.fAnalogDeadzone, 0.15f, true, true),
ConfigSetting("AnalogInverseDeadzone", &g_Config.fAnalogInverseDeadzone, 0.0f, true, true),
ConfigSetting("AnalogSensitivity", &g_Config.fAnalogSensitivity, 1.0f, true, true),
ConfigSetting("AnalogIsCircular", &g_Config.bAnalogIsCircular, true, true, true),
ConfigSetting("AnalogSensitivity", &g_Config.fAnalogSensitivity, 1.1f, true, true),
ConfigSetting("AnalogIsCircular", &g_Config.bAnalogIsCircular, false , true, true),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it circular on most platforms? Won't this give a lot of people diagonal problems?

-[Unknown]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has a circular-ish range on many platforms, but the circular transform used here is a bit extreme and feels weird testing it with the new visualization. Generally it works better to just increase sensitivity (scale) and clamp to a square.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, got it.

-[Unknown]


ConfigSetting("AnalogLimiterDeadzone", &g_Config.fAnalogLimiterDeadzone, 0.6f, true, true),

Expand Down
49 changes: 48 additions & 1 deletion Core/ControlMapper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <algorithm>

#include "Common/Math/math_util.h"
#include "Common/TimeUtil.h"

#include "Core/KeyMap.h"
#include "Core/ControlMapper.h"
#include "Core/Config.h"
Expand All @@ -13,7 +15,7 @@ static float MapAxisValue(float v) {
return sign * Clamp(invDeadzone + (abs(v) - deadzone) / (1.0f - deadzone) * (sensitivity - invDeadzone), 0.0f, 1.0f);
}

static void ConvertAnalogStick(float &x, float &y) {
void ConvertAnalogStick(float &x, float &y) {
const bool isCircular = g_Config.bAnalogIsCircular;

float norm = std::max(fabsf(x), fabsf(y));
Expand All @@ -40,6 +42,11 @@ void ControlMapper::SetCallbacks(std::function<void(int)> onVKeyDown, std::funct
setPSPAnalog_ = setPSPAnalog;
}

void ControlMapper::SetRawCallback(std::function<void(int, float, float)> setRawAnalog) {
setRawAnalog_ = setRawAnalog;
}


void ControlMapper::SetPSPAxis(char axis, float value, int stick) {
static float history[2][2] = {};

Expand All @@ -50,6 +57,10 @@ void ControlMapper::SetPSPAxis(char axis, float value, int stick) {
float x = history[stick][0];
float y = history[stick][1];

if (setRawAnalog_) {
setRawAnalog_(stick, x, y);
}

ConvertAnalogStick(x, y);

setPSPAnalog_(stick, x, y);
Expand Down Expand Up @@ -94,6 +105,23 @@ bool ControlMapper::Axis(const AxisInput &axis) {
return false;
}

void ControlMapper::Update() {
if (autoRotatingAnalogCW_) {
const double now = time_now_d();
// Clamp to a square
float x = std::min(1.0f, std::max(-1.0f, 1.42f * (float)cos(now * -g_Config.fAnalogAutoRotSpeed)));
float y = std::min(1.0f, std::max(-1.0f, 1.42f * (float)sin(now * -g_Config.fAnalogAutoRotSpeed)));

setPSPAnalog_(0, x, y);
} else if (autoRotatingAnalogCCW_) {
const double now = time_now_d();
float x = std::min(1.0f, std::max(-1.0f, 1.42f * (float)cos(now * g_Config.fAnalogAutoRotSpeed)));
float y = std::min(1.0f, std::max(-1.0f, 1.42f * (float)sin(now * g_Config.fAnalogAutoRotSpeed)));

setPSPAnalog_(0, x, y);
}
}


inline bool IsAnalogStickKey(int key) {
switch (key) {
Expand Down Expand Up @@ -203,6 +231,15 @@ void ControlMapper::onVKeyDown(int vkey) {
setVKeyAnalog('Y', CTRL_STICK_RIGHT, VIRTKEY_AXIS_RIGHT_Y_MIN, VIRTKEY_AXIS_RIGHT_Y_MAX, false);
break;

case VIRTKEY_ANALOG_ROTATE_CW:
autoRotatingAnalogCW_ = true;
autoRotatingAnalogCCW_ = false;
break;
case VIRTKEY_ANALOG_ROTATE_CCW:
autoRotatingAnalogCW_ = false;
autoRotatingAnalogCCW_ = true;
break;

default:
if (onVKeyDown_)
onVKeyDown_(vkey);
Expand Down Expand Up @@ -238,6 +275,16 @@ void ControlMapper::onVKeyUp(int vkey) {
setVKeyAnalog('Y', CTRL_STICK_RIGHT, VIRTKEY_AXIS_RIGHT_Y_MIN, VIRTKEY_AXIS_RIGHT_Y_MAX, false);
break;

case VIRTKEY_ANALOG_ROTATE_CW:
autoRotatingAnalogCW_ = false;
__CtrlSetAnalogXY(0, 0.0f, 0.0f);
break;

case VIRTKEY_ANALOG_ROTATE_CCW:
autoRotatingAnalogCCW_ = false;
__CtrlSetAnalogXY(0, 0.0f, 0.0f);
break;

default:
if (onVKeyUp_)
onVKeyUp_(vkey);
Expand Down
13 changes: 13 additions & 0 deletions Core/ControlMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@

class ControlMapper {
public:
void Update();

bool Key(const KeyInput &key, bool *pauseTrigger);
bool Axis(const AxisInput &axis);

// Required callbacks
void SetCallbacks(
std::function<void(int)> onVKeyDown,
std::function<void(int)> onVKeyUp,
std::function<void(int, float, float)> setPSPAnalog);

// Optional callback, only used in config
void SetRawCallback(std::function<void(int, float, float)> setRawAnalog);

private:
void processAxis(const AxisInput &axis, int direction);
void pspKey(int pspKeyCode, int flags);
Expand All @@ -37,8 +43,15 @@ class ControlMapper {
// De-noise mapped axis updates
int axisState_[JOYSTICK_AXIS_MAX]{};

// Mappable auto-rotation. Useful for keyboard/dpad->analog in a few games.
bool autoRotatingAnalogCW_ = false;
bool autoRotatingAnalogCCW_ = false;

// Callbacks
std::function<void(int)> onVKeyDown_;
std::function<void(int)> onVKeyUp_;
std::function<void(int, float, float)> setPSPAnalog_;
std::function<void(int, float, float)> setRawAnalog_;
};

void ConvertAnalogStick(float &x, float &y);
Loading