From 399a33fe36f8a777cd64dbbad7f3fa022360a5e6 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Mon, 8 Jun 2020 18:09:22 +0800 Subject: [PATCH] Update mouse device support, add mouse sensitivity option - Remove unnecessary accumulator, cleanup and comments - Add "Emulated Mouse Sensitivity" core option with range from 0.05 to 2.00, with 1.00 as normal mouse movement. --- frontend/libretro.c | 68 +++++++++++++++++--------------- frontend/libretro_core_options.h | 48 ++++++++++++++++++++++ 2 files changed, 84 insertions(+), 32 deletions(-) diff --git a/frontend/libretro.c b/frontend/libretro.c index a91c5c17..50392a9c 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -90,6 +90,7 @@ static int show_advanced_gpu_peops_settings = -1; static int show_advanced_gpu_unai_settings = -1; #endif static int show_other_input_settings = -1; +static float mouse_sensitivity = 1.0f; static unsigned previous_width = 0; static unsigned previous_height = 0; @@ -2108,6 +2109,13 @@ static void update_variables(bool in_flight) } #endif /* NEW_DYNAREC */ + var.value = NULL; + var.key = "pcsx_rearmed_input_sensitivity"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + mouse_sensitivity = atof(var.value); + } + var.key = "pcsx_rearmed_show_other_input_settings"; var.value = NULL; @@ -2396,6 +2404,32 @@ static void update_input_negcon(int port, int ret) in_analog_left[port][1] = get_analog_button(ret, input_state_cb, port, RETRO_DEVICE_ID_JOYPAD_L); } +static void update_input_mouse(int port, int ret) +{ + float raw_x = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); + float raw_y = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); + + int x = (int)roundf(raw_x * mouse_sensitivity); + int y = (int)roundf(raw_y * mouse_sensitivity); + + if (x > 127) x = 127; + else if (x < -128) x = -128; + + if (y > 127) y = 127; + else if (y < -128) y = -128; + + in_mouse[port][0] = x; /* -128..+128 left/right movement, 0 = no movement */ + in_mouse[port][1] = y; /* -128..+128 down/up movement, 0 = no movement */ + + /* left mouse button state */ + if (input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)) + in_keystate[port] |= 1 << 11; + + /* right mouse button state */ + if (input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT)) + in_keystate[port] |= 1 << 10; +} + static void update_input(void) { // reset all keystate, query libretro for keystate @@ -2432,38 +2466,8 @@ static void update_input(void) update_input_negcon(i, ret); break; case PSE_PAD_TYPE_MOUSE: - { - /* mouse x/y movement, range -128 to +127 */ - float accum_x = 0, accum_y = 0; - - float x = input_state_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); - float y = input_state_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); - - accum_x += x; - accum_y += y; - - if (accum_x > 127) - accum_x = 127; - else if (accum_x < -128) - accum_x = -128; - - if (accum_y > 127) - accum_y = 127; - else if (accum_y < -128) - accum_y = -128; - - in_mouse[i][0] = (int)accum_x; - in_mouse[i][1] = (int)accum_y; - - /* mouse button state */ - if (input_state_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)) - in_keystate[i] |= 1 << 11; - - if (input_state_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT)) - in_keystate[i] |= 1 << 10; - - break; - } + update_input_mouse(i, ret); + break; default: // Query digital inputs for (j = 0; j < RETRO_PSX_MAP_LEN; j++) diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h index 46670baa..95544f09 100644 --- a/frontend/libretro_core_options.h +++ b/frontend/libretro_core_options.h @@ -108,6 +108,54 @@ struct retro_core_option_definition option_defs_us[] = { }, "disabled", }, + { + "pcsx_rearmed_input_sensitivity", + "Emulated Mouse Sensitivity", + "Adjust responsiveness when using mouse controller (Default 1.0).", + { + { "0.05", NULL }, + { "0.10", NULL }, + { "0.15", NULL }, + { "0.20", NULL }, + { "0.25", NULL }, + { "0.30", NULL }, + { "0.35", NULL }, + { "0.40", NULL }, + { "0.45", NULL }, + { "0.50", NULL }, + { "0.55", NULL }, + { "0.60", NULL }, + { "0.65", NULL }, + { "0.70", NULL }, + { "0.75", NULL }, + { "0.80", NULL }, + { "0.85", NULL }, + { "0.90", NULL }, + { "0.95", NULL }, + { "1.00", NULL }, + { "1.05", NULL }, + { "1.10", NULL }, + { "1.15", NULL }, + { "1.20", NULL }, + { "1.25", NULL }, + { "1.30", NULL }, + { "1.35", NULL }, + { "1.40", NULL }, + { "1.45", NULL }, + { "1.50", NULL }, + { "1.55", NULL }, + { "1.60", NULL }, + { "1.65", NULL }, + { "1.70", NULL }, + { "1.75", NULL }, + { "1.80", NULL }, + { "1.85", NULL }, + { "1.90", NULL }, + { "1.95", NULL }, + { "2.00", NULL }, + }, + "1.00", + }, { "pcsx_rearmed_pad1type", "Pad 1 Type", -- 2.39.2