rnd-20010115-1-src
[rocksndiamonds.git] / src / init.c
index 3b6072741385769f6a1af70943a85d1e2f046a27..9af442484ca33df0fbcc39d9dda7ea3c3627a2df 100644 (file)
@@ -1,7 +1,7 @@
 /***********************************************************
 * Rocks'n'Diamonds -- McDuffin Strikes Back!               *
 *----------------------------------------------------------*
-* (c) 1995-2000 Artsoft Entertainment                      *
+* (c) 1995-2001 Artsoft Entertainment                      *
 *               Holger Schemel                             *
 *               Detmolder Strasse 189                      *
 *               33604 Bielefeld                            *
@@ -11,8 +11,6 @@
 * init.c                                                   *
 ***********************************************************/
 
-#include <signal.h>
-
 #include "libgame/libgame.h"
 
 #include "init.h"
@@ -31,7 +29,6 @@ static void InitPlayerInfo(void);
 static void InitLevelInfo(void);
 static void InitNetworkServer(void);
 static void InitSound(void);
-static void InitSoundServer(void);
 static void InitGfx(void);
 static void InitGfxBackground(void);
 static void InitGadgets(void);
@@ -58,16 +55,15 @@ void OpenAll(void)
 
   InitCounter();
   InitSound();
-  InitSoundServer();
   InitJoysticks();
   InitRND(NEW_RANDOMIZE);
 
-  InitEventFilter(FilterMouseMotionEvents);
-
   InitVideoDisplay();
   InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
                  setup.fullscreen);
 
+  InitEventFilter(FilterMouseMotionEvents);
+
   InitGfx();
   InitElementProperties();     /* initializes IS_CHAR() for el2gfx() */
 
@@ -132,13 +128,11 @@ void InitSound()
 {
   int i;
 
-  OpenAudio(&audio);
-
-  AllocSoundArray(NUM_SOUNDS);
+  OpenAudio();
 
   for(i=0; i<NUM_SOUNDS; i++)
   {
-    if (!LoadSound(i, sound_name[i]))
+    if (!LoadSound(sound_name[i]))
     {
       audio.sound_available = FALSE;
       audio.loops_available = FALSE;
@@ -147,46 +141,10 @@ void InitSound()
       return;
     }
   }
-}
 
-void InitSoundServer()
-{
-  if (!audio.sound_available)
-    return;
+  num_bg_loops = LoadMusic();
 
-#if !defined(TARGET_SDL)
-#if defined(PLATFORM_UNIX)
-
-  if (pipe(audio.soundserver_pipe) < 0)
-  {
-    Error(ERR_WARN, "cannot create pipe - no sounds");
-    audio.sound_available = FALSE;
-    return;
-  }
-
-  if ((audio.soundserver_pid = fork()) < 0)
-  {       
-    Error(ERR_WARN, "cannot create sound server process - no sounds");
-    audio.sound_available = FALSE;
-    return;
-  }
-
-  if (audio.soundserver_pid == 0)      /* we are child */
-  {
-    SoundServer();
-
-    /* never reached */
-    exit(0);
-  }
-  else                                 /* we are parent */
-    close(audio.soundserver_pipe[0]); /* no reading from pipe needed */
-
-#else /* !PLATFORM_UNIX */
-
-  SoundServer();
-
-#endif /* !PLATFORM_UNIX */
-#endif /* !TARGET_SDL */
+  StartSoundserver();
 }
 
 void InitJoysticks()
@@ -341,7 +299,7 @@ void InitGfx()
   }; 
 #endif
 
-#ifdef TARGET_X11
+#if defined(TARGET_X11_NATIVE)
   static struct
   {
     int start;
@@ -433,7 +391,16 @@ void InitGfx()
 
   InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]);
 
+  /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
+  for(i=0; i<NUM_TILES; i++)
+    tile_clipmask[i] = None;
+
 #if defined(TARGET_X11)
+  /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
+     often very slow when preparing a masked XCopyArea() for big Pixmaps.
+     To prevent this, create small (tile-sized) mask Pixmaps which will then
+     be set much faster with XSetClipOrigin() and speed things up a lot. */
+
   /* create graphic context structures needed for clipping */
   clip_gc_values.graphics_exposures = False;
   clip_gc_valuemask = GCGraphicsExposures;
@@ -458,10 +425,7 @@ void InitGfx()
     }
   }
 
-  /* initialize pixmap array to Pixmap 'None' */
-  for(i=0; i<NUM_TILES; i++)
-    tile_clipmask[i] = None;
-
+#if defined(TARGET_X11_NATIVE)
   /* create only those clipping Pixmaps we really need */
   for(i=0; tile_needs_clipping[i].start>=0; i++)
   {
@@ -485,6 +449,7 @@ void InitGfx()
                src_x, src_y, TILEX, TILEY, 0, 0);
     }
   }
+#endif /* TARGET_X11_NATIVE */
 #endif /* TARGET_X11 */
 }
 
@@ -1670,17 +1635,10 @@ void CloseAllAndExit(int exit_value)
 
   StopSounds();
   FreeSounds(NUM_SOUNDS);
-
-#if !defined(TARGET_SDL)
-  if (audio.soundserver_pid)
-    kill(audio.soundserver_pid, SIGTERM);
-#endif
+  CloseAudio();
 
   for(i=0; i<NUM_BITMAPS; i++)
     FreeBitmap(pix[i]);
-
-  KeyboardAutoRepeatOn();
-
   CloseVideoDisplay();
 
   ClosePlatformDependantStuff();