rnd-20001129-1-src
authorHolger Schemel <info@artsoft.org>
Tue, 28 Nov 2000 23:02:55 +0000 (00:02 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:35:13 +0000 (10:35 +0200)
src/game.c
src/init.c
src/main.c
src/main.h
src/msdos.c
src/msdos.h
src/screens.c
src/sound.c
src/sound.h
src/system.c
src/system.h

index 1f3aca0024d71c3808c3be9853326d37586b7f1b..670f8cb14a19a29e0ce6bbfe04483b2790c0d1a9 100644 (file)
@@ -167,10 +167,10 @@ static unsigned int getStateCheckSum(int counter)
 
 void GetPlayerConfig()
 {
-  if (!sysinfo.audio_available)
+  if (!audio.sound_available)
     setup.sound = FALSE;
 
-  if (!sysinfo.audio_loops_available)
+  if (!audio.loops_available)
   {
     setup.sound_loops = FALSE;
     setup.sound_music = FALSE;
@@ -6233,7 +6233,7 @@ static void HandleGameButtons(struct GadgetInfo *gi)
        setup.sound_music = FALSE;
        FadeSound(background_loop[level_nr % num_bg_loops]);
       }
-      else if (sysinfo.audio_loops_available)
+      else if (audio.loops_available)
       { 
        setup.sound = setup.sound_music = TRUE;
        PlaySoundLoop(background_loop[level_nr % num_bg_loops]);
@@ -6243,14 +6243,14 @@ static void HandleGameButtons(struct GadgetInfo *gi)
     case SOUND_CTRL_ID_LOOPS:
       if (setup.sound_loops)
        setup.sound_loops = FALSE;
-      else if (sysinfo.audio_loops_available)
+      else if (audio.loops_available)
        setup.sound = setup.sound_loops = TRUE;
       break;
 
     case SOUND_CTRL_ID_SIMPLE:
       if (setup.sound_simple)
        setup.sound_simple = FALSE;
-      else if (sysinfo.audio_available)
+      else if (audio.sound_available)
        setup.sound = setup.sound_simple = TRUE;
       break;
 
index 60e0bcd3c22fd6135785dca3291bcc050e787e2f..040270a1b844941f1c37a59d4a5a904128b1d6ad 100644 (file)
@@ -142,35 +142,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 */
+  audio = InitAudio();
 
   for(i=0; i<NUM_SOUNDS; i++)
   {
@@ -178,8 +150,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 +159,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 +187,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 */
 
@@ -1806,10 +1778,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
index 49fde3e9941378ca31fcbe7c6535d5edf1bfb3f8..30fea5358e60e5be97d035300457c07345c284f8 100644 (file)
@@ -107,7 +107,7 @@ struct TapeInfo             tape;
 struct OptionInfo      options;
 struct SetupInfo       setup;
 struct GameInfo                game;
-struct SystemInfo      sysinfo;
+struct AudioSystemInfo audio;
 struct GlobalInfo      global;
 
 /* data needed for playing sounds */
index 705582abe1614c5ab6358c29e7f1a21148b560c7..3eb6993d96e3e9c793281ec37825221306681587 100644 (file)
@@ -530,7 +530,7 @@ extern struct JoystickInfo  joystick[];
 extern struct OptionInfo       options;
 extern struct SetupInfo                setup;
 extern struct GameInfo         game;
-extern struct SystemInfo       sysinfo;
+extern struct AudioSystemInfo  audio;
 extern struct GlobalInfo       global;
 
 extern char            *sound_name[];
index 181a9f1ada1712bd03ff9bf7ab8172a55dcef1b3..2f672ed332ac856c128d5affeddae64ac288bf72 100644 (file)
@@ -63,7 +63,7 @@ extern struct SoundControl emptySoundControl;
 
 static BITMAP *Read_PCX_to_AllegroBitmap(char *);
 
-static void allegro_drivers()
+static void allegro_init_drivers()
 {
   int i;
 
@@ -89,12 +89,17 @@ static void allegro_drivers()
 
   last_joystick_state = 0;
   joystick_event = FALSE;
+}
 
-  sysinfo.audio_available = TRUE;
+static boolean allegro_init_audio()
+{
   reserve_voices(MAX_SOUNDS_PLAYING, 0);
+
   if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) == -1)
     if (install_sound(DIGI_SB, MIDI_NONE, NULL) == -1)
-      sysinfo.audio_available = FALSE;
+      return FALSE;
+
+  return TRUE;
 }
 
 static boolean hide_mouse(Display *display, int x, int y,
@@ -325,7 +330,7 @@ Display *XOpenDisplay(char *display_name)
   display->mouse_ptr = mouse_bitmap;
 
   allegro_init();
-  allegro_drivers();
+  allegro_init_drivers();
   set_color_depth(8);
 
   /* force Windows 95 to switch to fullscreen mode */
@@ -915,6 +920,11 @@ void XAutoRepeatOff(Display *display)
   keyboard_auto_repeat = FALSE;
 }
 
+boolean MSDOSInitAudio(void)
+{
+  return allegro_init_audio();
+}
+
 void NetworkServer(int port, int serveronly)
 {
   Error(ERR_WARN, "networking not supported in DOS version");
index 2a16bb6d4b5f5d99ec23803ace5831c7b4dd5810..499de70a94dc45b966f8c557b117a4400355812a 100644 (file)
@@ -703,6 +703,8 @@ Bool XQueryPointer(Display *, Window, Window *, Window *, int *, int *,
                   int *, int *, unsigned int *);
 void XAutoRepeatOn(Display *);
 void XAutoRepeatOff(Display *);
+
+boolean MSDOSInitAudio(void);
 void NetworkServer(int, int);
 
 #endif /* MSDOS_H */
index b97c44a134777973bdf98284cb50733a7e7728ee..e4be131820d7614a5c4d3b19d385393dc6178d5c 100644 (file)
@@ -1409,7 +1409,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
     {
       int yy = y-1;
 
-      if (y == 3 && sysinfo.audio_available)
+      if (y == 3 && audio.sound_available)
       {
        if (setup.sound)
        {
@@ -1423,7 +1423,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
          DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
        setup.sound = !setup.sound;
       }
-      else if (y == 4 && sysinfo.audio_loops_available)
+      else if (y == 4 && audio.loops_available)
       {
        if (setup.sound_loops)
          DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
@@ -1435,7 +1435,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
        }
        setup.sound_loops = !setup.sound_loops;
       }
-      else if (y == 5 && sysinfo.audio_loops_available)
+      else if (y == 5 && audio.loops_available)
       {
        if (setup.sound_music)
          DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
index 185b1822d9bbe3213a927ba37c803a671897107a..628dc047c11c66d9c9eecada841222e335873f01 100644 (file)
@@ -91,9 +91,14 @@ int CheckAudio(char *audio_device_name)
   return SOUND_AVAILABLE;
 }
 
-boolean UnixInitAudio(void)
+void UnixInitAudio(struct AudioSystemInfo *audio)
 {
-  return TRUE;
+  if (!(audio->sound_available = CheckAudio(sound_device_name)))
+    return;
+
+#ifdef VOXWARE
+  audio->loops_available = TRUE;
+#endif
 }
 #endif /* PLATFORM_UNIX */
 
@@ -104,7 +109,7 @@ void SoundServer()
   struct SoundControl snd_ctrl;
   fd_set sound_fdset;
 
-  close(sysinfo.audio_process_pipe[1]);        /* no writing into pipe needed */
+  close(audio.soundserver_pipe[1]);    /* no writing into pipe needed */
 #endif
 
   for(i=0;i<MAX_SOUNDS_PLAYING;i++)
@@ -122,15 +127,15 @@ void SoundServer()
 #endif
 
   FD_ZERO(&sound_fdset); 
-  FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset);
+  FD_SET(audio.soundserver_pipe[0], &sound_fdset);
 
   while(1)     /* wait for sound playing commands from client */
   {
-    FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset);
-    select(sysinfo.audio_process_pipe[0] + 1, &sound_fdset, NULL, NULL, NULL);
-    if (!FD_ISSET(sysinfo.audio_process_pipe[0], &sound_fdset))
+    FD_SET(audio.soundserver_pipe[0], &sound_fdset);
+    select(audio.soundserver_pipe[0] + 1, &sound_fdset, NULL, NULL, NULL);
+    if (!FD_ISSET(audio.soundserver_pipe[0], &sound_fdset))
       continue;
-    if (read(sysinfo.audio_process_pipe[0], &snd_ctrl, sizeof(snd_ctrl))
+    if (read(audio.soundserver_pipe[0], &snd_ctrl, sizeof(snd_ctrl))
        != sizeof(snd_ctrl))
       Error(ERR_EXIT_SOUND_SERVER, "broken pipe - no sounds");
 
@@ -154,7 +159,7 @@ void SoundServer()
        playlist[i]=emptySoundControl;
       playing_sounds=0;
 
-      close(sysinfo.audio_fd);
+      close(audio.device_fd);
     }
     else if (snd_ctrl.stop_sound)
     {
@@ -169,7 +174,7 @@ void SoundServer()
        }
 
       if (!playing_sounds)
-       close(sysinfo.audio_fd);
+       close(audio.device_fd);
     }
 
     if (playing_sounds || snd_ctrl.active)
@@ -189,7 +194,7 @@ void SoundServer()
 #endif
 
       if (playing_sounds ||
-         (sysinfo.audio_fd = OpenAudio(sound_device_name)) >= 0)
+         (audio.device_fd = OpenAudio(sound_device_name)) >= 0)
       {
        if (!playing_sounds)    /* we just opened the audio device */
        {
@@ -197,13 +202,12 @@ void SoundServer()
          /* (with stereo the effective buffer size will shrink to 256) */
          fragment_size = 0x00020009;
 
-         if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_SETFRAGMENT, &fragment_size)
-             < 0)
+         if (ioctl(audio.device_fd,SNDCTL_DSP_SETFRAGMENT,&fragment_size) < 0)
            Error(ERR_EXIT_SOUND_SERVER,
                  "cannot set fragment size of /dev/dsp - no sounds");
 
          /* try if we can use stereo sound */
-         if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_STEREO, &stereo) < 0)
+         if (ioctl(audio.device_fd, SNDCTL_DSP_STEREO, &stereo) < 0)
          {
 #ifdef DEBUG
            static boolean reported = FALSE;
@@ -217,13 +221,12 @@ void SoundServer()
            stereo = FALSE;
          }
 
