Skip to content

Commit f51a69e

Browse files
committed
Remove interval for XInput rumbles
1 parent 053ced8 commit f51a69e

File tree

2 files changed

+17
-52
lines changed

2 files changed

+17
-52
lines changed

input/drivers_joypad/xinput_hybrid_joypad.c

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <stdlib.h>
3232
#include <stddef.h>
3333
#include <string.h>
34-
#include <time.h>
3534

3635
#include <boolean.h>
3736
#include <retro_inline.h>
@@ -69,8 +68,6 @@ typedef struct
6968
bool connected;
7069
} xinput_joypad_state;
7170

72-
#define RUMBLE_INTERVAL 0.005
73-
7471
/* TODO/FIXME - static globals */
7572
static int g_xinput_pad_indexes[MAX_USERS];
7673
static unsigned g_last_xinput_pad_idx = 0;
@@ -94,7 +91,6 @@ static XINPUT_VIBRATION g_xinput_rumble_states[4];
9491
#endif
9592
static xinput_joypad_state g_xinput_states[4];
9693
static bool xinput_active_port[4] = {0};
97-
static clock_t last_rumble_time[4] = {0};
9894

9995
static unsigned xinput_hotplug_index = 0;
10096
static unsigned xinput_poll_counter = 0;
@@ -714,42 +710,29 @@ static void xinput_joypad_poll(void)
714710
static bool xinput_joypad_rumble(unsigned pad,
715711
enum retro_rumble_effect effect, uint16_t strength)
716712
{
717-
clock_t now;
718-
double time_since_last_rumble;
719-
XINPUT_VIBRATION new_state, *state;
713+
XINPUT_VIBRATION *state, prev;
720714
int xuser = PAD_INDEX_TO_XUSER_INDEX(pad);
721715

722716
if (xuser == -1)
723717
return dinput_joypad_set_rumble(pad, effect, strength);
724718

725-
state = &g_xinput_rumble_states[xuser];
726-
new_state = *state;
719+
state = &g_xinput_rumble_states[xuser];
720+
prev = *state;
727721

728722
/* Consider the low frequency (left) motor the "strong" one. */
729723
if (effect == RETRO_RUMBLE_STRONG)
730-
new_state.wLeftMotorSpeed = strength;
724+
state->wLeftMotorSpeed = strength;
731725
else if (effect == RETRO_RUMBLE_WEAK)
732-
new_state.wRightMotorSpeed = strength;
726+
state->wRightMotorSpeed = strength;
733727

734728
/* Rumble state unchanged? */
735-
if ( (new_state.wLeftMotorSpeed == state->wLeftMotorSpeed)
736-
&& (new_state.wRightMotorSpeed == state->wRightMotorSpeed))
729+
if ( (state->wLeftMotorSpeed == prev.wLeftMotorSpeed)
730+
&& (state->wRightMotorSpeed == prev.wRightMotorSpeed))
737731
return true;
738732

739-
now = clock();
740-
time_since_last_rumble = (double)(now - last_rumble_time[xuser]) / CLOCKS_PER_SEC;
741-
742-
/* Rumble interval unelapsed? */
743-
if (time_since_last_rumble < RUMBLE_INTERVAL)
733+
if (g_XInputSetState && (g_XInputSetState(xuser, state) == ERROR_SUCCESS))
744734
return true;
745735

746-
if (g_XInputSetState)
747-
{
748-
*state = new_state;
749-
last_rumble_time[xuser] = now;
750-
if (g_XInputSetState(xuser, state) == ERROR_SUCCESS)
751-
return true;
752-
}
753736
return false;
754737
}
755738

input/drivers_joypad/xinput_joypad.c

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
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 */
5855
typedef uint32_t (__stdcall *XInputGetStateEx_t)(uint32_t, XINPUT_STATE*);
5956
typedef uint32_t (__stdcall *XInputSetState_t)(uint32_t, XINPUT_VIBRATION*);
@@ -75,7 +72,6 @@ static XINPUT_VIBRATION g_xinput_rumble_states[4];
7572
#endif
7673
static xinput_joypad_state g_xinput_states[4];
7774
static bool xinput_active_port[4] = {0};
78-
static clock_t last_rumble_time[4] = {0};
7975

8076
static unsigned xinput_hotplug_index = 0;
8177
static unsigned xinput_poll_counter = 0;
@@ -434,43 +430,29 @@ if (!xinput_active_port[i] && has_active_ports)
434430
static 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

Comments
 (0)