shithub: choc

Download patch

ref: 9c38ec686f1a4592f52ee56d7ed4336299c8c5c9
parent: 7bf9829dbc35be88a7ff95a09ec7ea4f72b76a48
author: Simon Howard <[email protected]>
date: Tue Sep 6 18:39:43 EDT 2005

Restore -nosound, -nosfx, -nomusic

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 80

--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: i_sound.c 79 2005-09-06 21:40:28Z fraggle $
+// $Id: i_sound.c 80 2005-09-06 22:39:43Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.16  2005/09/06 22:39:43  fraggle
+// Restore -nosound, -nosfx, -nomusic
+//
 // Revision 1.15  2005/09/06 21:40:28  fraggle
 // Setting music volume
 //
@@ -80,7 +83,7 @@
 //-----------------------------------------------------------------------------
 
 static const char
-rcsid[] = "$Id: i_sound.c 79 2005-09-06 21:40:28Z fraggle $";
+rcsid[] = "$Id: i_sound.c 80 2005-09-06 22:39:43Z fraggle $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -105,9 +108,10 @@
 
 #define NUM_CHANNELS		16
 
-static int sound_initialised = 0;
+static boolean sound_initialised = false;
 static Mix_Chunk sound_chunks[NUMSFX];
 
+
 static byte *expand_sound_data(byte *data, int samplerate, int length)
 {
     byte *result = data;
@@ -249,8 +253,13 @@
   int		pitch,
   int		priority )
 {
-    Mix_Chunk *chunk = getsfx(id);
+    Mix_Chunk *chunk;
 
+    if (!sound_initialised)
+        return 0;
+
+    chunk = getsfx(id);
+
     // play sound
 
     Mix_PlayChannelTimed(channel, chunk, 0, -1);
@@ -266,6 +275,8 @@
 
 void I_StopSound (int handle)
 {
+    if (!sound_initialised)
+        return;
     Mix_HaltChannel(handle);
 }
 
@@ -272,6 +283,9 @@
 
 int I_SoundIsPlaying(int handle)
 {
+    if (!sound_initialised) 
+        return false;
+
     return Mix_Playing(handle);
 }
 
@@ -320,6 +334,9 @@
 {
     int left, right;
 
+    if (!sound_initialised)
+        return;
+
     left = ((254 - sep) * vol) / 15;
     right = ((sep) * vol) / 15;
 
@@ -340,12 +357,16 @@
 
 
 
-
-
-
 void
 I_InitSound()
 { 
+    // If music or sound is going to play, we need to at least
+    // initialise SDL
+
+    if (M_CheckParm("-nosound") 
+     || (M_CheckParm("-nosfx") && M_CheckParm("-nomusic")))
+        return;
+
     if (SDL_Init(SDL_INIT_AUDIO) < 0)
     {
         fprintf(stderr, "Unable to set up sound.\n");
@@ -359,9 +380,14 @@
 
     Mix_AllocateChannels(NUM_CHANNELS);
     
-    sound_initialised = 1;
-
     SDL_PauseAudio(0);
+
+    if (M_CheckParm("-nosound") || M_CheckParm("-nosfx"))
+        return;
+
+    sound_initialised = true;
+
+
 }
 
 
@@ -372,9 +398,22 @@
 // Still no music done.
 // Remains. Dummies.
 //
-void I_InitMusic(void)		{ }
-void I_ShutdownMusic(void)	{ }
 
+static int music_initialised;
+
+void I_InitMusic(void)		
+{ 
+    if (M_CheckParm("-nomusic") || M_CheckParm("-nosound"))
+        return;
+
+    music_initialised = true;
+}
+
+void I_ShutdownMusic(void)	
+{ 
+    music_initialised = false;
+}
+
 static int	looping=0;
 static int	musicdies=-1;
 
@@ -383,6 +422,9 @@
     Mix_Music *music = (Mix_Music *) handle;
     int loops;
 
+    if (!music_initialised)
+        return;
+
     if (handle == NULL)
         return;
 
@@ -396,16 +438,25 @@
 
 void I_PauseSong (void *handle)
 {
+    if (!music_initialised)
+        return;
+
     Mix_PauseMusic();
 }
 
 void I_ResumeSong (void *handle)
 {
+    if (!music_initialised)
+        return;
+
     Mix_ResumeMusic();
 }
 
 void I_StopSong(void *handle)
 {
+    if (!music_initialised)
+        return;
+
     Mix_HaltMusic();
 }
 
@@ -413,6 +464,9 @@
 {
     Mix_Music *music = (Mix_Music *) handle;
 
+    if (!music_initialised)
+        return;
+
     if (handle == NULL)
         return;
 
@@ -426,6 +480,9 @@
     MIDI *mididata;
     UBYTE *mid;
     int midlen;
+
+    if (!music_initialised)
+        return NULL;
     
 #ifdef _WIN32
     sprintf(filename, "doom.mid");
@@ -475,6 +532,9 @@
 // Is the song playing?
 int I_QrySongPlaying(void *handle)
 {
+    if (!music_initialised)
+        return false;
+
     return Mix_PlayingMusic();
 }
 
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: i_system.c 37 2005-08-04 18:42:15Z fraggle $
+// $Id: i_system.c 80 2005-09-06 22:39:43Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.8  2005/09/06 22:39:43  fraggle
+// Restore -nosound, -nosfx, -nomusic
+//
 // Revision 1.7  2005/08/04 18:42:15  fraggle
 // Silence compiler warnings
 //
@@ -49,7 +52,7 @@
 //-----------------------------------------------------------------------------
 
 static const char
-rcsid[] = "$Id: i_system.c 37 2005-08-04 18:42:15Z fraggle $";
+rcsid[] = "$Id: i_system.c 80 2005-09-06 22:39:43Z fraggle $";
 
 
 #include <stdlib.h>
@@ -136,6 +139,7 @@
 void I_Init (void)
 {
     I_InitSound();
+    I_InitMusic();
 
     // initialise timer