Skip to content

Commit

Permalink
Remove in/out function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Mar 31, 2023
1 parent 526b4f7 commit 7dfa587
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
20 changes: 11 additions & 9 deletions Core/ControlMapper.cpp
Expand Up @@ -41,13 +41,15 @@ static float MapAxisValue(float v) {
return sign * Clamp(invDeadzone + (abs(v) - deadzone) / (1.0f - deadzone) * (sensitivity - invDeadzone), 0.0f, 1.0f);
}

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

float norm = std::max(fabsf(x), fabsf(y));

if (norm == 0.0f)
if (norm == 0.0f) {
*outX = x;
*outY = y;
return;
}

if (isCircular) {
float newNorm = sqrtf(x * x + y * y);
Expand All @@ -58,8 +60,8 @@ void ConvertAnalogStick(float &x, float &y) {
}

float mappedNorm = MapAxisValue(norm);
x = Clamp(x / norm * mappedNorm, -1.0f, 1.0f);
y = Clamp(y / norm * mappedNorm, -1.0f, 1.0f);
*outX = Clamp(x / norm * mappedNorm, -1.0f, 1.0f);
*outY = Clamp(y / norm * mappedNorm, -1.0f, 1.0f);
}

void ControlMapper::SetCallbacks(
Expand Down Expand Up @@ -102,7 +104,7 @@ void ControlMapper::SetPSPAxis(int device, int stick, char axis, float value) {
bool ignore = false;
if (inDeadZone && lastNonDeadzoneDeviceID_[stick] != device) {
// Ignore this event! See issue #15465
ignore = true;
ignore = true;
}

if (!inDeadZone) {
Expand All @@ -114,9 +116,9 @@ void ControlMapper::SetPSPAxis(int device, int stick, char axis, float value) {

float x = history_[stick][0];
float y = history_[stick][1];

ConvertAnalogStick(x, y);
setPSPAnalog_(stick, x, y);
float convertedX, convertedY;
ConvertAnalogStick(x, y, &convertedX, &convertedY);
setPSPAnalog_(stick, convertedX, convertedY);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Core/ControlMapper.h
Expand Up @@ -66,4 +66,4 @@ class ControlMapper {
std::function<void(int, float, float)> setRawAnalog_;
};

void ConvertAnalogStick(float &x, float &y);
void ConvertAnalogStick(float x, float y, float *outX, float *outY);
8 changes: 4 additions & 4 deletions UI/JoystickHistoryView.cpp
Expand Up @@ -34,8 +34,8 @@ void JoystickHistoryView::Draw(UIContext &dc) {
float by = (iy + 1) * dx;

if (type_ == StickHistoryViewType::OUTPUT) {
ConvertAnalogStick(ax, ay);
ConvertAnalogStick(bx, by);
ConvertAnalogStick(ax, ay, &ax, &ay);
ConvertAnalogStick(bx, by, &bx, &by);
}

ax = ax * minRadius + bounds_.centerX();
Expand All @@ -58,8 +58,8 @@ void JoystickHistoryView::Draw(UIContext &dc) {
float by = fy;

if (type_ == StickHistoryViewType::OUTPUT) {
ConvertAnalogStick(ax, ay);
ConvertAnalogStick(bx, by);
ConvertAnalogStick(ax, ay, &ax, &ay);
ConvertAnalogStick(bx, by, &bx, &by);
}

ax = ax * minRadius + bounds_.centerX();
Expand Down

0 comments on commit 7dfa587

Please sign in to comment.