rnd-20050724-1-src
[rocksndiamonds.git] / src / libgame / sdl.c
index 1bc222a958c49c227bfc9fa9a6a23bf853cd8a33..b127c7844055152de46fc5f8474abd93c5be1237 100644 (file)
@@ -1440,6 +1440,7 @@ void HandleJoystickEvent(Event *event)
 void SDLInitJoysticks()
 {
   static boolean sdl_joystick_subsystem_initialized = FALSE;
+  boolean print_warning = !sdl_joystick_subsystem_initialized;
   int i;
 
   if (!sdl_joystick_subsystem_initialized)
@@ -1459,11 +1460,19 @@ void SDLInitJoysticks()
     int joystick_nr = getJoystickNrFromDeviceName(device_name);
 
     if (joystick_nr >= SDL_NumJoysticks())
+    {
+      if (setup.input[i].use_joystick && print_warning)
+       Error(ERR_WARN, "cannot find joystick %d", joystick_nr);
+
       joystick_nr = -1;
+    }
 
     /* misuse joystick file descriptor variable to store joystick number */
     joystick.fd[i] = joystick_nr;
 
+    if (joystick_nr == -1)
+      continue;
+
     /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
     if (SDLCheckJoystickOpened(joystick_nr))
       SDLCloseJoystick(joystick_nr);
@@ -1473,7 +1482,9 @@ void SDLInitJoysticks()
 
     if (!SDLOpenJoystick(joystick_nr))
     {
-      Error(ERR_WARN, "cannot open joystick %d", joystick_nr);
+      if (print_warning)
+       Error(ERR_WARN, "cannot open joystick %d", joystick_nr);
+
       continue;
     }