mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-25 15:15:40 +00:00
libretro: Add rumble interface
This commit is contained in:
parent
c9c2c00c1a
commit
de388d342f
|
@ -63,6 +63,14 @@ LibretroHostInterface::~LibretroHostInterface()
|
|||
}
|
||||
}
|
||||
|
||||
void LibretroHostInterface::InitInterfaces()
|
||||
{
|
||||
SetCoreOptions();
|
||||
InitLogging();
|
||||
InitDiskControlInterface();
|
||||
InitRumbleInterface();
|
||||
}
|
||||
|
||||
void LibretroHostInterface::InitLogging()
|
||||
{
|
||||
if (s_libretro_log_callback_registered)
|
||||
|
@ -650,6 +658,11 @@ void LibretroHostInterface::CheckForSettingsChanges(const Settings& old_settings
|
|||
UpdateLogging();
|
||||
}
|
||||
|
||||
void LibretroHostInterface::InitRumbleInterface()
|
||||
{
|
||||
m_rumble_interface_valid = g_retro_environment_callback(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &m_rumble_interface);
|
||||
}
|
||||
|
||||
void LibretroHostInterface::UpdateControllers()
|
||||
{
|
||||
g_retro_input_poll_callback();
|
||||
|
@ -745,6 +758,17 @@ void LibretroHostInterface::UpdateControllersAnalogController(u32 index)
|
|||
const int16_t state = g_retro_input_state_callback(index, RETRO_DEVICE_ANALOG, it.second.first, it.second.second);
|
||||
controller->SetAxisState(static_cast<s32>(it.first), std::clamp(static_cast<float>(state) / 32767.0f, -1.0f, 1.0f));
|
||||
}
|
||||
|
||||
if (m_rumble_interface_valid)
|
||||
{
|
||||
const u32 motor_count = controller->GetVibrationMotorCount();
|
||||
for (u32 i = 0; i < motor_count; i++)
|
||||
{
|
||||
const float strength = controller->GetVibrationMotorStrength(i);
|
||||
m_rumble_interface.set_rumble_state(index, RETRO_RUMBLE_STRONG,
|
||||
static_cast<u16>(static_cast<u32>(strength * 65565.0f)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static std::optional<GPURenderer> RetroHwContextToRenderer(retro_hw_context_type type)
|
||||
|
|
|
@ -11,10 +11,7 @@ public:
|
|||
LibretroHostInterface();
|
||||
~LibretroHostInterface() override;
|
||||
|
||||
static void InitLogging();
|
||||
static bool SetCoreOptions();
|
||||
static bool HasCoreVariablesChanged();
|
||||
static void InitDiskControlInterface();
|
||||
void InitInterfaces();
|
||||
|
||||
ALWAYS_INLINE u32 GetResolutionScale() const { return g_settings.gpu_resolution_scale; }
|
||||
|
||||
|
@ -51,6 +48,12 @@ protected:
|
|||
void CheckForSettingsChanges(const Settings& old_settings) override;
|
||||
|
||||
private:
|
||||
bool SetCoreOptions();
|
||||
bool HasCoreVariablesChanged();
|
||||
void InitLogging();
|
||||
void InitDiskControlInterface();
|
||||
void InitRumbleInterface();
|
||||
|
||||
void LoadSettings();
|
||||
void UpdateSettings();
|
||||
void UpdateControllers();
|
||||
|
@ -86,6 +89,9 @@ private:
|
|||
bool m_hw_render_callback_valid = false;
|
||||
bool m_using_hardware_renderer = false;
|
||||
std::optional<u32> m_next_disc_index;
|
||||
|
||||
retro_rumble_interface m_rumble_interface = {};
|
||||
bool m_rumble_interface_valid = false;
|
||||
};
|
||||
|
||||
extern LibretroHostInterface g_libretro_host_interface;
|
||||
|
|
|
@ -122,12 +122,7 @@ RETRO_API size_t retro_get_memory_size(unsigned id)
|
|||
RETRO_API void retro_set_environment(retro_environment_t f)
|
||||
{
|
||||
g_retro_environment_callback = f;
|
||||
|
||||
if (!g_libretro_host_interface.SetCoreOptions())
|
||||
Log_WarningPrintf("Failed to set core options, settings will not be changeable.");
|
||||
|
||||
g_libretro_host_interface.InitLogging();
|
||||
g_libretro_host_interface.InitDiskControlInterface();
|
||||
g_libretro_host_interface.InitInterfaces();
|
||||
}
|
||||
|
||||
RETRO_API void retro_set_video_refresh(retro_video_refresh_t f)
|
||||
|
|
Loading…
Reference in a new issue