-         if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_SPEED, &sample_rate) < 0)
+         if (ioctl(audio.device_fd, SNDCTL_DSP_SPEED, &sample_rate) < 0)
            Error(ERR_EXIT_SOUND_SERVER,
                  "cannot set sample rate of /dev/dsp - no sounds");
 
          /* get the real fragmentation size; this should return 512 */
-         if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_GETBLKSIZE, &fragment_size)
-             < 0)
+         if (ioctl(audio.device_fd, SNDCTL_DSP_GETBLKSIZE,&fragment_size) < 0)
            Error(ERR_EXIT_SOUND_SERVER,
                  "cannot get fragment size of /dev/dsp - no sounds");
 
@@ -234,10 +237,10 @@ void SoundServer()
          SoundServer_InsertNewSound(snd_ctrl);
 
        while(playing_sounds &&
-             select(sysinfo.audio_process_pipe[0] + 1,
+             select(audio.soundserver_pipe[0] + 1,
                     &sound_fdset, NULL, NULL, &delay) < 1)
        {       
-         FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset);
+         FD_SET(audio.soundserver_pipe[0], &sound_fdset);
 
          /* first clear the last premixing buffer */
          memset(premix_last_buffer,0,fragment_size*sizeof(int));
@@ -334,12 +337,12 @@ void SoundServer()
          }
 
          /* finally play the sound fragment */
