[mupen64plus-input-sdl] 92/196: Imported Upstream version 1.99.5

Sven Eckelmann ecsv-guest at moszumanska.debian.org
Thu Nov 26 06:00:23 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 c83531fc56556456a63ae9510f8f5424bef3b295
Author: Sven Eckelmann <sven at narfation.org>
Date:   Sun Mar 11 11:56:50 2012 +0100

    Imported Upstream version 1.99.5
---
 RELEASE               |  20 ++++
 data/InputAutoCfg.ini | 181 +++++-----------------------
 src/config.c          | 326 +++++++++++++++++++++++++++++++-------------------
 src/config.h          |   2 +
 src/plugin.c          |  18 ++-
 src/version.h         |   4 +-
 6 files changed, 275 insertions(+), 276 deletions(-)

diff --git a/RELEASE b/RELEASE
index 0d80d13..5fa9011 100644
--- a/RELEASE
+++ b/RELEASE
@@ -1,6 +1,26 @@
 SDL Input plugin for Mupen64Plus
 --------------------------------
 
+Mupen64Plus-input-sdl v1.99.5 - March 10, 2012
+-------------------------------------------------
+ - Improved input setup behavior (auto-config) to make some use cases more friendly
+ - Updated input plugin for new Mupen64plus 2.0 API versioning scheme
+ - Added version number to SDL Input plugin parameters
+ - Add new parameter for mouse sensitivity, handle mouse movement differently so mouse is easier to use as controller
+ - New auto-configuration for controllers:
+   - raphnet technologies GC/N64 usb converter
+   - Logitech Chillstream Controller
+   - Jess Tech Colour Rumble
+   - Xbox 360 linux userspace driver
+   - Generic X-Box pad
+   - Saitek P2900 Wireless Pad
+   - Jess Tech USB 4-Axis 12-Button Gamepad
+ - bugfix: #392 - when switching between rumble pak and memory pak, simulate removing the pack, waiting 1 second, then inserting the new one
+ - bugfix: #424 - problem with USB devices supporting multiple controllers per device
+ - bugfix: #409 - PS3 controller not auto-detected in Gentoo when connected via bluetooth
+ - bugfix: correctly handle USB devices with multiple game pads, from Peter Helbing
+ - makefile fixes and improvements
+
 Mupen64Plus-input-sdl v1.99.4 - November 22, 2010
 -------------------------------------------------
  - Bugfix: Do configuration during PluginStart(), so GUI will see defaults (auto-configured) the first time it is run
diff --git a/data/InputAutoCfg.ini b/data/InputAutoCfg.ini
index 2d854b0..8ab3ce7 100644
--- a/data/InputAutoCfg.ini
+++ b/data/InputAutoCfg.ini
@@ -226,6 +226,31 @@ Rumblepak switch =
 X Axis = axis(0-,0+)
 Y Axis = axis(1-,1+)
 
+[Jess Tech USB 4-Axis 12-Button Gamepad]
+plugged = True
+plugin = 2
+mouse = False
+AnalogDeadzone = 4096,4096
+AnalogPeak = 32768,32768
+DPad R = hat(0 Right)
+DPad L = hat(0 Left)
+DPad D = hat(0 Down)
+DPad U = hat(0 Up)
+Start = button(4)
+Z Trig = button(5)
+B Button = button(8)
+A Button = button(9)
+C Button R = button(1)
+C Button L = button(3)
+C Button D = button(2)
+C Button U = button(0)
+R Trig = button(7)
+L Trig = button(6)
+Mempak switch =
+Rumblepak switch =
+X Axis = axis(0-,0+)
+Y Axis = axis(1-,1+)
+
 [Logitech Cordless Rumblepad 2]
 [Logitech RumblePad 2 USB]
 [Logitech Dual Action]
@@ -279,55 +304,12 @@ X Axis = axis(0-,0+)
 Y Axis = axis(1-,1+)
 
 [Microsoft X-Box 360 pad]
-plugged = True
-plugin = 2
-mouse = False
-AnalogDeadzone = 4096,4096
-AnalogPeak = 32768,32768
-DPad R = axis(6+)
-DPad L = axis(6-)
-DPad D = axis(7+)
-DPad U = axis(7-)
-Start = button(6)
-Z Trig = axis(2+)
-B Button = button(2)
-A Button = button(0)
-C Button R = button(1) axis(3+)
-C Button L = axis(3-)
-C Button D = axis(4+)
-C Button U = button(3) axis(4-)
-R Trig = button(5)
-L Trig = button(4)
-Mempak switch = button(9)
-Rumblepak switch = axis(5+)
-X Axis = axis(0-,0+)
-Y Axis = axis(1-,1+)
-
 [Win32: Controller (XBOX 360 For Windows)]
-plugged = True
-plugin = 2
-mouse = False
-AnalogDeadzone = 4096,4096
-AnalogPeak = 32768,32768
-DPad R = hat(0 Right)
-DPad L = hat(0 Left)
-DPad D = hat(0 Down)
-DPad U = hat(0 Up)
-Start = button(7)
-Z Trig = axis(2+)
-B Button = button(2)
-A Button = button(0)
-C Button R = button(1) axis(4+)
-C Button L = axis(4-)
-C Button D = axis(3+)
-C Button U = button(3) axis(3-)
-R Trig = button(5)
-L Trig = button(4)
-Mempak switch = button(9)
-Rumblepak switch = axis(2-)
-X Axis = axis(0-,0+)
-Y Axis = axis(1-,1+)
 [Win32: XBOX 360 For Windows (Controller)]
