[mupen64plus-input-sdl] 136/196: Use SDL2 to play force feedback effects

Sven Eckelmann ecsv-guest at moszumanska.debian.org
Thu Nov 26 06:00:32 UTC 2015


This is an automated email from the git hooks/post-receive script.

ecsv-guest pushed a commit to branch master
in repository mupen64plus-input-sdl.

commit cd48263409a7c3583995e16c260e3212d61ab059
Author: Sven Eckelmann <sven at narfation.org>
Date:   Wed Jun 12 23:10:49 2013 +0200

    Use SDL2 to play force feedback effects
---
 debian/changelog                        |   1 +
 debian/patches/sdl2_forcefeedback.patch | 242 ++++++++++++++++++++++++++++++++
 debian/patches/series                   |   1 +
 3 files changed, 244 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 4428144..dd32246 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,7 @@ mupen64plus-input-sdl (2.0~rc2+1+9aaeab081d97-2) UNRELEASED; urgency=low
   * debian/patches:
     - Add sdl2_scancodes.patch, Convert predefined SDL1.2 Keycodes to
       SDL2 Scancodes
+    - Add sdl2_forcefeedback.patch, Use SDL2 to play force feedback effects
 
  -- Sven Eckelmann <sven at narfation.org>  Sun, 09 Jun 2013 22:36:16 +0200
 