-         write(sysinfo.audio_fd, playing_buffer,fragment_size);
+         write(audio.device_fd, playing_buffer,fragment_size);
        }
 
        /* if no sounds playing, free device for other sound programs */
        if (!playing_sounds)
-         close(sysinfo.audio_fd);
+         close(audio.device_fd);
       }
     }
 
@@ -354,15 +357,15 @@ void SoundServer()
       int wait_percent = 90;   /* wait 90% of the real playing time */
       int i;
 
-      if ((sysinfo.audio_fd = OpenAudio(sound_device_name)) >= 0)
+      if ((audio.device_fd = OpenAudio(sound_device_name)) >= 0)
       {
        playing_sounds = 1;
 
        while(playing_sounds &&
-             select(sysinfo.audio_process_pipe[0] + 1,
+             select(audio.soundserver_pipe[0] + 1,
                     &sound_fdset, NULL, NULL, &delay) < 1)
        {       
-         FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset);
+         FD_SET(audio.soundserver_pipe[0], &sound_fdset);
 
          /* get pointer and size of the actual sound sample */
          sample_ptr = snd_ctrl.data_ptr + snd_ctrl.playingpos;
@@ -389,12 +392,12 @@ void SoundServer()
            playing_sounds = 0;
 
          /* finally play the sound fragment */
-         write(sysinfo.audio_fd,playing_buffer,sample_size);
+         write(audio.device_fd,playing_buffer,sample_size);
 
          delay.tv_sec = 0;
          delay.tv_usec = ((sample_size*10*wait_percent)/(sample_rate))*1000;
        }
-       close(sysinfo.audio_fd);
+       close(audio.device_fd);
       }
     }
 
@@ -608,7 +611,7 @@ static void SoundServer_StopSound(int nr)
 
 #if !defined(PLATFORM_MSDOS)
   if (!playing_sounds)
-    close(sysinfo.audio_fd);
+    close(audio.device_fd);
 #endif
 }
 
@@ -627,7 +630,7 @@ static void SoundServer_StopAllSounds()
   playing_sounds = 0;
 
 #if !defined(PLATFORM_MSDOS)
-  close(sysinfo.audio_fd);
+  close(audio.device_fd);
 #endif
 }
 #endif /* PLATFORM_MSDOS */
