rnd-20001202-2-src
[rocksndiamonds.git] / src / init.c
index 60e0bcd3c22fd6135785dca3291bcc050e787e2f..3a0c54ed7bfcc69500e138dba69ba5046b8a1fed 100644 (file)
 
 #include <signal.h>
 
+#include "libgame/libgame.h"
+
 #include "init.h"
 #include "events.h"
-#include "misc.h"
-#include "sound.h"
 #include "screens.h"
 #include "editor.h"
 #include "game.h"
@@ -24,8 +24,6 @@
 #include "tools.h"
 #include "files.h"
 #include "joystick.h"
-#include "image.h"
-#include "pcx.h"
 #include "network.h"
 #include "netserv.h"
 
@@ -40,6 +38,7 @@ static void InitLevelInfo(void);
 static void InitNetworkServer(void);
 static void InitSound(void);
 static void InitSoundServer(void);
+static void InitDisplay(void);
 static void InitGfx(void);
 static void InitGfxBackground(void);
 static void LoadGfx(int, struct PictureFileInfo *);
@@ -75,7 +74,7 @@ void OpenAll(int argc, char *argv[])
   signal(SIGINT, CloseAllAndExit);
   signal(SIGTERM, CloseAllAndExit);
 
-  InitBufferedDisplay(&backbuffer, &window);
+  InitDisplay();
   InitEventFilter(FilterMouseMotionEvents);
 
   InitGfx();
@@ -142,35 +141,7 @@ void InitSound()
 {
   int i;
 
-  /* REMOVE THIS! (gone to system.c:InitAudio) */
-  if (!sysinfo.audio_available)
-    return;
-
-#if defined(TARGET_SDL)
-  if (InitAudio())
-  {
-    sysinfo.audio_available = TRUE;
-    sysinfo.audio_loops_available = TRUE;
-  }
-  else
-  {
-    sysinfo.audio_available = FALSE;
-  }
-#else /* !TARGET_SDL */
-
-#if defined(PLATFORM_UNIX)
-  if (!(sysinfo.audio_available = CheckAudio(sound_device_name)))
-    return;
-
-#ifdef VOXWARE
-  sysinfo.audio_loops_available = TRUE;
-#endif
-
-#else /* !PLATFORM_UNIX */
-  sysinfo.audio_loops_available = TRUE;
-
-#endif /* !PLATFORM_UNIX */
-#endif /* !TARGET_SDL */
+  OpenAudio(&audio);
 
   for(i=0; i<NUM_SOUNDS; i++)
   {
@@ -178,8 +149,8 @@ void InitSound()
 
     if (!LoadSound(&Sound[i]))
     {
-      sysinfo.audio_available = FALSE;
-      sysinfo.audio_loops_available = FALSE;
+      audio.sound_available = FALSE;
+      audio.loops_available = FALSE;
       return;
     }
   }
@@ -187,27 +158,27 @@ void InitSound()
 
 void InitSoundServer()
 {
-  if (!sysinfo.audio_available)
+  if (!audio.sound_available)
     return;
 
 #if !defined(TARGET_SDL)
 #if defined(PLATFORM_UNIX)
 
-  if (pipe(sysinfo.audio_process_pipe) < 0)
+  if (pipe(audio.soundserver_pipe) < 0)
   {
     Error(ERR_WARN, "cannot create pipe - no sounds");
-    sysinfo.audio_available = FALSE;
+    audio.sound_available = FALSE;
     return;
   }
 
-  if ((sysinfo.audio_process_id = fork()) < 0)
+  if ((audio.soundserver_pid = fork()) < 0)
   {       
     Error(ERR_WARN, "cannot create sound server process - no sounds");
-    sysinfo.audio_available = FALSE;
+    audio.sound_available = FALSE;
     return;
   }
 
-  if (!sysinfo.audio_process_id)       /* we are child */
+  if (audio.soundserver_pid == 0)      /* we are child */
   {
     SoundServer();
 
@@ -215,7 +186,7 @@ void InitSoundServer()
     exit(0);
   }
   else                                 /* we are parent */
-    close(sysinfo.audio_process_pipe[0]); /* no reading from pipe needed */
+    close(audio.soundserver_pipe[0]); /* no reading from pipe needed */
 
 #else /* !PLATFORM_UNIX */
 
@@ -337,6 +308,26 @@ void InitJoysticks()
 #endif /* !TARGET_SDL */
 }
 
+void InitDisplay()
+{
+  char *gfx_dir = getPath2(options.ro_base_directory, GRAPHICS_DIRECTORY);
+  char *x11_icon_filename = getPath2(gfx_dir, X11_ICON_FILENAME);
+  char *x11_iconmask_filename = getPath2(gfx_dir, X11_ICONMASK_FILENAME);
+  char *msdos_pointer_filename = getPath2(gfx_dir, MSDOS_POINTER_FILENAME);
+
+  free(gfx_dir);
+
+  InitProgramInfo(program_name, PROGRAM_TITLE_STRING, WINDOW_TITLE_STRING,
+                 ICON_TITLE_STRING, x11_icon_filename, x11_iconmask_filename,
+                 msdos_pointer_filename);
+
+  InitScrollbufferSize(FXSIZE, FYSIZE);        /* (only needed for MS-DOS code) */
+
+  InitVideoDisplay();
+  InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
+                 setup.fullscreen);
+}
+
 void InitGfx()
 {
   int i, j;
@@ -545,7 +536,7 @@ void InitGfxBackground()
 {
   int x, y;
 
-  drawto = backbuffer = pix[PIX_DB_BACK];
+  drawto = backbuffer;
   fieldbuffer = pix[PIX_DB_FIELD];
   SetDrawtoField(DRAW_BACKBUFFER);
 
@@ -1806,10 +1797,10 @@ void CloseAllAndExit(int exit_value)
   StopSounds();
   FreeSounds(NUM_SOUNDS);
 #else
-  if (sysinfo.audio_process_id)
+  if (audio.soundserver_pid)
   {
     StopSounds();
-    kill(sysinfo.audio_process_id, SIGTERM);
+    kill(audio.soundserver_pid, SIGTERM);
     FreeSounds(NUM_SOUNDS);
   }
 #endif