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 ;
@@ -351,7 +347,9 @@ static int16_t xinput_joypad_state_func(
351347static void xinput_joypad_poll (void )
352348{
353349 int i ;
350+ #ifdef __WINRT__
354351 bool has_active_ports = false;
352+ #endif
355353
356354 /* Hotplugging detection: scanning one port at a time every few frames,
357355 * to avoid polling overload and framerate drops. */
@@ -382,11 +380,13 @@ static void xinput_joypad_poll(void)
382380 xinput_hotplug_index = (xinput_hotplug_index + 1 ) % 4 ;
383381 }
384382
383+ #ifdef __WINRT__
385384 for (i = 0 ; i < 4 ; ++ i )
386385 {
387386 if (xinput_active_port [i ])
388387 has_active_ports = true;
389388 }
389+ #endif
390390
391391 for (i = 0 ; i < 4 ; ++ i )
392392 {
@@ -397,8 +397,8 @@ static void xinput_joypad_poll(void)
397397 * If no ports are currently active, we need to poll all ports
398398 * to catch any late arriving controllers. */
399399#ifdef __WINRT__
400- if (!xinput_active_port [i ] && has_active_ports )
401- continue ;
400+ if (!xinput_active_port [i ] && has_active_ports )
401+ continue ;
402402#else
403403 if (!xinput_active_port [i ])
404404 continue ;
@@ -434,44 +434,27 @@ if (!xinput_active_port[i] && has_active_ports)
434434static bool xinput_joypad_rumble (unsigned pad ,
435435 enum retro_rumble_effect effect , uint16_t strength )
436436{
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 );
437+ XINPUT_VIBRATION * state , prev ;
438+ int xuser = pad_index_to_xuser_index (pad );
441439
442440 if (xuser == -1 )
443441 return false;
444442
445- state = & g_xinput_rumble_states [xuser ];
446- new_state = * state ;
443+ state = & g_xinput_rumble_states [xuser ];
444+ prev = * state ;
447445
448446 /* Consider the low frequency (left) motor the "strong" one. */
449447 if (effect == RETRO_RUMBLE_STRONG )
450- new_state . wLeftMotorSpeed = strength ;
448+ state -> wLeftMotorSpeed = strength ;
451449 else if (effect == RETRO_RUMBLE_WEAK )
452- new_state . wRightMotorSpeed = strength ;
450+ state -> wRightMotorSpeed = strength ;
453451
454452 /* Rumble state unchanged? */
455- if ( (new_state . wLeftMotorSpeed == state -> wLeftMotorSpeed )
456- && (new_state . wRightMotorSpeed == state -> wRightMotorSpeed ))
453+ if ( (state -> wLeftMotorSpeed == prev . wLeftMotorSpeed )
454+ && (state -> wRightMotorSpeed == prev . wRightMotorSpeed ))
457455 return true;
458456
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 )
464- return true;
465-
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-
474- return false;
457+ return g_XInputSetState && (g_XInputSetState (xuser , state ) == ERROR_SUCCESS );
475458}
476459
477460input_device_driver_t xinput_joypad = {
0 commit comments