2525#include <stdlib.h>
2626#include <stddef.h>
2727#include <string.h>
28- #include <time.h>
2928
3029#include <boolean.h>
3130#include <retro_inline.h>
@@ -52,8 +51,6 @@ typedef struct
5251 bool connected ;
5352} xinput_joypad_state ;
5453
55- #define RUMBLE_INTERVAL 0.005
56-
5754/* Function pointer, to be assigned with dylib_proc */
5855typedef uint32_t (__stdcall * XInputGetStateEx_t )(uint32_t , XINPUT_STATE * );
5956typedef uint32_t (__stdcall * XInputSetState_t )(uint32_t , XINPUT_VIBRATION * );
@@ -75,7 +72,6 @@ static XINPUT_VIBRATION g_xinput_rumble_states[4];
7572#endif
7673static xinput_joypad_state g_xinput_states [4 ];
7774static bool xinput_active_port [4 ] = {0 };
78- static clock_t last_rumble_time [4 ] = {0 };
7975
8076static unsigned xinput_hotplug_index = 0 ;
8177static unsigned xinput_poll_counter = 0 ;
@@ -434,43 +430,29 @@ if (!xinput_active_port[i] && has_active_ports)
434430static bool xinput_joypad_rumble (unsigned pad ,
435431 enum retro_rumble_effect effect , uint16_t strength )
436432{
437- clock_t now ;
438- double time_since_last_rumble ;
439- XINPUT_VIBRATION * state , new_state ;
440- int xuser = pad_index_to_xuser_index (pad );
433+ XINPUT_VIBRATION * state , prev ;
434+ int xuser = pad_index_to_xuser_index (pad );
441435
442436 if (xuser == -1 )
443437 return false;
444438
445- state = & g_xinput_rumble_states [xuser ];
446- new_state = * state ;
439+ state = & g_xinput_rumble_states [xuser ];
440+ prev = * state ;
447441
448442 /* Consider the low frequency (left) motor the "strong" one. */
449443 if (effect == RETRO_RUMBLE_STRONG )
450- new_state . wLeftMotorSpeed = strength ;
444+ state -> wLeftMotorSpeed = strength ;
451445 else if (effect == RETRO_RUMBLE_WEAK )
452- new_state . wRightMotorSpeed = strength ;
446+ state -> wRightMotorSpeed = strength ;
453447
454448 /* Rumble state unchanged? */
455- if ( (new_state . wLeftMotorSpeed == state -> wLeftMotorSpeed )
456- && (new_state . wRightMotorSpeed == state -> wRightMotorSpeed ))
449+ if ( (state -> wLeftMotorSpeed == prev . wLeftMotorSpeed )
450+ && (state -> wRightMotorSpeed == prev . wRightMotorSpeed ))
457451 return true;
458452
459- now = clock ();
460- time_since_last_rumble = (double )(now - last_rumble_time [xuser ]) / CLOCKS_PER_SEC ;
461-
462- /* Rumble interval unelapsed? */
463- if (time_since_last_rumble < RUMBLE_INTERVAL )
453+ if (g_XInputSetState && (g_XInputSetState (xuser , state ) == ERROR_SUCCESS ))
464454 return true;
465455
466- if (g_XInputSetState )
467- {
468- * state = new_state ;
469- last_rumble_time [xuser ] = now ;
470- if (g_XInputSetState (xuser , state ) == ERROR_SUCCESS )
471- return true;
472- }
473-
474456 return false;
475457}
476458
0 commit comments