rnd-20140515-2-src
[rocksndiamonds.git] / src / libgame / joystick.c
index 04731ec8809f7fa64a09c367e0c15628b4c4737c..0966b94934ed68b664acdd71cbc8af2213d09d02 100644 (file)
@@ -1,7 +1,7 @@
 /***********************************************************
 * Artsoft Retro-Game Library                               *
 *----------------------------------------------------------*
-* (c) 1995-2002 Artsoft Entertainment                      *
+* (c) 1995-2006 Artsoft Entertainment                      *
 *               Holger Schemel                             *
 *               Detmolder Strasse 189                      *
 *               33604 Bielefeld                            *
 
 
 /* ========================================================================= */
-/* platform dependant joystick functions                                     */
-/* ========================================================================= */
-
-#if defined(PLATFORM_UNIX) && !defined(TARGET_SDL)
-void UnixInitJoysticks()
-{
-  int i;
-
-  for (i=0; i<MAX_PLAYERS; i++)
-  {
-    char *device_name = setup.input[i].joy.device_name;
-
-    /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
-    if (joystick.fd[i] != -1)
-    {
-      close(joystick.fd[i]);
-      joystick.fd[i] = -1;
-    }
-
-    if (!setup.input[i].use_joystick)
-      continue;
-
-    if (access(device_name, R_OK) != 0)
-    {
-      Error(ERR_WARN, "cannot access joystick device '%s'", device_name);
-      continue;
-    }
-
-    if ((joystick.fd[i] = open(device_name, O_RDONLY)) < 0)
-    {
-      Error(ERR_WARN, "cannot open joystick device '%s'", device_name);
-      continue;
-    }
-
-    joystick.status = JOYSTICK_ACTIVATED;
-  }
-}
-
-boolean UnixReadJoystick(int fd, int *x, int *y, boolean *b1, boolean *b2)
-{
-#if defined(PLATFORM_FREEBSD)
-  struct joystick joy_ctrl;
-#else
-  struct joystick_control
-  {
-    int buttons;
-    int x;
-    int y;
-  } joy_ctrl;
-#endif
-
-  if (read(fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
-    return FALSE;
-
-  if (x != NULL)
-    *x = joy_ctrl.x;
-  if (y != NULL)
-    *y = joy_ctrl.y;
-
-#if defined(PLATFORM_FREEBSD)
-  if (b1 != NULL)
-    *b1 = joy_ctrl.b1;
-  if (b2 != NULL)
-    *b2 = joy_ctrl.b2;
-#else
-  if (b1 != NULL)
-    *b1 = joy_ctrl.buttons & 1;
-  if (b2 != NULL)
-    *b2 = joy_ctrl.buttons & 2;
-#endif
-
-  return TRUE;
-}
-#endif /* PLATFORM_UNIX && !TARGET_SDL */
-
-
-/* ========================================================================= */
-/* platform independant joystick functions                                   */
+/* platform independent joystick functions                                   */
 /* ========================================================================= */
 
 #define TRANSLATE_JOYSYMBOL_TO_JOYNAME 0
@@ -125,7 +48,7 @@ void translate_joyname(int *joysymbol, char **name, int mode)
   {
     *name = "[undefined]";
 
-    for (i=0; i<6; i++)
+    for (i = 0; i < 6; i++)
     {
       if (*joysymbol == translate_joy[i].joysymbol)
       {
@@ -138,9 +61,9 @@ void translate_joyname(int *joysymbol, char **name, int mode)
   {
     *joysymbol = 0;
 
-    for (i=0; i<6; i++)
+    for (i = 0; i < 6; i++)
     {
-      if (strcmp(*name, translate_joy[i].name) == 0)
+      if (strEqual(*name, translate_joy[i].name))
       {
        *joysymbol = translate_joy[i].joysymbol;
        break;
@@ -200,7 +123,7 @@ char *getDeviceNameFromJoystickNr(int joystick_nr)
 
 static int JoystickPositionPercent(int center, int border, int actual)
 {
-  long range, position;
+  int range, position;
   int percent;
 
   if (border < center && actual > center)
@@ -224,7 +147,7 @@ void CheckJoystickData()
   int i;
   int distance = 100;
 
-  for(i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     if (setup.input[i].joy.xleft >= setup.input[i].joy.xmiddle)
       setup.input[i].joy.xleft = setup.input[i].joy.xmiddle - distance;
@@ -317,7 +240,7 @@ int AnyJoystick()
   int i;
   int result = 0;
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
     result |= Joystick(i);
 
   return result;
@@ -326,9 +249,9 @@ int AnyJoystick()
 int AnyJoystickButton()
 {
   int i;
-  int result;
+  int result = JOY_BUTTON_NOT_PRESSED;
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     result = JoystickButton(i);
     if (result != JOY_BUTTON_NOT_PRESSED)
@@ -338,7 +261,7 @@ int AnyJoystickButton()
   return result;
 }
 
-void DeactivateJoystickForCalibration()
+void DeactivateJoystick()
 {
   /* Temporarily deactivate joystick. This is needed for calibration
      screens, where the player has to select a joystick device that
@@ -351,7 +274,7 @@ void DeactivateJoystickForCalibration()
     joystick.status &= ~JOYSTICK_ACTIVE;
 }
 
-void ActivateJoystickIfAvailable()
+void ActivateJoystick()
 {
   /* reactivate temporarily deactivated joystick */