Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- old/Joystick_SDL.cpp 2013-08-31 23:33:41.000000000 +0200
- +++ new/Joystick_SDL.cpp 2015-09-08 10:58:41.000000000 +0200
- @@ -31,11 +31,14 @@
- ~Joystick_SDL();
- void UpdateInternal(void);
- +
- + virtual void SetRumble(uint8 weak_intensity, uint8 strong_intensity);
- virtual unsigned HatToButtonCompat(unsigned hat);
- private:
- SDL_Joystick *sdl_joy;
- + SDL_Haptic *sdl_haptic;
- unsigned sdl_num_axes;
- unsigned sdl_num_hats;
- unsigned sdl_num_balls;
- @@ -47,6 +50,32 @@
- return(sdl_num_buttons + (hat * 4));
- }
- +void Joystick_SDL::SetRumble(uint8 weak_intensity, uint8 strong_intensity)
- +{
- + if (sdl_haptic == NULL) {
- + return;
- + }
- +
- + static int effectID = -1;
- +
- + float intensity = 0.3 * weak_intensity + 0.7 * strong_intensity;
- +
- + if (effectID != -1) {
- + SDL_HapticDestroyEffect(sdl_haptic, effectID);
- + effectID = -1;
- + }
- +
- + if (intensity > 0) {
- + SDL_HapticEffect effect;
- + memset( &effect, 0, sizeof(SDL_HapticEffect) );
- + effect.type = SDL_HAPTIC_CONSTANT;
- + effect.constant.length = SDL_HAPTIC_INFINITY;
- + effect.constant.level = intensity / 255.0 * 32767;
- + effectID = SDL_HapticNewEffect(sdl_haptic, &effect);
- + SDL_HapticRunEffect(sdl_haptic, effectID, SDL_HAPTIC_INFINITY);
- + }
- +}
- +
- Joystick_SDL::Joystick_SDL(unsigned index) : sdl_joy(NULL)
- {
- sdl_joy = SDL_JoystickOpen(index);
- @@ -72,10 +101,21 @@
- axis_state.resize(num_axes);
- rel_axis_state.resize(num_rel_axes);
- button_state.resize(num_buttons);
- +
- + sdl_haptic = SDL_HapticOpenFromJoystick(sdl_joy);
- + if (sdl_haptic != NULL && (SDL_HapticQuery(sdl_haptic) & SDL_HAPTIC_CONSTANT)) {
- + MDFNI_printf("Rumble supported by: %s", name);
- + } else {
- + sdl_haptic = NULL;
- + }
- }
- Joystick_SDL::~Joystick_SDL()
- {
- + if (sdl_haptic) {
- + SDL_HapticClose(sdl_haptic);
- + sdl_haptic = NULL;
- + }
- if(sdl_joy)
- {
- SDL_JoystickClose(sdl_joy);
- @@ -136,7 +176,7 @@
- JoystickDriver_SDL::JoystickDriver_SDL()
- {
- - SDL_InitSubSystem(SDL_INIT_JOYSTICK);
- + SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC);
- for(int n = 0; n < SDL_NumJoysticks(); n++)
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement