rnd-20001128-1-src
[rocksndiamonds.git] / src / init.c
index a8ce6a50bc357ce2dde3cede3b3535b47224973e..60e0bcd3c22fd6135785dca3291bcc050e787e2f 100644 (file)
@@ -35,10 +35,6 @@ struct PictureFileInfo
   boolean picture_with_mask;
 };
 
-#ifndef USE_SDL_LIBRARY
-static int sound_process_id = 0;
-#endif
-
 static void InitPlayerInfo(void);
 static void InitLevelInfo(void);
 static void InitNetworkServer(void);
@@ -52,16 +48,16 @@ static void InitElementProperties(void);
 
 void OpenAll(int argc, char *argv[])
 {
-#if defined(MSDOS) || defined(WIN32)
+#if !defined(PLATFORM_UNIX)
   initErrorFile();
 #endif
 
   if (options.serveronly)
   {
-#ifdef WIN32
-    Error(ERR_WARN, "networking not supported in Windows version");
-#else
+#if defined(PLATFORM_UNIX)
     NetworkServer(options.server_port, options.serveronly);
+#else
+    Error(ERR_WARN, "networking not supported in Windows version");
 #endif
 
     /* never reached */
@@ -121,14 +117,14 @@ void InitLevelInfo()
 
 void InitNetworkServer()
 {
-#if !defined(MSDOS) && !defined(WIN32)
+#if defined(PLATFORM_UNIX)
   int nr_wanted;
 #endif
 
   if (!options.network)
     return;
 
-#if !defined(MSDOS) && !defined(WIN32)
+#if defined(PLATFORM_UNIX)
   nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
 
   if (!ConnectToServer(options.server_host, options.server_port))
@@ -146,69 +142,35 @@ void InitSound()
 {
   int i;
 
-  if (sound_status == SOUND_OFF)
-    return;
-
-#ifdef USE_SDL_LIBRARY
-  /* initialize SDL audio */
-
-  if (SDL_Init(SDL_INIT_AUDIO) < 0)
-  {
-    Error(ERR_WARN, "SDL_Init() failed: %s", SDL_GetError());
-    sound_status = SOUND_OFF;
+  /* REMOVE THIS! (gone to system.c:InitAudio) */
+  if (!sysinfo.audio_available)
     return;
-  }
 
-  if (Mix_OpenAudio(22050, AUDIO_S16, 2, 512) < 0)
+#if defined(TARGET_SDL)
+  if (InitAudio())
   {
-    Error(ERR_WARN, "Mix_OpenAudio() failed: %s", SDL_GetError());
-    sound_status = SOUND_OFF;
-    return;
+    sysinfo.audio_available = TRUE;
+    sysinfo.audio_loops_available = TRUE;
   }
-
-  Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4);
-  Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4);
-
-  sound_status = SOUND_AVAILABLE;
-  sound_loops_allowed = TRUE;
-
-#else /* !USE_SDL_LIBRARY */
-
-#if !defined(MSDOS) && !defined(WIN32)
-  if (access(sound_device_name, W_OK) != 0)
+  else
   {
-    Error(ERR_WARN, "cannot access sound device - no sounds");
-    sound_status = SOUND_OFF;
-    return;
+    sysinfo.audio_available = FALSE;
   }
+#else /* !TARGET_SDL */
 
-  if ((sound_device = OpenAudio(sound_device_name)) < 0)
-  {
-    Error(ERR_WARN, "cannot open sound device - no sounds");
-    sound_status = SOUND_OFF;
+#if defined(PLATFORM_UNIX)
+  if (!(sysinfo.audio_available = CheckAudio(sound_device_name)))
     return;
-  }
-
-  close(sound_device);
-  sound_status = SOUND_AVAILABLE;
 
 #ifdef VOXWARE
-  sound_loops_allowed = TRUE;
-
-  /*
-  setup.sound_loops_on = TRUE;
-  */
-
+  sysinfo.audio_loops_available = TRUE;
 #endif
-#else /* MSDOS || WIN32 */
-  sound_loops_allowed = TRUE;
 
-  /*
-  setup.sound_loops_on = TRUE;
-  */
+#else /* !PLATFORM_UNIX */
+  sysinfo.audio_loops_available = TRUE;
 
-#endif /* MSDOS || WIN32 */
-#endif /* !USE_SDL_LIBRARY */
+#endif /* !PLATFORM_UNIX */
+#endif /* !TARGET_SDL */
 
   for(i=0; i<NUM_SOUNDS; i++)
   {
@@ -216,63 +178,56 @@ void InitSound()
 
     if (!LoadSound(&Sound[i]))
     {
-      sound_status = SOUND_OFF;
-      sound_loops_allowed = FALSE;
+      sysinfo.audio_available = FALSE;
+      sysinfo.audio_loops_available = FALSE;
       return;
     }
   }
-
-#if 0
-  sound_status = SOUND_OFF;
-#endif
-
 }
 
 void InitSoundServer()
 {
-  if (sound_status == SOUND_OFF)
+  if (!sysinfo.audio_available)
     return;
 
-#ifndef USE_SDL_LIBRARY
-
-#if !defined(MSDOS) && !defined(WIN32)
+#if !defined(TARGET_SDL)
+#if defined(PLATFORM_UNIX)
 
-  if (pipe(sound_pipe)<0)
+  if (pipe(sysinfo.audio_process_pipe) < 0)
   {
     Error(ERR_WARN, "cannot create pipe - no sounds");
-    sound_status = SOUND_OFF;
+    sysinfo.audio_available = FALSE;
     return;
   }
 
-  if ((sound_process_id = fork()) < 0)
+  if ((sysinfo.audio_process_id = fork()) < 0)
   {       
     Error(ERR_WARN, "cannot create sound server process - no sounds");
-    sound_status = SOUND_OFF;
+    sysinfo.audio_available = FALSE;
     return;
   }
 
-  if (!sound_process_id)       /* we are child */
+  if (!sysinfo.audio_process_id)       /* we are child */
   {
     SoundServer();
 
     /* never reached */
     exit(0);
   }
-  else                         /* we are parent */
-    close(sound_pipe[0]);      /* no reading from pipe needed */
+  else                                 /* we are parent */
+    close(sysinfo.audio_process_pipe[0]); /* no reading from pipe needed */
 
-#else /* MSDOS || WIN32 */
+#else /* !PLATFORM_UNIX */
 
   SoundServer();
 
-#endif /* MSDOS */
-
-#endif /* !USE_SDL_LIBRARY */
+#endif /* !PLATFORM_UNIX */
+#endif /* !TARGET_SDL */
 }
 
 void InitJoysticks()
 {
-#ifdef USE_SDL_JOYSTICK
+#if defined(TARGET_SDL)
   static boolean sdl_joystick_subsystem_initialized = FALSE;
 #endif
 
@@ -283,7 +238,7 @@ void InitJoysticks()
 
   joystick_status = JOYSTICK_OFF;
 
-#ifdef USE_SDL_JOYSTICK
+#if defined(TARGET_SDL)
 
   if (!sdl_joystick_subsystem_initialized)
   {
@@ -323,9 +278,9 @@ void InitJoysticks()
     joystick_status = JOYSTICK_AVAILABLE;
   }
 
-#else /* !USE_SDL_JOYSTICK */
+#else /* !TARGET_SDL */
 
-#ifndef MSDOS
+#if defined(PLATFORM_UNIX)
   for (i=0; i<MAX_PLAYERS; i++)
   {
     char *device_name = setup.input[i].joy.device_name;
@@ -355,7 +310,7 @@ void InitJoysticks()
     joystick_status = JOYSTICK_AVAILABLE;
   }
 
-#else /* MSDOS */
+#else /* !PLATFORM_UNIX */
 
   /* try to access two joysticks; if that fails, try to access just one */
   if (install_joystick(JOY_TYPE_2PADS) == 0 ||
@@ -379,14 +334,14 @@ void InitJoysticks()
   }
 #endif
 
-#endif /* !USE_SDL_LIBRARY */
+#endif /* !TARGET_SDL */
 }
 
 void InitGfx()
 {
   int i, j;
 
-#ifdef USE_SDL_LIBRARY
+#if defined(TARGET_SDL)
   SDL_Surface *sdl_image_tmp;
 #else
   GC copy_clipmask_gc;
@@ -394,21 +349,7 @@ void InitGfx()
   unsigned long clip_gc_valuemask;
 #endif
 
-#ifdef MSDOS
-  static struct PictureFileInfo pic[NUM_PICTURES] =
-  {
-    { "Screen",        TRUE },
-    { "Door",  TRUE },
-    { "Heroes",        TRUE },
-    { "Toons", TRUE },
-    { "SP",    TRUE },
-    { "DC",    TRUE },
-    { "More",  TRUE },
-    { "Font",  FALSE },
-    { "Font2", FALSE },
-    { "Font3", FALSE }
-  }; 
-#else
+#if !defined(PLATFORM_MSDOS)
   static struct PictureFileInfo pic[NUM_PICTURES] =
   {
     { "RocksScreen",   TRUE },
@@ -422,6 +363,20 @@ void InitGfx()
     { "RocksFont2",    FALSE },
     { "RocksFont3",    FALSE }
   }; 
+#else
+  static struct PictureFileInfo pic[NUM_PICTURES] =
+  {
+    { "Screen",        TRUE },
+    { "Door",  TRUE },
+    { "Heroes",        TRUE },
+    { "Toons", TRUE },
+    { "SP",    TRUE },
+    { "DC",    TRUE },
+    { "More",  TRUE },
+    { "Font",  FALSE },
+    { "Font2", FALSE },
+    { "Font3", FALSE }
+  }; 
 #endif
 
   static struct
@@ -484,10 +439,10 @@ void InitGfx()
   LoadGfx(PIX_SMALLFONT, &pic[PIX_SMALLFONT]);
   DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
   DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
-#ifdef MSDOS
+#if defined(PLATFORM_MSDOS)
   DrawInitText(PROGRAM_DOS_PORT_STRING, 210, FC_BLUE);
   rest(200);
-#endif /* MSDOS */
+#endif
   DrawInitText("Loading graphics:",120,FC_GREEN);
 
   for(i=0; i<NUM_PICTURES; i++)
@@ -496,7 +451,7 @@ void InitGfx()
 
   /* create additional image buffers for masking of graphics */
 
-#ifdef USE_SDL_LIBRARY
+#if defined(TARGET_SDL)
 
   /* initialize surface array to 'NULL' */
   for(i=0; i<NUM_TILES; i++)
@@ -534,7 +489,7 @@ void InitGfx()
     }
   }
 
