Skip to content

Commit

Permalink
Refactor rumble
Browse files Browse the repository at this point in the history
  • Loading branch information
isage committed Jul 8, 2021
1 parent 5bd182c commit 761d86d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
17 changes: 3 additions & 14 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ bool inputs[INPUT_COUNT];
bool lastinputs[INPUT_COUNT];
in_action last_sdl_action;
SDL_Joystick *joy;
SDL_Haptic *haptic;

int ACCEPT_BUTTON = JUMPKEY;
int DECLINE_BUTTON = FIREKEY;
Expand Down Expand Up @@ -106,7 +105,7 @@ bool input_init(void)
#endif
mappings[ENTERKEY].key = SDLK_RETURN;

SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC);
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
if (SDL_NumJoysticks() > 0)
{
// Open joystick
Expand All @@ -119,16 +118,6 @@ bool input_init(void)
LOG_INFO("Number of Axes: {}", SDL_JoystickNumAxes(joy));
LOG_INFO("Number of Buttons: {}", SDL_JoystickNumButtons(joy));
LOG_INFO("Number of Balls: {}", SDL_JoystickNumBalls(joy));
haptic = SDL_HapticOpenFromJoystick(joy);
if (haptic == NULL)
{
LOG_INFO("No force feedback support");
}
else
{
if (SDL_HapticRumbleInit(haptic) != 0)
LOG_WARN("Coiuldn't init simple rumble");
}
}
else
{
Expand All @@ -140,8 +129,8 @@ bool input_init(void)

void rumble(float str, uint32_t len)
{
if (haptic != NULL && settings->rumble)
SDL_HapticRumblePlay(haptic, str, len);
if (settings->rumble)
SDL_JoystickRumble(joy, 0xFFFF * str, 0xFFFF * str, len);
}

// set the SDL key that triggers an input
Expand Down
1 change: 0 additions & 1 deletion src/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ extern bool inputs[INPUT_COUNT];
extern bool lastinputs[INPUT_COUNT];
extern in_action last_sdl_action;
extern SDL_Joystick *joy;
extern SDL_Haptic *haptic;
extern int ACCEPT_BUTTON;
extern int DECLINE_BUTTON;

Expand Down

0 comments on commit 761d86d

Please sign in to comment.