+[Win32: XBOX 360 For Windows]
+[Xbox 360 Wireless Receiver]
+[OSX: Wireless 360 Controller]
+[Linux: Xbox Gamepad (userspace driver)]
 plugged = True
 plugin = 2
 mouse = False
@@ -338,117 +320,20 @@ DPad L = hat(0 Left)
 DPad D = hat(0 Down)
 DPad U = hat(0 Up)
 Start = button(7)
-Z Trig = axis(2-)
-B Button = button(1)
-A Button = button(0)
-C Button R = axis(4+)
-C Button L = axis(4-)
-C Button D = axis(3+)
-C Button U = axis(3-)
-R Trig = button(5)
-L Trig = button(4)
-Mempak switch = button(6)
-Rumblepak switch = axis(2+)
-X Axis = axis(0-,0+)
-Y Axis = axis(1-,1+)
-[Win32: XBOX 360 For Windows]
-plugged = True
-plugin = 2
-mouse = False
-AnalogDeadzone = 4096,4096
-AnalogPeak = 32768,32768
-DPad R = axis(6+)
-DPad L = axis(6-)
-DPad D = axis(7+)
-DPad U = axis(7-)
-Start = button(7)
-Z Trig = axis(2-)
+Z Trig = axis(2+)
 B Button = button(2)
 A Button = button(0)
 C Button R = axis(4+)
-C Button L = axis(4-)
-C Button D = axis(3+)
+C Button L = axis(4-) button(3)
+C Button D = axis(3+) button(1)
 C Button U = axis(3-)
-R Trig = button(5)
+R Trig = button(5) axis(2-)
 L Trig = button(4)
-Mempak switch = button(8)
-Rumblepak switch = axis(9)
-X Axis = axis(0-,0+)
-Y Axis = axis(1-,1+)
-
-[Xbox 360 Wireless Receiver]
-plugged = True
-plugin = 2
-mouse = False
-AnalogDeadzone = 4096,4096
-AnalogPeak = 32768,32768
-DPad R = button(13)
-DPad L = button(12)
-DPad D = button(11)
-DPad U = button(10)
-Start = button(6)
-Z Trig = button(4)
-B Button = button(2)
-A Button = button(0)
-C Button R = axis(3+)
-C Button L = button(3) axis(3-)
-C Button D = button(1) axis(4+)
-C Button U = axis(4-)
-R Trig = axis(5-)
-L Trig = axis(2-)
 Mempak switch = 
 Rumblepak switch = 
 X Axis = axis(0-,0+)
 Y Axis = axis(1-,1+)
 
-[OSX: Wireless 360 Controller]
-plugged = True
-plugin = 2
-mouse = False
-AnalogDeadzone = 4096,4096
-AnalogPeak = 32768,32768
-DPad R = axis(2+)
-DPad L = axis(2-)
-DPad D = axis(3+)
-DPad U = axis(3-)
-Start = button(4)
-Z Trig = axis(5+)
-B Button = button(13)
-A Button = button(11)
-C Button R = button(3)
-C Button L = button(2)
-C Button D = button(1)
-C Button U = button(0)
-R Trig = button(9)
-L Trig = button(8)
-Mempak switch = 
-Rumblepak switch = 
-X Axis = axis(0-,0+)
-Y Axis = axis(1-,1+)
-
-[Linux: Xbox Gamepad (userspace driver)]
-plugged = True
-plugin = 2
-mouse = False
-DPad R = button(3)
-DPad L = button(2)
-DPad D = button(1)
-DPad U = button(0)
-Start = button(13)
-Z Trig = button(8)
-B Button = button(6)
-A Button = button(4)
-C Button R = axis(2+)
-C Button L = axis(2-)
-C Button D = axis(3+)
-C Button U = axis(3-)
-R Trig = button(9)
-L Trig = button(10)
-Mempak switch =
-Rumblepak switch =
-X Axis = axis(0-,0+)
-Y Axis = axis(1-,1+)
-
 [N64 controller]
 plugged = True
 plugin = 2
diff --git a/src/config.c b/src/config.c
index fc7e873..885c30c 100644
--- a/src/config.c
+++ b/src/config.c
@@ -147,12 +147,20 @@ static const char * get_sdl_joystick_name(int iCtrlIdx)
         return JoyName;
 }
 