diff --git a/debian/patches/sdl2_forcefeedback.patch b/debian/patches/sdl2_forcefeedback.patch
new file mode 100644
index 0000000..7cebc9f
--- /dev/null
+++ b/debian/patches/sdl2_forcefeedback.patch
@@ -0,0 +1,242 @@
+Description: Use SDL2 to play force feedback effects
+Author: Sven Eckelmann <sven at narfation.org>
+
+---
+diff --git a/src/plugin.c b/src/plugin.c
+index 8ce635c592f35d774d0ab8fadd25160328d03796..e47d1d4411218aa65a6b6ddb4e458d5b2dcc909a 100644
+--- a/src/plugin.c
++++ b/src/plugin.c
+@@ -111,7 +111,14 @@ static int romopen = 0;         // is a rom opened
+ 
+ static unsigned char myKeyState[SDL_NUM_SCANCODES];
+ 
+-#ifdef __linux__
++#if SDL_VERSION_ATLEAST(2,0,0)
++static SDL_HapticEffect ffeffect[4];
++static int ffeffect_id[4];
++static SDL_HapticEffect ffstrong[4];
++static int ffstrong_id[4];
++static SDL_HapticEffect ffweak[4];
++static int ffweak_id[4];
++#elif __linux__
+ static struct ff_effect ffeffect[3];
+ static struct ff_effect ffstrong[3];
+ static struct ff_effect ffweak[3];
+@@ -402,7 +409,15 @@ EXPORT void CALL ControllerCommand(int Control, unsigned char *Command)
+                 unsigned int dwAddress = (Command[3] << 8) + (Command[4] & 0xE0);
+               if (dwAddress == PAK_IO_RUMBLE && *Data)
+                     DebugMessage(M64MSG_VERBOSE, "Triggering rumble pack.");
+-#ifdef __linux__
++#if SDL_VERSION_ATLEAST(2,0,0)
++                if(dwAddress == PAK_IO_RUMBLE && controller[Control].event_joystick) {
++                    if (*Data) {
++                        SDL_HapticRunEffect(controller[Control].event_joystick, ffeffect_id[Control], 1);
++                    } else {
++                        SDL_HapticStopEffect(controller[Control].event_joystick, ffeffect_id[Control]);
++                    }
++                }
++#elif __linux__
+                 struct input_event play;
+                 if( dwAddress == PAK_IO_RUMBLE && controller[Control].event_joystick != 0)
+                 {
+@@ -617,7 +632,29 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
+     *Keys = controller[Control].buttons;
+ 
+     /* handle mempack / rumblepak switching (only if rumble is active on joystick) */
+-#ifdef __linux__
++#if SDL_VERSION_ATLEAST(2,0,0)
++    if (controller[Control].event_joystick) {
++        static unsigned int SwitchPackTime[4] = {0, 0, 0, 0}, SwitchPackType[4] = {0, 0, 0, 0};
++        if (controller[Control].buttons.Value & button_bits[14]) {
++            SwitchPackTime[Control] = SDL_GetTicks();         // time at which the 'switch pack' command was given
++            SwitchPackType[Control] = PLUGIN_MEMPAK;          // type of new pack to insert
++            controller[Control].control->Plugin = PLUGIN_NONE;// remove old pack
++            SDL_HapticRunEffect(controller[Control].event_joystick, ffweak_id[Control], 1);
++        }
++        if (controller[Control].buttons.Value & button_bits[15]) {
++            SwitchPackTime[Control] = SDL_GetTicks();         // time at which the 'switch pack' command was given
++            SwitchPackType[Control] = PLUGIN_RAW;             // type of new pack to insert
++            controller[Control].control->Plugin = PLUGIN_NONE;// remove old pack
++            SDL_HapticRunEffect(controller[Control].event_joystick, ffstrong_id[Control], 1);
++        }
++        // handle inserting new pack if the time has arrived
++        if (SwitchPackTime[Control] != 0 && (SDL_GetTicks() - SwitchPackTime[Control]) >= 1000)
++        {
++            controller[Control].control->Plugin = SwitchPackType[Control];
++            SwitchPackTime[Control] = 0;
++        }
++    }
++#elif __linux__
+     if (controller[Control].event_joystick != 0)
+     {
+         struct input_event play;
+@@ -657,9 +694,81 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
+     controller[Control].buttons.Value = 0;
+ }
+ 
++static void InitiateJoysticks(int cntrl)
++{
++    // init SDL joystick subsystem
++    if (!SDL_WasInit(SDL_INIT_JOYSTICK))
++        if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) {
++            DebugMessage(M64MSG_ERROR, "Couldn't init SDL joystick subsystem: %s", SDL_GetError() );
++            return;
++        }
++
++    if (controller[cntrl].device >= 0) {
++        controller[cntrl].joystick = SDL_JoystickOpen(controller[cntrl].device);
++        if (!controller[cntrl].joystick)
++            DebugMessage(M64MSG_WARNING, "Couldn't open joystick for controller #%d: %s", cntrl + 1, SDL_GetError());
++    } else {
++        controller[cntrl].joystick = NULL;
++    }
++}
++
++static void DeinitJoystick(int cntrl)
++{
++    if (controller[cntrl].joystick) {
++        SDL_JoystickClose(controller[cntrl].joystick);
++        controller[cntrl].joystick = NULL;
++    }
++}
++
+ static void InitiateRumble(int cntrl)
+ {
+-#ifdef __linux__
++#if SDL_VERSION_ATLEAST(2,0,0)
++    if (!SDL_WasInit(SDL_INIT_HAPTIC)) {
++        if (SDL_InitSubSystem(SDL_INIT_HAPTIC) == -1) {
++            DebugMessage(M64MSG_ERROR, "Couldn't init SDL haptic subsystem: %s", SDL_GetError() );
++            return;
++        }
++    }
++
++    controller[cntrl].event_joystick = SDL_HapticOpenFromJoystick(controller[cntrl].joystick);
++    if (!controller[cntrl].event_joystick) {
++        DebugMessage(M64MSG_WARNING, "Couldn't open rumble support for joystick #%i", cntrl + 1);
++        return;
++    }
++
++    if ((SDL_HapticQuery(controller[cntrl].event_joystick) & SDL_HAPTIC_SINE) == 0) {
++        controller[cntrl].event_joystick = NULL;
++        DebugMessage(M64MSG_WARNING, "Joystick #%i doesn't support sine effect", cntrl + 1);
++        return;
++    }
++
++    memset(&ffeffect[cntrl], 0, sizeof(SDL_HapticEffect));
++    ffeffect[cntrl].type = SDL_HAPTIC_SINE;
++    ffeffect[cntrl].periodic.period = 1000;
++    ffeffect[cntrl].periodic.magnitude = 0x7FFF;
++    // TODO this should have been SDL_HAPTIC_INFINITY but doesnt work with xboxdrv?
++    ffeffect[cntrl].periodic.length = 0x7FFF;
++
++    ffeffect_id[cntrl] = SDL_HapticNewEffect(controller[cntrl].event_joystick, &ffeffect[cntrl]);
++
++    memset(&ffstrong[cntrl], 0, sizeof(SDL_HapticEffect));
++    ffstrong[cntrl].type = SDL_HAPTIC_SINE;
++    ffstrong[cntrl].periodic.period = 1000;
++    ffstrong[cntrl].periodic.magnitude = 0x7FFF;
++    ffstrong[cntrl].periodic.length = 500;
++
++    ffstrong_id[cntrl] = SDL_HapticNewEffect(controller[cntrl].event_joystick, &ffstrong[cntrl]);
++
++    memset(&ffstrong[cntrl], 0, sizeof(SDL_HapticEffect));
++    ffweak[cntrl].type = SDL_HAPTIC_SINE;
++    ffweak[cntrl].periodic.period = 1000;
++    ffweak[cntrl].periodic.magnitude = 0x3FFF;
++    ffweak[cntrl].periodic.length = 500;
++
++    ffweak_id[cntrl] = SDL_HapticNewEffect(controller[cntrl].event_joystick, &ffweak[cntrl]);
++
++    DebugMessage(M64MSG_INFO, "Rumble activated on N64 joystick #%i", cntrl + 1);
++#elif __linux__
+     DIR* dp;
+     struct dirent* ep;
+     unsigned long features[4];
+@@ -760,6 +869,19 @@ static void InitiateRumble(int cntrl)
+ #endif /* __linux__ */
+ }
+ 
++static void DeinitRumble(int cntrl)
++{
++#if SDL_VERSION_ATLEAST(2,0,0)
++    if (controller[cntrl].event_joystick) {
++        SDL_HapticDestroyEffect(controller[cntrl].event_joystick, ffeffect_id[cntrl]);
++        SDL_HapticDestroyEffect(controller[cntrl].event_joystick, ffstrong_id[cntrl]);
++        SDL_HapticDestroyEffect(controller[cntrl].event_joystick, ffweak_id[cntrl]);
++        SDL_HapticClose(controller[cntrl].event_joystick);
++        controller[cntrl].event_joystick = NULL;
++    }
++#endif
++}
++
+ /******************************************************************
+   Function: InitiateControllers
+   Purpose:  This function initialises how each of the controllers
+@@ -790,10 +912,13 @@ EXPORT void CALL InitiateControllers(CONTROL_INFO ControlInfo)
+     for( i = 0; i < 4; i++ )
+     {
+         // test for rumble support for this joystick
++        InitiateJoysticks(i);
+         InitiateRumble(i);
+         // if rumble not supported, switch to mempack
+         if (controller[i].control->Plugin == PLUGIN_RAW && controller[i].event_joystick == 0)
+             controller[i].control->Plugin = PLUGIN_MEMPAK;
++        DeinitRumble(i);
++        DeinitJoystick(i);
+     }
+ 
+     DebugMessage(M64MSG_INFO, "%s version %i.%i.%i initialized.", PLUGIN_NAME, VERSION_PRINTF_SPLIT(PLUGIN_VERSION));
+@@ -830,12 +955,10 @@ EXPORT void CALL RomClosed(void)
+     int i;
+ 
+     // close joysticks
+-    for( i = 0; i < 4; i++ )
+-        if( controller[i].joystick )
+-        {
+-            SDL_JoystickClose( controller[i].joystick );
+-            controller[i].joystick = NULL;
+-        }
++    for( i = 0; i < 4; i++ ) {
++        DeinitRumble(i);
++        DeinitJoystick(i);
++    }
+ 
+     // quit SDL joystick subsystem
+     SDL_QuitSubSystem( SDL_INIT_JOYSTICK );
+@@ -871,15 +994,10 @@ EXPORT int CALL RomOpen(void)
+         }
+ 
+     // open joysticks
+-    for( i = 0; i < 4; i++ )
+-        if( controller[i].device >= 0 )
+-        {
+-            controller[i].joystick = SDL_JoystickOpen( controller[i].device );
+-            if( controller[i].joystick == NULL )
+-                DebugMessage(M64MSG_WARNING, "Couldn't open joystick for controller #%d: %s", i + 1, SDL_GetError() );
+-        }
+-        else
+-            controller[i].joystick = NULL;
++    for (i = 0; i < 4; i++) {
++        InitiateJoysticks(i);
++        InitiateRumble(i);
++    }
+ 
+     // grab mouse
+     if (controller[0].mouse || controller[1].mouse || controller[2].mouse || controller[3].mouse)
+diff --git a/src/plugin.h b/src/plugin.h
+index f5e7bfd32916d650447efd39076eaf0038bea6eb..c55e96bee51f7e5df429f53724d4baa688a624b4 100644
+--- a/src/plugin.h
++++ b/src/plugin.h
+@@ -135,7 +135,11 @@ typedef struct
+     int           device;           // joystick device; -1 = keyboard; -2 = none
+     int           mouse;            // mouse enabled: 0 = no; 1 = yes
+     SDL_Joystick *joystick;         // SDL joystick device
++#if SDL_VERSION_ATLEAST(2,0,0)
++    SDL_Haptic   *event_joystick;   // the sdl device for force feeback
++#else
+     int           event_joystick;   // the /dev/input/eventX device for force feeback
++#endif
+     int           axis_deadzone[2]; // minimum absolute value before analog movement is recognized
+     int           axis_peak[2];     // highest analog value returned by SDL, used for scaling
+     float         mouse_sens[2];    // mouse sensitivity
diff --git a/debian/patches/series b/debian/patches/series
index 994b2da..cb89e5b 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 sdl2_scancodes.patch
+sdl2_forcefeedback.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/mupen64plus-input-sdl.git



More information about the Pkg-games-commits mailing list