From 0456f22f8937fbfae936e2cc56611384e1f70433 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 7 Apr 2022 10:39:20 +0200 Subject: [PATCH] Added cursor acceleration option and cursor speed is now consistent between resolutions (thanks to StupidHoroscope) Restored cursor speed to its default value (1.0) Restored sound volume to 192 by default to avoid speaker saturation Subtitles are not forced anymore (but still by default) --- backends/platform/libretro/libretro.cpp | 12 ++- .../platform/libretro/libretro_core_options.h | 22 +++++- backends/platform/libretro/libretro_os.cpp | 78 +++++++++++++------ backends/platform/libretro/os.h | 2 +- base/commandLine.cpp | 8 +- base/main.cpp | 1 - 6 files changed, 93 insertions(+), 30 deletions(-) diff --git a/backends/platform/libretro/libretro.cpp b/backends/platform/libretro/libretro.cpp index 657344496203..37e1588cff50 100644 --- a/backends/platform/libretro/libretro.cpp +++ b/backends/platform/libretro/libretro.cpp @@ -53,6 +53,7 @@ static float gampad_cursor_speed = 1.0f; static bool analog_response_is_quadratic = false; static float mouse_speed = 1.0f; +static float gamepad_acceleration_time = 0.2f; static bool speed_hack_is_enabled = false; @@ -229,6 +230,15 @@ static void update_variables(void) gampad_cursor_speed = (float)atof(var.value); } + var.key = "scummvm_gamepad_cursor_acceleration_time"; + var.value = NULL; + gamepad_acceleration_time = 0.2f; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + printf("Updating gamepad_acceleration_time\n"); + gamepad_acceleration_time = (float)atof(var.value); + } + var.key = "scummvm_analog_response"; var.value = NULL; analog_response_is_quadratic = false; @@ -450,7 +460,7 @@ void retro_run (void) if(g_system) { poll_cb(); - retroProcessMouse(input_cb, retro_device, gampad_cursor_speed, analog_response_is_quadratic, analog_deadzone, mouse_speed); + retroProcessMouse(input_cb, retro_device, gampad_cursor_speed, gamepad_acceleration_time, analog_response_is_quadratic, analog_deadzone, mouse_speed); } /* Run emu */ diff --git a/backends/platform/libretro/libretro_core_options.h b/backends/platform/libretro/libretro_core_options.h index 1147682d8050..d0e6c63aea16 100644 --- a/backends/platform/libretro/libretro_core_options.h +++ b/backends/platform/libretro/libretro_core_options.h @@ -64,7 +64,7 @@ struct retro_core_option_definition option_defs_us[] = { { "3.0", NULL }, { NULL, NULL }, }, - "1.5" + "1.0" }, { "scummvm_analog_response", @@ -123,6 +123,26 @@ struct retro_core_option_definition option_defs_us[] = { }, "1.0" }, + { + "scummvm_gamepad_cursor_acceleration_time", + "Gamepad Cursor Acceleration", + "The amount of time (In seconds) it takes for the cursor to reach full speed", + { + { "off", NULL }, + { "0.1", NULL }, + { "0.2", NULL }, + { "0.3", NULL }, + { "0.4", NULL }, + { "0.5", NULL }, + { "0.6", NULL }, + { "0.7", NULL }, + { "0.8", NULL }, + { "0.9", NULL }, + { "1.0", NULL }, + { NULL, NULL }, + }, + "0.2" + }, { "scummvm_speed_hack", "Speed Hack (Restart)", diff --git a/backends/platform/libretro/libretro_os.cpp b/backends/platform/libretro/libretro_os.cpp index 8af789c0407b..87714aaac7c0 100644 --- a/backends/platform/libretro/libretro_os.cpp +++ b/backends/platform/libretro/libretro_os.cpp @@ -303,6 +303,10 @@ class OSystem_RETRO : public EventsBaseBackend, public PaletteManager { int _mouseY; float _mouseXAcc; float _mouseYAcc; + float _dpadXAcc; + float _dpadYAcc; + float _dpadXVel; + float _dpadYVel; int _mouseHotspotX; int _mouseHotspotY; int _mouseKeyColor; @@ -326,6 +330,7 @@ class OSystem_RETRO : public EventsBaseBackend, public PaletteManager { OSystem_RETRO(bool aEnableSpeedHack) : _mousePaletteEnabled(false), _mouseVisible(false), _mouseX(0), _mouseY(0), _mouseXAcc(0.0), _mouseYAcc(0.0), _mouseHotspotX(0), _mouseHotspotY(0), + _dpadXAcc(0.0), _dpadYAcc(0.0), _dpadXVel(0.0f), _dpadYVel(0.0f), _mouseKeyColor(0), _mouseDontScale(false), _joypadnumpadLast(8), _joypadnumpadActive(false), _mixer(0), _startTime(0), _threadExitTime(10), @@ -808,13 +813,15 @@ class OSystem_RETRO : public EventsBaseBackend, public PaletteManager { #define BASE_CURSOR_SPEED 4 #define PI 3.141592653589793238 - void processMouse(retro_input_state_t aCallback, int device, float gampad_cursor_speed, bool analog_response_is_quadratic, int analog_deadzone, float mouse_speed) + void processMouse(retro_input_state_t aCallback, int device, float gampad_cursor_speed, float gamepad_acceleration_time, bool analog_response_is_quadratic, int analog_deadzone, float mouse_speed) { int16_t joy_x, joy_y, joy_rx, joy_ry, x, y; float analog_amplitude_x, analog_amplitude_y; int mouse_acc_int; bool do_joystick, do_mouse, down; - float adjusted_cursor_speed = (float)BASE_CURSOR_SPEED * gampad_cursor_speed; + float screen_adjusted_cursor_speed = (float)_screen.w / 320.0f; // Dpad cursor speed should always be based off a 320 wide screen, to keep speeds consistent + float adjusted_cursor_speed = (float)BASE_CURSOR_SPEED * gampad_cursor_speed * screen_adjusted_cursor_speed; + float inverse_acceleration_time = (gamepad_acceleration_time > 0.0) ? (1.0 / 60.0) * (1.0 / gamepad_acceleration_time) : 1.0; int dpad_cursor_offset; double rs_radius, rs_angle; unsigned numpad_index; @@ -943,42 +950,69 @@ class OSystem_RETRO : public EventsBaseBackend, public PaletteManager { } } - if (device == RETRO_DEVICE_JOYPAD) { - if (aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT)) + if (device == RETRO_DEVICE_JOYPAD) + { + bool dpadLeft = aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT); + bool dpadRight = aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT); + bool dpadUp = aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP); + bool dpadDown = aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN); + + if (dpadLeft || dpadRight) + { + _dpadXVel = MIN(_dpadXVel + inverse_acceleration_time, 1.0f); + } + else { - dpad_cursor_offset = (int)(adjusted_cursor_speed * 0.5f); - dpad_cursor_offset = (dpad_cursor_offset < 1) ? 1 : dpad_cursor_offset; - _mouseX -= dpad_cursor_offset; + _dpadXVel = 0.0f; + } + + if (dpadUp || dpadDown) + { + _dpadYVel = MIN(_dpadYVel + inverse_acceleration_time, 1.0f); + } + else + { + _dpadYVel = 0.0f; + } + + if (dpadLeft) + { + _dpadXAcc = MIN(_dpadXAcc - _dpadXVel * adjusted_cursor_speed, 0.0f); + _mouseX += (int)_dpadXAcc; + _dpadXAcc -= (float)(int)_dpadXAcc; + _mouseX = (_mouseX < 0) ? 0 : _mouseX; _mouseX = (_mouseX >= _screen.w) ? _screen.w : _mouseX; do_joystick = true; } - - if (aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT)) + if (dpadRight) { - dpad_cursor_offset = (int)(adjusted_cursor_speed * 0.5f); - dpad_cursor_offset = (dpad_cursor_offset < 1) ? 1 : dpad_cursor_offset; - _mouseX += dpad_cursor_offset; + _dpadXAcc = MAX(_dpadXAcc + _dpadXVel * adjusted_cursor_speed, 0.0f); + _mouseX += (int)_dpadXAcc; + _dpadXAcc -= (float)(int)_dpadXAcc; + _mouseX = (_mouseX < 0) ? 0 : _mouseX; _mouseX = (_mouseX >= _screen.w) ? _screen.w : _mouseX; do_joystick = true; } - if (aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP)) + if (dpadUp) { - dpad_cursor_offset = (int)(adjusted_cursor_speed * 0.5f); - dpad_cursor_offset = (dpad_cursor_offset < 1) ? 1 : dpad_cursor_offset; - _mouseY -= dpad_cursor_offset; + _dpadYAcc = MIN(_dpadYAcc - _dpadYVel * adjusted_cursor_speed, 0.0f); + _mouseY += (int)_dpadYAcc; + _dpadYAcc -= (float)(int)_dpadYAcc; + _mouseY = (_mouseY < 0) ? 0 : _mouseY; _mouseY = (_mouseY >= _screen.h) ? _screen.h : _mouseY; do_joystick = true; } - if (aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN)) + if (dpadDown) { - dpad_cursor_offset = (int)(adjusted_cursor_speed * 0.5f); - dpad_cursor_offset = (dpad_cursor_offset < 1) ? 1 : dpad_cursor_offset; - _mouseY += dpad_cursor_offset; + _dpadYAcc = MAX(_dpadYAcc + _dpadYVel * adjusted_cursor_speed, 0.0f); + _mouseY += (int)_dpadYAcc; + _dpadYAcc -= (float)(int)_dpadYAcc; + _mouseY = (_mouseY < 0) ? 0 : _mouseY; _mouseY = (_mouseY >= _screen.h) ? _screen.h : _mouseY; do_joystick = true; @@ -1276,9 +1310,9 @@ const Graphics::Surface& getScreen() return dynamic_cast(g_system)->getScreen(); } -void retroProcessMouse(retro_input_state_t aCallback, int device, float gampad_cursor_speed, bool analog_response_is_quadratic, int analog_deadzone, float mouse_speed) +void retroProcessMouse(retro_input_state_t aCallback, int device, float gamepad_cursor_speed, float gamepad_acceleration_time, bool analog_response_is_quadratic, int analog_deadzone, float mouse_speed) { - dynamic_cast(g_system)->processMouse(aCallback, device, gampad_cursor_speed, analog_response_is_quadratic, analog_deadzone, mouse_speed); + dynamic_cast(g_system)->processMouse(aCallback, device, gamepad_cursor_speed, gamepad_acceleration_time, analog_response_is_quadratic, analog_deadzone, mouse_speed); } void retroPostQuit() diff --git a/backends/platform/libretro/os.h b/backends/platform/libretro/os.h index 22b5809eb77a..f52cee8fd50f 100644 --- a/backends/platform/libretro/os.h +++ b/backends/platform/libretro/os.h @@ -52,7 +52,7 @@ extern int access(const char *path, int amode); OSystem* retroBuildOS(bool aEnableSpeedHack); const Graphics::Surface& getScreen(); -void retroProcessMouse(retro_input_state_t aCallback, int device, float gampad_cursor_speed, bool analog_response_is_quadratic, int analog_deadzone, float mouse_speed); +void retroProcessMouse(retro_input_state_t aCallback, int device, float gamepad_cursor_speed, float gamepad_acceleration_time, bool analog_response_is_quadratic, int analog_deadzone, float mouse_speed); void retroPostQuit(); void retroSetSystemDir(const char* aPath); diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 5984e84766de..cc3df6242ea8 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -257,9 +257,9 @@ void registerDefaults() { ConfMan.registerDefault("vsync", true); // Sound & Music - ConfMan.registerDefault("music_volume", 256); - ConfMan.registerDefault("sfx_volume", 256); - ConfMan.registerDefault("speech_volume", 256); + ConfMan.registerDefault("music_volume", 192); + ConfMan.registerDefault("sfx_volume", 192); + ConfMan.registerDefault("speech_volume", 192); ConfMan.registerDefault("music_mute", false); ConfMan.registerDefault("sfx_mute", false); @@ -285,7 +285,7 @@ void registerDefaults() { ConfMan.registerDefault("path", ""); ConfMan.registerDefault("platform", Common::kPlatformDOS); ConfMan.registerDefault("language", "en"); - ConfMan.registerDefault("subtitles", false); + ConfMan.registerDefault("subtitles", true); ConfMan.registerDefault("boot_param", 0); ConfMan.registerDefault("dump_scripts", false); ConfMan.registerDefault("save_slot", -1); diff --git a/base/main.cpp b/base/main.cpp index 3f5ee2901067..1cd58473415f 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -425,7 +425,6 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { ConfMan.set("themepath", "./theme", Common::ConfigManager::kApplicationDomain); ConfMan.set("extrapath", "./extra", Common::ConfigManager::kApplicationDomain); ConfMan.set("gui_scale", "90", Common::ConfigManager::kApplicationDomain); - ConfMan.set("subtitles", "true", Common::ConfigManager::kApplicationDomain); // Load and setup the debuglevel and the debug flags. We do this at the // soonest possible moment to ensure debug output starts early on, if