-static int load_controller_config(const char *SectionName, int i)
+/////////////////////////////////////
+// load_controller_config()
+// return value: 1 = OK
+//               0 = fail: couldn't open config section
+//              -1 = fail: stored configuration incomplete - missing parameters
+//              -2 = fail: AutoKeyboard stored in mupen64plus.cfg file
+//              -3 = fail: joystick name stored in mupen64plus.cfg doesn't match SDL joystick name for given SDL joystick #
+
+static int load_controller_config(const char *SectionName, int i, int bIsAutoconfig)
 {
     m64p_handle pConfig;
     char input_str[256], value1_str[16], value2_str[16];
     const char *config_ptr;
-    int readOK, j;
+    int j;
 
     /* Open the configuration section for this controller */
     if (ConfigOpenSection(SectionName, &pConfig) != M64ERR_SUCCESS)
@@ -160,108 +168,148 @@ static int load_controller_config(const char *SectionName, int i)
         DebugMessage(M64MSG_ERROR, "Couldn't open config section '%s'", SectionName);
         return 0;
     }
-    /* try to read all of the configuration values */
-    for (readOK = 0; readOK == 0; readOK = 1)
+    /* Check version number, and if it doesn't match: delete the config section and return with error */
+    if (!bIsAutoconfig)
     {
-        /* check for the required parameters */
-        if (ConfigGetParameter(pConfig, "plugged", M64TYPE_BOOL, &controller[i].control->Present, sizeof(int)) != M64ERR_SUCCESS)
-            break;
-        if (ConfigGetParameter(pConfig, "plugin", M64TYPE_INT, &controller[i].control->Plugin, sizeof(int)) != M64ERR_SUCCESS)
-            break;
-        if (ConfigGetParameter(pConfig, "device", M64TYPE_INT, &controller[i].device, sizeof(int)) != M64ERR_SUCCESS)
-            break;
-        /* then do the optional parameters */
-        ConfigGetParameter(pConfig, "mouse", M64TYPE_BOOL, &controller[i].mouse, sizeof(int));
-        if (ConfigGetParameter(pConfig, "MouseSensitivity", M64TYPE_STRING, input_str, 256) == M64ERR_SUCCESS)
+        float fVersion = 0.0f;
+        if (ConfigGetParameter(pConfig, "version", M64TYPE_FLOAT, &fVersion, sizeof(float)) != M64ERR_SUCCESS)
         {
-            if (sscanf(input_str, "%f,%f", &controller[i].mouse_sens[0], &controller[i].mouse_sens[1]) != 2)
-                DebugMessage(M64MSG_WARNING, "parsing error in MouseSensitivity parameter for controller %i", i + 1);
+            ConfigDeleteSection(SectionName);
+            return -1;
         }
-        if (ConfigGetParameter(pConfig, "AnalogDeadzone", M64TYPE_STRING, input_str, 256) == M64ERR_SUCCESS)
+        if (((int) fVersion) != ((int) CONFIG_VERSION))
         {
-            if (sscanf(input_str, "%i,%i", &controller[i].axis_deadzone[0], &controller[i].axis_deadzone[1]) != 2)
-                DebugMessage(M64MSG_WARNING, "parsing error in AnalogDeadzone parameter for controller %i", i + 1);
+            DebugMessage(M64MSG_WARNING, "Incompatible version %.2f in config section '%s': current is %.2f. Clearing.", fVersion, SectionName, (float) CONFIG_VERSION);
+            ConfigDeleteSection(SectionName);
+            return -1;
         }
-        if (ConfigGetParameter(pConfig, "AnalogPeak", M64TYPE_STRING, input_str, 256) == M64ERR_SUCCESS)
+    }
+    /* check for the required parameters */
+    if (ConfigGetParameter(pConfig, "plugged", M64TYPE_BOOL, &controller[i].control->Present, sizeof(int)) != M64ERR_SUCCESS)
+        return -1;
+    if (ConfigGetParameter(pConfig, "plugin", M64TYPE_INT, &controller[i].control->Plugin, sizeof(int)) != M64ERR_SUCCESS)
+        return -1;
+    if (ConfigGetParameter(pConfig, "device", M64TYPE_INT, &controller[i].device, sizeof(int)) != M64ERR_SUCCESS)
+        return -1;
+    /* Name validation only applies to stored configurations (not auto-configs) */
+    if (!bIsAutoconfig)
+    {
+        char device_name[256];
+        if (ConfigGetParameter(pConfig, "name", M64TYPE_STRING, device_name, 256) != M64ERR_SUCCESS)
+            device_name[0] = 0;
+        if (controller[i].device == DEVICE_NOT_JOYSTICK)
         {
-            if (sscanf(input_str, "%i,%i", &controller[i].axis_peak[0], &controller[i].axis_peak[1]) != 2)
-                DebugMessage(M64MSG_WARNING, "parsing error in AnalogPeak parameter for controller %i", i + 1);
+            /* do not load automatically generated keyboard config that was stored to disk (prefer any joysticks attached) */
+            if (strcmp(device_name, "AutoKeyboard") == 0)
+                return -2;
         }
-        /* load configuration for all the digital buttons */
-        for (j = 0; j < X_AXIS; j++)
+        else if (controller[i].device >= 0 && device_name[0] != 0)
         {
-            if (ConfigGetParameter(pConfig, button_names[j], M64TYPE_STRING, input_str, 256) != M64ERR_SUCCESS)
-                continue;
-            if ((config_ptr = strstr(input_str, "key")) != NULL)
-                if (sscanf(config_ptr, "key(%i)", (int *) &controller[i].button[j].key) != 1)
-                    DebugMessage(M64MSG_WARNING, "parsing error in key() parameter of button '%s' for controller %i", button_names[j], i + 1);
-            if ((config_ptr = strstr(input_str, "button")) != NULL)
-                if (sscanf(config_ptr, "button(%i)", &controller[i].button[j].button) != 1)
-                    DebugMessage(M64MSG_WARNING, "parsing error in button() parameter of button '%s' for controller %i", button_names[j], i + 1);
-            if ((config_ptr = strstr(input_str, "axis")) != NULL)
+            /* check that the SDL device name matches the name stored in the config section */
+            const char *sdl_name = get_sdl_joystick_name(controller[i].device);
+            if (sdl_name == NULL || strncmp(device_name, sdl_name, 255) != 0)
             {
-                char chAxisDir;
-                if (sscanf(config_ptr, "axis(%d%c,%d", &controller[i].button[j].axis, &chAxisDir, &controller[i].button[j].axis_deadzone) != 3 &&
-                    sscanf(config_ptr, "axis(%i%c", &controller[i].button[j].axis, &chAxisDir) != 2)
-                    DebugMessage(M64MSG_WARNING, "parsing error in axis() parameter of button '%s' for controller %i", button_names[j], i + 1);
-                controller[i].button[j].axis_dir = (chAxisDir == '+' ? 1 : (chAxisDir == '-' ? -1 : 0));
+                DebugMessage(M64MSG_WARNING, "N64 Controller #%i: SDL joystick name '%s' doesn't match stored configuration name '%s'", i + 1, sdl_name, device_name);
+                return -3;
             }
-            if ((config_ptr = strstr(input_str, "hat")) != NULL)
-            {
-                char *lastchar = NULL;
-                if (sscanf(config_ptr, "hat(%i %15s", &controller[i].button[j].hat, value1_str) != 2)
-                    DebugMessage(M64MSG_WARNING, "parsing error in hat() parameter of button '%s' for controller %i", button_names[j], i + 1);
-                value1_str[15] = 0;
-                /* chop off the last character of value1_str if it is the closing parenthesis */
-                lastchar = &value1_str[strlen(value1_str) - 1];
-                if (lastchar > value1_str && *lastchar == ')') *lastchar = 0;
-                controller[i].button[j].hat_pos = get_hat_pos_by_name(value1_str);
-            }
-            if ((config_ptr = strstr(input_str, "mouse")) != NULL)
-                if (sscanf(config_ptr, "mouse(%i)", &controller[i].button[j].mouse) != 1)
-                    DebugMessage(M64MSG_WARNING, "parsing error in mouse() parameter of button '%s' for controller %i", button_names[j], i + 1);
         }
-        /* load configuration for the 2 analog joystick axes */
-        for (j = X_AXIS; j <= Y_AXIS; j++)
+    }
+    /* then do the optional parameters */
+    ConfigGetParameter(pConfig, "mouse", M64TYPE_BOOL, &controller[i].mouse, sizeof(int));
+    if (ConfigGetParameter(pConfig, "MouseSensitivity", M64TYPE_STRING, input_str, 256) == M64ERR_SUCCESS)
+    {
+        if (sscanf(input_str, "%f,%f", &controller[i].mouse_sens[0], &controller[i].mouse_sens[1]) != 2)
+            DebugMessage(M64MSG_WARNING, "parsing error in MouseSensitivity parameter for controller %i", i + 1);
+    }
+    if (ConfigGetParameter(pConfig, "AnalogDeadzone", M64TYPE_STRING, input_str, 256) == M64ERR_SUCCESS)
+    {
+        if (sscanf(input_str, "%i,%i", &controller[i].axis_deadzone[0], &controller[i].axis_deadzone[1]) != 2)
+            DebugMessage(M64MSG_WARNING, "parsing error in AnalogDeadzone parameter for controller %i", i + 1);
+    }
+    if (ConfigGetParameter(pConfig, "AnalogPeak", M64TYPE_STRING, input_str, 256) == M64ERR_SUCCESS)
+    {
+        if (sscanf(input_str, "%i,%i", &controller[i].axis_peak[0], &controller[i].axis_peak[1]) != 2)
+            DebugMessage(M64MSG_WARNING, "parsing error in AnalogPeak parameter for controller %i", i + 1);
+    }
+    /* load configuration for all the digital buttons */
+    for (j = 0; j < X_AXIS; j++)
+    {
+        if (ConfigGetParameter(pConfig, button_names[j], M64TYPE_STRING, input_str, 256) != M64ERR_SUCCESS)
         {
-            int axis_idx = j - X_AXIS;
-            if (ConfigGetParameter(pConfig, button_names[j], M64TYPE_STRING, input_str, 256) != M64ERR_SUCCESS)
-                continue;
-            if ((config_ptr = strstr(input_str, "key")) != NULL)
-                if (sscanf(config_ptr, "key(%i,%i)", (int *) &controller[i].axis[axis_idx].key_a, (int *) &controller[i].axis[axis_idx].key_b) != 2)
-                    DebugMessage(M64MSG_WARNING, "parsing error in key() parameter of axis '%s' for controller %i", button_names[j], i + 1);
-            if ((config_ptr = strstr(input_str, "button")) != NULL)
-                if (sscanf(config_ptr, "button(%i,%i)", &controller[i].axis[axis_idx].button_a, &controller[i].axis[axis_idx].button_b) != 2)
-                    DebugMessage(M64MSG_WARNING, "parsing error in button() parameter of axis '%s' for controller %i", button_names[j], i + 1);
-            if ((config_ptr = strstr(input_str, "axis")) != NULL)
-            {
-                char chAxisDir1, chAxisDir2;
-                if (sscanf(config_ptr, "axis(%i%c,%i%c)", &controller[i].axis[axis_idx].axis_a, &chAxisDir1,
-                                                          &controller[i].axis[axis_idx].axis_b, &chAxisDir2) != 4)
-                    DebugMessage(M64MSG_WARNING, "parsing error in axis() parameter of axis '%s' for controller %i", button_names[j], i + 1);
-                controller[i].axis[axis_idx].axis_dir_a = (chAxisDir1 == '+' ? 1 : (chAxisDir1 == '-' ? -1 : 0));
-                controller[i].axis[axis_idx].axis_dir_b = (chAxisDir2 == '+' ? 1 : (chAxisDir2 == '-' ? -1 : 0));
-            }
-            if ((config_ptr = strstr(input_str, "hat")) != NULL)
-            {
-                char *lastchar = NULL;
-                if (sscanf(config_ptr, "hat(%i %15s %15s", &controller[i].axis[axis_idx].hat, value1_str, value2_str) != 3)
-                    DebugMessage(M64MSG_WARNING, "parsing error in hat() parameter of axis '%s' for controller %i", button_names[j], i + 1);
-                value1_str[15] = value2_str[15] = 0;
-                /* chop off the last character of value2_str if it is the closing parenthesis */
-                lastchar = &value2_str[strlen(value2_str) - 1];
-                if (lastchar > value2_str && *lastchar == ')') *lastchar = 0;
-                controller[i].axis[axis_idx].hat_pos_a = get_hat_pos_by_name(value1_str);
-                controller[i].axis[axis_idx].hat_pos_b = get_hat_pos_by_name(value2_str);
-            }
+            DebugMessage(M64MSG_WARNING, "missing config key '%s' for controller %i button %i", button_names[j], i+1, j);
+            continue;
+        }
+        if ((config_ptr = strstr(input_str, "key")) != NULL)
+            if (sscanf(config_ptr, "key(%i)", (int *) &controller[i].button[j].key) != 1)
+                DebugMessage(M64MSG_WARNING, "parsing error in key() parameter of button '%s' for controller %i", button_names[j], i + 1);
+        if ((config_ptr = strstr(input_str, "button")) != NULL)
+            if (sscanf(config_ptr, "button(%i)", &controller[i].button[j].button) != 1)
+                DebugMessage(M64MSG_WARNING, "parsing error in button() parameter of button '%s' for controller %i", button_names[j], i + 1);
+        if ((config_ptr = strstr(input_str, "axis")) != NULL)
+        {
+            char chAxisDir;
+            if (sscanf(config_ptr, "axis(%d%c,%d", &controller[i].button[j].axis, &chAxisDir, &controller[i].button[j].axis_deadzone) != 3 &&
+                sscanf(config_ptr, "axis(%i%c", &controller[i].button[j].axis, &chAxisDir) != 2)
+                DebugMessage(M64MSG_WARNING, "parsing error in axis() parameter of button '%s' for controller %i", button_names[j], i + 1);
+            controller[i].button[j].axis_dir = (chAxisDir == '+' ? 1 : (chAxisDir == '-' ? -1 : 0));
+        }
+        if ((config_ptr = strstr(input_str, "hat")) != NULL)
+        {
+            char *lastchar = NULL;
+            if (sscanf(config_ptr, "hat(%i %15s", &controller[i].button[j].hat, value1_str) != 2)
+                DebugMessage(M64MSG_WARNING, "parsing error in hat() parameter of button '%s' for controller %i", button_names[j], i + 1);
+            value1_str[15] = 0;
+            /* chop off the last character of value1_str if it is the closing parenthesis */
+            lastchar = &value1_str[strlen(value1_str) - 1];
+            if (lastchar > value1_str && *lastchar == ')') *lastchar = 0;
+            controller[i].button[j].hat_pos = get_hat_pos_by_name(value1_str);
+        }
+        if ((config_ptr = strstr(input_str, "mouse")) != NULL)
+            if (sscanf(config_ptr, "mouse(%i)", &controller[i].button[j].mouse) != 1)
+                DebugMessage(M64MSG_WARNING, "parsing error in mouse() parameter of button '%s' for controller %i", button_names[j], i + 1);
+    }
+    /* load configuration for the 2 analog joystick axes */
+    for (j = X_AXIS; j <= Y_AXIS; j++)
+    {
+        int axis_idx = j - X_AXIS;
+        if (ConfigGetParameter(pConfig, button_names[j], M64TYPE_STRING, input_str, 256) != M64ERR_SUCCESS)
+        {
+            DebugMessage(M64MSG_WARNING, "missing config key '%s' for controller %i axis %i", button_names[j], i+1, axis_idx);
+            continue;
+        }
+        if ((config_ptr = strstr(input_str, "key")) != NULL)
+            if (sscanf(config_ptr, "key(%i,%i)", (int *) &controller[i].axis[axis_idx].key_a, (int *) &controller[i].axis[axis_idx].key_b) != 2)
+                DebugMessage(M64MSG_WARNING, "parsing error in key() parameter of axis '%s' for controller %i", button_names[j], i + 1);
+        if ((config_ptr = strstr(input_str, "button")) != NULL)
+            if (sscanf(config_ptr, "button(%i,%i)", &controller[i].axis[axis_idx].button_a, &controller[i].axis[axis_idx].button_b) != 2)
+                DebugMessage(M64MSG_WARNING, "parsing error in button() parameter of axis '%s' for controller %i", button_names[j], i + 1);
+        if ((config_ptr = strstr(input_str, "axis")) != NULL)
+        {
+            char chAxisDir1, chAxisDir2;
+            if (sscanf(config_ptr, "axis(%i%c,%i%c)", &controller[i].axis[axis_idx].axis_a, &chAxisDir1,
+                                                      &controller[i].axis[axis_idx].axis_b, &chAxisDir2) != 4)
+                DebugMessage(M64MSG_WARNING, "parsing error in axis() parameter of axis '%s' for controller %i", button_names[j], i + 1);
+            controller[i].axis[axis_idx].axis_dir_a = (chAxisDir1 == '+' ? 1 : (chAxisDir1 == '-' ? -1 : 0));
+            controller[i].axis[axis_idx].axis_dir_b = (chAxisDir2 == '+' ? 1 : (chAxisDir2 == '-' ? -1 : 0));
+        }
+        if ((config_ptr = strstr(input_str, "hat")) != NULL)
+        {
+            char *lastchar = NULL;
+            if (sscanf(config_ptr, "hat(%i %15s %15s", &controller[i].axis[axis_idx].hat, value1_str, value2_str) != 3)
+                DebugMessage(M64MSG_WARNING, "parsing error in hat() parameter of axis '%s' for controller %i", button_names[j], i + 1);
+            value1_str[15] = value2_str[15] = 0;
+            /* chop off the last character of value2_str if it is the closing parenthesis */
+            lastchar = &value2_str[strlen(value2_str) - 1];
+            if (lastchar > value2_str && *lastchar == ')') *lastchar = 0;
+            controller[i].axis[axis_idx].hat_pos_a = get_hat_pos_by_name(value1_str);
+            controller[i].axis[axis_idx].hat_pos_b = get_hat_pos_by_name(value2_str);
         }
     }
 