@@ -891,7 +894,7 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop)
 {
   struct SoundControl snd_ctrl = emptySoundControl;
 
-  if (!sysinfo.audio_available || !setup.sound)
+  if (!audio.sound_available || !setup.sound)
     return;
 
   if (volume<PSND_MIN_VOLUME)
@@ -921,10 +924,10 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop)
 
 #else
 #if !defined(PLATFORM_MSDOS)
-  if (write(sysinfo.audio_process_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
+  if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
   {
     Error(ERR_WARN, "cannot pipe to child process - no sounds");
-    sysinfo.audio_available = FALSE;
+    audio.sound_available = FALSE;
     return;
   }
 #else
@@ -957,7 +960,7 @@ void StopSoundExt(int nr, int method)
 {
   struct SoundControl snd_ctrl = emptySoundControl;
 
-  if (!sysinfo.audio_available)
+  if (!audio.sound_available)
     return;
 
   if (SSND_FADING(method))
@@ -986,10 +989,10 @@ void StopSoundExt(int nr, int method)
 
 #else
 #if !defined(PLATFORM_MSDOS)
-  if (write(sysinfo.audio_process_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
+  if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
   {
     Error(ERR_WARN, "cannot pipe to child process - no sounds");
-    sysinfo.audio_available = FALSE;
+    audio.sound_available = FALSE;
     return;
   }
 #else
@@ -1002,7 +1005,7 @@ void FreeSounds(int num_sounds)
 {
   int i;
 
-  if (!sysinfo.audio_available)
+  if (!audio.sound_available)
     return;
 
   for(i=0; i<num_sounds; i++)
index 811a7bb9c9ee620c99786eb56dbd8c0990de3b8e..a4f9d878cb2a47b9366711d7646f91da3e995a1d 100644 (file)
@@ -163,7 +163,7 @@ struct SoundControl
 /* general sound functions */
 int OpenAudio(char *);
 int CheckAudio(char *);
-boolean UnixInitAudio(void);
+void UnixInitAudio(struct AudioSystemInfo *);
 
 /* sound server functions */ 
 void SoundServer(void);
index bfc0c0e8c97c3d10290637590c8263bb90f0d289..cdf66b33dc05efb823ded0623cf4e44626314329 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "main.h"
 #include "misc.h"
+#include "sound.h"
 
 
 /* ========================================================================= */
@@ -233,19 +234,33 @@ inline void ChangeVideoModeIfNeeded(void)
 /* audio functions                                                           */
 /* ========================================================================= */
 
-inline boolean InitAudio(void)
+inline struct AudioSystemInfo InitAudio(void)
 {
-  sysinfo.audio_available = TRUE;
-  sysinfo.audio_loops_available = FALSE;
+  struct AudioSystemInfo audio;
 
-  if (!sysinfo.audio_available)
-    return FALSE;
+  audio.sound_available = FALSE;
+  audio.loops_available = FALSE;
+  audio.soundserver_pipe[0] = audio.soundserver_pipe[1] = 0;
+  audio.soundserver_pid = 0;
+  audio.device_fd = 0;
 
-#ifdef TARGET_SDL
-  return SDLInitAudio();
-#else
-  return TRUE;
+#if defined(TARGET_SDL)
+  if (SDLInitAudio())
+  {
+    audio.sound_available = TRUE;
+    audio.loops_available = TRUE;
+  }
+#elif defined(PLATFORM_MSDOS)
+  if (MSDOSInitAudio())
+  {
+    audio.sound_available = TRUE;
+    audio.loops_available = TRUE;
+  }
+#elif defined(PLATFORM_UNIX)
+  UnixInitAudio(&audio);
 #endif
+
+  return audio;
 }
 
 
index 0e84953a407dad736dc1d4f5885a9a164bb82619..feaf5ae668162cfcd3a1be0fa0c598a244af13cc 100644 (file)
@@ -43,13 +43,13 @@ typedef int (*EventFilter)(const Event *);
 
 /* structure definitions */
 
-struct SystemInfo
+struct AudioSystemInfo
 {
-  boolean audio_available;
-  boolean audio_loops_available;
-  int audio_process_id;
-  int audio_process_pipe[2];
-  int audio_fd;
+  boolean sound_available;
+  boolean loops_available;
+  int soundserver_pipe[2];
+  int soundserver_pid;
+  int device_fd;
 };
 
 
@@ -73,7 +73,7 @@ inline boolean PointerInWindow(DrawWindow);
 inline boolean SetVideoMode(void);
 inline void ChangeVideoModeIfNeeded(void);
 
-inline boolean InitAudio(void);
+inline struct AudioSystemInfo InitAudio(void);
 
 inline void InitEventFilter(EventFilter);
 inline boolean PendingEvent(void);