-#else /* !USE_SDL_LIBRARY */
+#else /* !TARGET_SDL */
 
   /* create graphic context structures needed for clipping */
   clip_gc_values.graphics_exposures = False;
@@ -583,7 +538,7 @@ void InitGfx()
     }
   }
 
-#endif /* !USE_SDL_LIBRARY */
+#endif /* !TARGET_SDL */
 }
 
 void InitGfxBackground()
@@ -610,11 +565,11 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
   char basefilename[256];
   char filename[256];
 
-#ifdef USE_SDL_LIBRARY
+#if defined(TARGET_SDL)
   SDL_Surface *sdl_image_tmp;
-#else /* !USE_SDL_LIBRARY */
+#else
   int pcx_err;
-#endif /* !USE_SDL_LIBRARY */
+#endif
   char *picture_ext = ".pcx";
 
   /* Grafik laden */
@@ -625,11 +580,11 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
     sprintf(filename, "%s/%s/%s",
            options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename);
 
-#ifdef MSDOS
+#if defined(PLATFORM_MSDOS)
     rest(100);
-#endif /* MSDOS */
+#endif
 
-#ifdef USE_SDL_LIBRARY
+#if defined(TARGET_SDL)
     /* load image to temporary surface */
     if ((sdl_image_tmp = IMG_Load(filename)) == NULL)
       Error(ERR_EXIT, "IMG_Load() failed: %s", SDL_GetError());