-    return readOK;
+    return 1;
 }
 
-/* global functions */
-static void save_controller_config(int iCtrlIdx)
+static void save_controller_config(int iCtrlIdx, const char *pccDeviceName)
 {
     m64p_handle pConfig;
     char SectionName[32], Param[32], ParamString[128];
@@ -278,10 +326,12 @@ static void save_controller_config(int iCtrlIdx)
     }
 
     /* save the general controller parameters */
+    ConfigSetDefaultFloat(pConfig, "version", CONFIG_VERSION, "Mupen64Plus SDL Input Plugin config parameter version number.  Please don't change");
     ConfigSetDefaultBool(pConfig, "plugged", controller[iCtrlIdx].control->Present, "Specifies whether this controller is 'plugged in' to the simulated N64");
     ConfigSetDefaultInt(pConfig, "plugin", controller[iCtrlIdx].control->Plugin, "Specifies which type of expansion pak is in the controller: 1=None, 2=Mem pak, 5=Rumble pak");
     ConfigSetDefaultBool(pConfig, "mouse", controller[iCtrlIdx].mouse, "If True, then mouse buttons may be used with this controller");
     ConfigSetDefaultInt(pConfig, "device", controller[iCtrlIdx].device, "Specifies which joystick is bound to this controller: -2=Keyboard/mouse, -1=Auto config, 0 or more= SDL Joystick number");
