- added config options for joystick buttons/axis
authorIngo Ruhnke <grumbel@gmx.de>
Tue, 20 Apr 2004 16:50:18 +0000 (16:50 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Tue, 20 Apr 2004 16:50:18 +0000 (16:50 +0000)
SVN-Revision: 594

src/configfile.cpp
src/globals.cpp
src/setup.cpp

index 514c249..c415d13 100644 (file)
@@ -90,6 +90,13 @@ void loadconfig(void)
     use_joystick = false;
   else
     use_joystick = true;
+
+  reader.read_int ("joystick-x", &joystick_keymap.x_axis);
+  reader.read_int ("joystick-y", &joystick_keymap.y_axis);
+  reader.read_int ("joystick-a", &joystick_keymap.a_button);
+  reader.read_int ("joystick-b", &joystick_keymap.b_button);
+  reader.read_int ("joystick-start", &joystick_keymap.start_button);
+  reader.read_int ("joystick-deadzone", &joystick_keymap.dead_zone);
 }
 
 void saveconfig (void)
@@ -112,6 +119,14 @@ void saveconfig (void)
 
       fprintf(config, "\n\t;; joystick number (-1 means no joystick):\n");
       fprintf(config, "\t(joystick   %d)\n", use_joystick ? joystick_num : -1);
+
+      fprintf(config, "\t(joystick-x   %d)\n", joystick_keymap.x_axis);
+      fprintf(config, "\t(joystick-y   %d)\n", joystick_keymap.y_axis);
+      fprintf(config, "\t(joystick-a   %d)\n", joystick_keymap.a_button);
+      fprintf(config, "\t(joystick-b   %d)\n", joystick_keymap.b_button);
+      fprintf(config, "\t(joystick-start  %d)\n", joystick_keymap.start_button);
+      fprintf(config, "\t(joystick-deadzone  %d)\n", joystick_keymap.dead_zone);
+
       fprintf(config, ")\n");
     }
 }
index 5809b4b..50cab21 100644 (file)
@@ -27,7 +27,7 @@ JoystickKeymap::JoystickKeymap()
 {
   a_button     = 0;
   b_button     = 1;
-  start_button = 9;
+  start_button = 2;
   
   x_axis = 0;
   y_axis = 1;
index 26fdba3..ab73581 100644 (file)
@@ -762,8 +762,6 @@ void st_joystick_setup(void)
             }
           else
             {
-              /* Check for proper joystick configuration: */
-
               if (SDL_JoystickNumAxes(js) < 2)
                 {
                   fprintf(stderr,
@@ -927,6 +925,29 @@ void parseargs(int argc, char * argv[])
           assert(i+1 < argc);
           joystick_num = atoi(argv[++i]);
         }
+      else if (strcmp(argv[i], "--joymap") == 0)
+        {
+          assert(i+1 < argc);
+          if (sscanf(argv[++i],
+                     "%d:%d:%d:%d:%d", 
+                     &joystick_keymap.x_axis, 
+                     &joystick_keymap.y_axis, 
+                     &joystick_keymap.a_button, 
+                     &joystick_keymap.b_button, 
+                     &joystick_keymap.start_button) != 5)
+            {
+              puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'");
+            }
+          else
+            {
+              std::cout << "Using new joymap:\n"
+                        << "  X-Axis:       " << joystick_keymap.x_axis << "\n"
+                        << "  Y-Axis:       " << joystick_keymap.y_axis << "\n"
+                        << "  A-Button:     " << joystick_keymap.a_button << "\n"
+                        << "  B-Button:     " << joystick_keymap.b_button << "\n"
+                        << "  Start-Button: " << joystick_keymap.start_button << std::endl;
+            }
+        }
       else if (strcmp(argv[i], "--worldmap") == 0)
         {
           launch_worldmap_mode = true;
@@ -1004,6 +1025,8 @@ void parseargs(int argc, char * argv[])
                "\n"
                "Misc Options:\n"
                "  -j, --joystick NUM  Use joystick NUM (default: 0)\n" 
+               "  --joymap XAXIS:YAXIS:A:B:START\n"
+               "                      Define how joystick buttons and axis should be mapped\n"
                "  --worldmap          Start in worldmap-mode (EXPERIMENTAL)\n"          
                "  -d, --datadir DIR   Load Game data from DIR (default: automatic)\n"
                "  --debug-mode        Enables the debug-mode, which is useful for developers.\n"