@@ -647,7 +602,7 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
     /* free temporary surface */
     SDL_FreeSurface(sdl_image_tmp);
 
-#else /* !USE_SDL_LIBRARY */
+#else /* !TARGET_SDL */
 
     pcx_err = Read_PCX_to_Pixmap(display, window, gc, filename,
                                 &pix[pos], &clipmask[pos]);
@@ -676,14 +631,14 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
        use pix_masked[], although they are the same when not using SDL */
     pix_masked[pos] = pix[pos];
 
-#endif /* !USE_SDL_LIBRARY */
+#endif /* !TARGET_SDL */
   }
 
-#ifndef USE_SDL_LIBRARY
-  /* zugehörige Maske laden (wenn vorhanden) */
+#if defined(TARGET_X11)
+  /* check if clip mask was correctly created */
   if (pic->picture_with_mask && !clipmask[pos])
     Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename);
-#endif /* !USE_SDL_LIBRARY */
+#endif
 }
 
 void InitGadgets()
@@ -1847,14 +1802,14 @@ void CloseAllAndExit(int exit_value)
 {
   int i;
 
-#ifdef USE_SDL_LIBRARY
+#if defined(TARGET_SDL)
   StopSounds();
   FreeSounds(NUM_SOUNDS);
 #else
-  if (sound_process_id)
+  if (sysinfo.audio_process_id)
   {
     StopSounds();
-    kill(sound_process_id, SIGTERM);
+    kill(sysinfo.audio_process_id, SIGTERM);
     FreeSounds(NUM_SOUNDS);
   }
 #endif
@@ -1864,7 +1819,7 @@ void CloseAllAndExit(int exit_value)
     if (pix[i])
       FreeBitmap(pix[i]);
 
-#ifdef USE_SDL_LIBRARY
+#if defined(TARGET_SDL)
     FreeBitmap(pix_masked[i]);
 #else
     if (clipmask[i])
@@ -1874,7 +1829,7 @@ void CloseAllAndExit(int exit_value)
 #endif
   }
 
-#ifdef USE_SDL_LIBRARY
+#if defined(TARGET_SDL)
   KeyboardAutoRepeatOn();
 #else
   if (gc)
@@ -1887,7 +1842,7 @@ void CloseAllAndExit(int exit_value)
   }
 #endif
 
-#if defined(MSDOS) || defined(WIN32)
+#if !defined(PLATFORM_UNIX)
   dumpErrorFile();
 #endif