+    ConfigSetDefaultString(pConfig, "name", pccDeviceName, "SDL joystick name (name check disabled if this is empty string)");
 
     sprintf(Param, "%.2f,%.2f", controller[iCtrlIdx].mouse_sens[0], controller[iCtrlIdx].mouse_sens[1]);
     ConfigSetDefaultString(pConfig, "MouseSensitivity", Param, "Scaling factor for mouse movements.  For X, Y axes.");
@@ -378,6 +428,30 @@ static void save_controller_config(int iCtrlIdx)
 
 }
 
+static void force_controller_keyboard(int n64CtrlIdx)
+{
+    if (n64CtrlIdx < 0 || n64CtrlIdx > 3)
+    {
+        DebugMessage(M64MSG_ERROR, "internal assert in ForceControllerKeyboard.  n64CtrlIdx=%i", n64CtrlIdx);
+        return;
+    }
+
+    DebugMessage(M64MSG_INFO, "N64 Controller #%i: Forcing default keyboard configuration", n64CtrlIdx+1);
+    auto_set_defaults(DEVICE_NOT_JOYSTICK, "Keyboard");
+    if (load_controller_config("AutoConfig0", n64CtrlIdx, 1) > 0)
+    {
+        /* use ConfigSetDefault*() to save this auto-config if config section was empty */
+        save_controller_config(n64CtrlIdx, "AutoKeyboard");
+    }
+    else
+    {
+        DebugMessage(M64MSG_ERROR, "Autoconfig keyboard setup invalid");
+    }
+    ConfigDeleteSection("AutoConfig0");
+}
+
+/* global functions */
+
 /* The reason why the architecture of this config-handling code is so wacky is that it tries to balance
  * several different user scenarios.  From a high-level perspective, it works like this:
  * 1. If there is a valid configuration setup already in the config file, it should not be changed
@@ -399,39 +473,56 @@ void load_configuration(int bPrintSummary)
     const char *JoyName;
     int joy_found = 0, joy_plugged = 0;
     int readOK;
-    int i, j;
+    int n64CtrlIdx, sdlCtrlIdx, j;
 
     /* loop through all 4 simulated N64 controllers */
