Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
Added cursor acceleration option and cursor speed is now consistent b…
Browse files Browse the repository at this point in the history
…etween 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)
  • Loading branch information
DrUm78 committed Apr 23, 2022
1 parent 83d1f20 commit 0456f22
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 30 deletions.
12 changes: 11 additions & 1 deletion backends/platform/libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
22 changes: 21 additions & 1 deletion backends/platform/libretro/libretro_core_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct retro_core_option_definition option_defs_us[] = {
{ "3.0", NULL },
{ NULL, NULL },
},
"1.5"
"1.0"
},
{
"scummvm_analog_response",
Expand Down Expand Up @@ -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)",
Expand Down
78 changes: 56 additions & 22 deletions backends/platform/libretro/libretro_os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1276,9 +1310,9 @@ const Graphics::Surface& getScreen()
return dynamic_cast<OSystem_RETRO *>(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<OSystem_RETRO *>(g_system)->processMouse(aCallback, device, gampad_cursor_speed, analog_response_is_quadratic, analog_deadzone, mouse_speed);
dynamic_cast<OSystem_RETRO *>(g_system)->processMouse(aCallback, device, gamepad_cursor_speed, gamepad_acceleration_time, analog_response_is_quadratic, analog_deadzone, mouse_speed);
}

void retroPostQuit()
Expand Down
2 changes: 1 addition & 1 deletion backends/platform/libretro/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions base/commandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion base/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0456f22

Please sign in to comment.