Skip to content

Commit ce4e42e

Browse files
committed
expose analog-is-circle functionality to libretro
1 parent 027edd6 commit ce4e42e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

libretro/libretro.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,16 @@ static void check_variables(CoreParameter &coreParam)
722722
g_Config.iButtonPreference = PSP_SYSTEMPARAM_BUTTON_CIRCLE;
723723
}
724724

725+
var.key = "ppsspp_analog_is_circular";
726+
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
727+
{
728+
if (!strcmp(var.value, "disabled"))
729+
g_Config.bAnalogIsCircular = false;
730+
else
731+
g_Config.bAnalogIsCircular = true;
732+
}
733+
734+
725735
var.key = "ppsspp_internal_resolution";
726736
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
727737
{
@@ -1534,6 +1544,31 @@ static void retro_input(void)
15341544
float y_left = input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / -32767.0f;
15351545
float x_right = input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 32767.0f;
15361546
float y_right = input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / -32767.0f;
1547+
1548+
__CtrlSetAnalogXY(CTRL_STICK_LEFT, x_left, y_left);
1549+
__CtrlSetAnalogXY(CTRL_STICK_RIGHT, x_right, y_right);
1550+
1551+
// Analog circle vs square gate compensation
1552+
// copied from ControlMapper.cpp's ConvertAnalogStick function
1553+
const bool isCircular = g_Config.bAnalogIsCircular;
1554+
1555+
float norm = std::max(fabsf(x_left), fabsf(y_left));
1556+
1557+
if (norm == 0.0f)
1558+
return;
1559+
1560+
if (isCircular) {
1561+
float newNorm = sqrtf(x_left * x_left + y_left * y_left);
1562+
float factor = newNorm / norm;
1563+
x_left *= factor;
1564+
y_left *= factor;
1565+
norm = newNorm;
1566+
}
1567+
1568+
float mappedNorm = norm;
1569+
x_left = std::clamp(x_left / norm * mappedNorm, -1.0f, 1.0f);
1570+
y_left = std::clamp(y_left / norm * mappedNorm, -1.0f, 1.0f);
1571+
15371572
__CtrlSetAnalogXY(CTRL_STICK_LEFT, x_left, y_left);
15381573
__CtrlSetAnalogXY(CTRL_STICK_RIGHT, x_right, y_right);
15391574
}

libretro/libretro_core_options.h

+10
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ struct retro_core_option_v2_definition option_defs_us[] = {
261261
},
262262
"Cross"
263263
},
264+
{
265+
"ppsspp_analog_is_circular",
266+
"Analog Circle vs Square Gate Compensation",
267+
NULL,
268+
NULL,
269+
NULL,
270+
"system",
271+
BOOL_OPTIONS,
272+
"disabled"
273+
},
264274
{
265275
"ppsspp_internal_resolution",
266276
"Internal Resolution (Restart)",

0 commit comments

Comments
 (0)