-    for (i = 0; i < 4; i++)
+    for (n64CtrlIdx=0,sdlCtrlIdx=0; n64CtrlIdx < 4; n64CtrlIdx++)
     {
         /* reset the controller configuration */
-        clear_controller(i);
+        clear_controller(n64CtrlIdx);
         /* try to load the config from the core's configuration api */
-        sprintf(SectionName, "Input-SDL-Control%i", i + 1);
-        readOK = load_controller_config(SectionName, i);
+        sprintf(SectionName, "Input-SDL-Control%i", n64CtrlIdx + 1);
+        readOK = load_controller_config(SectionName, n64CtrlIdx, 0);
 
-        if (!readOK || controller[i].device == DEVICE_AUTO)
+        if (readOK <= 0 || controller[n64CtrlIdx].device == DEVICE_AUTO)
         {
             int ControllersFound = 0;
+            /* make sure that SDL device number hasn't already been used for a different N64 controller */
+            for (j = 0; j < n64CtrlIdx; j++)
+            {
+                if (controller[j].device == sdlCtrlIdx)
+                {
+                    sdlCtrlIdx++;
+                    j = -1;
+                }
+            }
             /* if auto / bad config, get joystick name based on SDL order */
-            JoyName = get_sdl_joystick_name(i);
+            JoyName = get_sdl_joystick_name(sdlCtrlIdx);
             /* reset the controller configuration again and try to auto-configure */
-            ControllersFound = auto_set_defaults(i, JoyName);
-            if (ControllersFound > 0)
+            ControllersFound = auto_set_defaults(sdlCtrlIdx, JoyName);
+            sdlCtrlIdx++;
+            if (ControllersFound == 0)
+            {
+                controller[n64CtrlIdx].device = DEVICE_AUTO;
+                controller[n64CtrlIdx].control->Present = 0;
+                DebugMessage(M64MSG_WARNING, "N64 Controller #%i: Disabled, SDL joystick %i is not available", n64CtrlIdx+1, sdlCtrlIdx-1);
+            }
+            else
             {
                 for (j = 0; j < ControllersFound; j++) /* a USB device may have > 1 controller */
                 {
                     sprintf(SectionName, "AutoConfig%i", j);
-                    if (i + j > 3)
+                    if (n64CtrlIdx + j > 3)
                     {
                         ConfigDeleteSection(SectionName);
                         continue;
                     }
-                    clear_controller(i + j);
-                    if (load_controller_config(SectionName, i + j))
+                    clear_controller(n64CtrlIdx + j);
+                    if (load_controller_config(SectionName, n64CtrlIdx + j, 1) > 0)
                     {
                         /* use ConfigSetDefault*() to save this auto-config if config section was empty */
-                        save_controller_config(i + j);
+                        save_controller_config(n64CtrlIdx + j, JoyName);
+                        DebugMessage(M64MSG_INFO, "N64 Controller #%i: Using auto-config for SDL joystick %i ('%s')", n64CtrlIdx+1, controller[n64CtrlIdx].device, JoyName);
                     }
                     else
                     {
@@ -439,38 +530,38 @@ void load_configuration(int bPrintSummary)
                     }
                     ConfigDeleteSection(SectionName);
                 }
-                i += ControllersFound - 1;
+                n64CtrlIdx += ControllersFound - 1;
                 continue;
             }
         }
-        else if (controller[i].device >= 0)
+        else if (controller[n64CtrlIdx].device >= 0)
         {
             /* if joystick found in cfg, take its SDL number from there */
-            JoyName = get_sdl_joystick_name(controller[i].device);
+            JoyName = get_sdl_joystick_name(controller[n64CtrlIdx].device);
             /* valid joystick configuration was read; check if the specified joystick is available in SDL */
             if (JoyName == NULL)
             {
-                controller[i].device = DEVICE_AUTO;
-                controller[i].control->Present = 0;
-                DebugMessage(M64MSG_INFO, "N64 Controller #%i: Disabled, SDL joystick is not available", i+1);
+                controller[n64CtrlIdx].device = DEVICE_AUTO;
+                controller[n64CtrlIdx].control->Present = 0;
+                DebugMessage(M64MSG_WARNING, "N64 Controller #%i: Disabled, SDL joystick %i is not available", n64CtrlIdx+1, controller[n64CtrlIdx].device);
             }
             else
-                DebugMessage(M64MSG_INFO, "N64 Controller #%i: Using SDL joystick %i ('%s')", i+1, controller[i].device, JoyName);
+                DebugMessage(M64MSG_INFO, "N64 Controller #%i: Using stored config for SDL joystick %i ('%s')", n64CtrlIdx+1, controller[n64CtrlIdx].device, JoyName);
         }
         else /* controller is configured for keyboard/mouse */
         {
-            DebugMessage(M64MSG_INFO, "N64 Controller #%i: Using keyboard/mouse", i+1);
+            DebugMessage(M64MSG_INFO, "N64 Controller #%i: Using keyboard/mouse", n64CtrlIdx+1);
         }
     }
 
     /* see how many joysticks were found */
     joy_found = 0, joy_plugged = 0;
