PAD: Store rumble intensity as float

No longer have to worry about what the max value should be
Unlocks > 50% rumble power on new rumble API
This commit is contained in:
TellowKrinkle 2021-12-01 15:41:43 -06:00 committed by tellowkrinkle
parent 5d6f0d7e47
commit 5f168b1a1e
4 changed files with 19 additions and 16 deletions

View File

@ -73,7 +73,7 @@ void PADSaveConfig()
fprintf(f, "log = %d\n", g_conf.log);
fprintf(f, "options = %d\n", g_conf.packed_options);
fprintf(f, "mouse_sensibility = %d\n", g_conf.get_sensibility());
fprintf(f, "ff_intensity = %d\n", g_conf.get_ff_intensity());
fprintf(f, "ff_intensity = %g\n", g_conf.get_ff_intensity());
fprintf(f, "uid[0] = %zu\n", g_conf.get_joy_uid(0));
fprintf(f, "uid[1] = %zu\n", g_conf.get_joy_uid(1));
@ -109,6 +109,7 @@ void PADLoadConfig()
}
u32 value;
float fvalue;
if (fscanf(f, "first_time_wizard = %u\n", &value) == 1)
g_conf.ftw = value;
@ -122,8 +123,12 @@ void PADLoadConfig()
if (fscanf(f, "mouse_sensibility = %u\n", &value) == 1)
g_conf.set_sensibility(value);
if (fscanf(f, "ff_intensity = %u\n", &value) == 1)
g_conf.set_ff_intensity(value);
if (fscanf(f, "ff_intensity = %f\n", &fvalue) == 1)
{
if (fvalue > 1)
fvalue /= 0x7fff; // Old config
g_conf.set_ff_intensity(fvalue);
}
size_t uid;
if (fscanf(f, "uid[0] = %zu\n", &uid) == 1)

View File

@ -19,7 +19,7 @@
class PADconf
{
u32 ff_intensity;
float ff_intensity;
u32 sensibility;
public:
@ -53,7 +53,7 @@ public:
log = 0;
ftw = 1;
packed_options = 0;
ff_intensity = 0x7FFF; // set it at max value by default
ff_intensity = 1.0; // set it at max value by default
sensibility = 100;
for (u32 pad = 0; pad < GAMEPAD_NUMBER; pad++)
{
@ -80,7 +80,7 @@ public:
/**
* Return (a copy of) private memner ff_instensity
**/
u32 get_ff_intensity()
float get_ff_intensity()
{
return ff_intensity;
}
@ -89,12 +89,9 @@ public:
* Set intensity while checking that the new value is within
* valid range, more than 0x7FFF will cause pad not to rumble(and less than 0 is obviously bad)
**/
void set_ff_intensity(u32 new_intensity)
void set_ff_intensity(float new_intensity)
{
if (new_intensity <= 0x7FFF)
{
ff_intensity = new_intensity;
}
ff_intensity = std::min(std::max(new_intensity, 0.f), 1.f);
}
/**

View File

@ -110,7 +110,7 @@ void JoystickInfo::UpdateRumble(bool needs_update)
{
if (remaining > 0)
{
rumble_amt[i] = std::min<u32>(g_conf.get_ff_intensity(), UINT16_MAX);
rumble_amt[i] = std::min<u32>(g_conf.get_ff_intensity() * UINT16_MAX, UINT16_MAX);
rumble_time = std::max(rumble_time, static_cast<u32>(remaining));
}
else
@ -228,7 +228,7 @@ size_t JoystickInfo::GetUniqueIdentifier()
bool JoystickInfo::TestForce(float strength = 0.60)
{
u16 u16strength = static_cast<u16>(0x7fff * strength);
u16 u16strength = static_cast<u16>(UINT16_MAX * strength);
return SDL_GameControllerRumble(m_controller, u16strength, u16strength, 400) >= 0;
}

View File

@ -117,11 +117,12 @@ void GamepadConfiguration::OnSliderReleased(wxCommandEvent& event)
if (sl_id == rumble_slider_id)
{
g_conf.set_ff_intensity(m_sl_rumble_intensity->GetValue());
float value = static_cast<float>(m_sl_rumble_intensity->GetValue()) / 0x7FFF;
g_conf.set_ff_intensity(value);
// convert in a float value between 0 and 1, and run rumble feedback.
// 0 to 1 scales to 0x0 to 0x7FFF
device_manager.devices[m_pad_id]->TestForce(m_sl_rumble_intensity->GetValue() / (float)0x7FFF);
device_manager.devices[m_pad_id]->TestForce(value);
}
else if (sl_id == joy_slider_id)
{
@ -174,7 +175,7 @@ void GamepadConfiguration::repopulate()
{
m_cb_rumble->SetValue(g_conf.pad_options[m_pad_id].forcefeedback);
m_sl_rumble_intensity->SetValue(g_conf.get_ff_intensity());
m_sl_rumble_intensity->SetValue(g_conf.get_ff_intensity() * 0x7FFF);
m_sl_joystick_sensibility->SetValue(g_conf.get_sensibility());
u32 joyid = Device::uid_to_index(m_pad_id);