-    for (i = 0; i < 4; i++)
+    for (j = 0; j < 4; j++)
     {
-        if (controller[i].device >= 0 || controller[i].device == DEVICE_NOT_JOYSTICK)
+        if (controller[j].device >= 0 || controller[j].device == DEVICE_NOT_JOYSTICK)
         {
             joy_found++;
-            if (controller[i].control->Present)
+            if (controller[j].control->Present)
                 joy_plugged++;
         }
     }
@@ -478,18 +569,7 @@ void load_configuration(int bPrintSummary)
     /* fallback to keyboard if no joysticks are available and 'plugged in' */
     if (joy_found == 0 || joy_plugged == 0)
     {
-        DebugMessage(M64MSG_INFO, "N64 Controller #1: Forcing default keyboard configuration");
-        auto_set_defaults(DEVICE_NOT_JOYSTICK, "Keyboard");
-        if (load_controller_config("AutoConfig0", 0))
-        {
-            /* use ConfigSetDefault*() to save this auto-config if config section was empty */
-            save_controller_config(0);
-        }
-        else
-        {
-            DebugMessage(M64MSG_ERROR, "Autoconfig keyboard setup invalid");
-        }
-        ConfigDeleteSection("AutoConfig0");
+        force_controller_keyboard(0);
     }
 
     if (bPrintSummary)
diff --git a/src/config.h b/src/config.h
index 48c23f2..2547f24 100644
--- a/src/config.h
+++ b/src/config.h
@@ -22,6 +22,8 @@
 #ifndef __CONFIG_H__
 #define __CONFIG_H__
 
+#define CONFIG_VERSION 1.00
+
 extern void load_configuration(int bPrintSummary);
 
 #endif /* __CONFIG_H__ */
diff --git a/src/plugin.c b/src/plugin.c
index cbdf054..e0bb9f1 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -594,7 +594,7 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
     }
 
 #ifdef _DEBUG
-    DebugMessage(M64MSG_VERBOSE, "Controller #%d value: 0x%8.8X\n", Control, *(int *)&controller[Control].buttons );
+    DebugMessage(M64MSG_VERBOSE, "Controller #%d value: 0x%8.8X", Control, *(int *)&controller[Control].buttons );
 #endif
     *Keys = controller[Control].buttons;
 
@@ -603,9 +603,13 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
     if (controller[Control].event_joystick != 0)
     {
         struct input_event play;
+        static unsigned int SwitchPackTime[4] = {0, 0, 0, 0}, SwitchPackType[4] = {0, 0, 0, 0};
+        // when the user switches packs, we should mimick the act of removing 1 pack, and then inserting another 1 second later
         if (controller[Control].buttons.Value & button_bits[14])
         {
-            controller[Control].control->Plugin = PLUGIN_MEMPAK;
+            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
             play.type = EV_FF;
             play.code = ffweak[Control].id;
             play.value = 1;
@@ -614,13 +618,21 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
         }
         if (controller[Control].buttons.Value & button_bits[15])
         {
-            controller[Control].control->Plugin = PLUGIN_RAW;
+            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
             play.type = EV_FF;
             play.code = ffstrong[Control].id;
             play.value = 1;
             if (write(controller[Control].event_joystick, (const void*) &play, sizeof(play)) == -1)
                 perror("Error starting rumble effect");
         }
+        // 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;
+        }
     }
 #endif /* __linux__ */
 
diff --git a/src/version.h b/src/version.h
index 506e961..5bc2913 100644
--- a/src/version.h
+++ b/src/version.h
@@ -1,7 +1,7 @@
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *   Mupen64plus-input-sdl - version.h                                     *
  *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
- *   Copyright (C) 2009-2011 Richard Goedeken                              *
+ *   Copyright (C) 2009-2012 Richard Goedeken                              *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -27,7 +27,7 @@
 #define VERSION_H
 
 #define PLUGIN_NAME    "Mupen64Plus SDL Input Plugin"
-#define PLUGIN_VERSION           0x016304
+#define PLUGIN_VERSION           0x016305
 #define INPUT_PLUGIN_API_VERSION 0x020000
 #define CONFIG_API_VERSION       0x020000
 

-- 
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