]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Added a CHANNELFLAG_LOCALSOUND flag for channels playing a client-side sound, such...
authormolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 2 Apr 2004 13:23:20 +0000 (13:23 +0000)
committermolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 2 Apr 2004 13:23:20 +0000 (13:23 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4078 d7cf8633-e32d-0410-b094-e92efae38249

cl_parse.c
snd_dma.c
snd_mix.c
snd_null.c
sound.h

index 8804284272ca74461564b2b904f84d687ed8dfef..b8c47759f79832ff144921dced4fcc4278c66d01 100644 (file)
@@ -1667,9 +1667,15 @@ void CL_ParseServerMessage(void)
                case svc_setpause:
                        cl.paused = MSG_ReadByte ();
                        if (cl.paused)
+                       {
                                CDAudio_Pause ();
+                               S_PauseGameSounds ();
+                       }
                        else
+                       {
                                CDAudio_Resume ();
+                               S_ResumeGameSounds ();
+                       }
                        break;
 
                case svc_signonnum:
index 24525fee956237fd4e42020ca014fe6a4f33c2ba..ea4d6a4053da2f5532c8b98984e1f9ce585ed1d7 100644 (file)
--- a/snd_dma.c
+++ b/snd_dma.c
@@ -527,7 +527,7 @@ void SND_Spatialize(channel_t *ch, int isstatic)
 // Start a sound effect
 // =======================================================================
 
-void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
+int S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
 {
        channel_t *target_chan, *check;
        int             vol;
@@ -535,14 +535,14 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
        size_t  skip;
 
        if (!sound_started || !sfx || !sfx->fetcher || nosound.integer)
-               return;
+               return -1;
 
        vol = fvol*255;
 
 // pick a channel to play on
        target_chan = SND_PickChannel(entnum, entchannel);
        if (!target_chan)
-               return;
+               return -1;
 
 // spatialize
        memset (target_chan, 0, sizeof(*target_chan));
@@ -561,7 +561,7 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
        if (!S_LoadSound (sfx, true))
        {
                target_chan->sfx = NULL;
-               return;         // couldn't load the sound's data
+               return -1;              // couldn't load the sound's data
        }
 
        target_chan->sfx = sfx;
@@ -590,6 +590,8 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
                        break;
                }
        }
+
+       return (channels - target_chan);
 }
 
 void S_StopSound(int entnum, int entchannel)
@@ -622,6 +624,34 @@ void S_StopAllSoundsC(void)
        S_StopAllSounds(true);
 }
 
+void S_PauseGameSounds (void)
+{
+       unsigned int i;
+
+       for (i = 0; i < total_channels; i++)
+       {
+               channel_t *ch;
+
+               ch = &channels[i];
+               if (ch->sfx != NULL && ! (ch->flags & CHANNELFLAG_LOCALSOUND))
+                       ch->flags |= CHANNELFLAG_PAUSED;
+       }
+}
+
+void S_ResumeGameSounds (void)
+{
+       unsigned int i;
+
+       for (i = 0; i < total_channels; i++)
+       {
+               channel_t *ch;
+
+               ch = &channels[i];
+               if (ch->sfx != NULL && ! (ch->flags & CHANNELFLAG_LOCALSOUND))
+                       ch->flags &= ~CHANNELFLAG_PAUSED;
+       }
+}
+
 void S_ClearBuffer(void)
 {
        int             clear;
@@ -963,7 +993,7 @@ console functions
 
 static void S_Play_Common(float fvol, float attenuation)
 {
-       int     i;
+       int     i, ch_ind;
        char name[256];
        sfx_t   *sfx;
 
@@ -985,7 +1015,9 @@ static void S_Play_Common(float fvol, float attenuation)
                else
                        i++;
 
-               S_StartSound(-1, 0, sfx, listener_vieworigin, fvol, attenuation);
+               ch_ind = S_StartSound(-1, 0, sfx, listener_vieworigin, fvol, attenuation);
+               if (ch_ind >= 0)
+                       channels[ch_ind].flags |= CHANNELFLAG_LOCALSOUND;
        }
 }
 
@@ -1027,6 +1059,7 @@ void S_SoundList(void)
 void S_LocalSound (char *sound)
 {
        sfx_t   *sfx;
+       int             ch_ind;
 
        if (!snd_initialized.integer || nosound.integer)
                return;
@@ -1037,7 +1070,10 @@ void S_LocalSound (char *sound)
                Con_Printf("S_LocalSound: can't precache %s\n", sound);
                return;
        }
-       S_StartSound (cl.viewentity, -1, sfx, vec3_origin, 1, 1);
+
+       ch_ind = S_StartSound (cl.viewentity, -1, sfx, vec3_origin, 1, 1);
+       if (ch_ind >= 0)
+               channels[ch_ind].flags |= CHANNELFLAG_LOCALSOUND;
 }
 
 
index f6cd8e889aec496fe909e440e0479da639978379..e4759cfd6608ccdd313d2e76518375be72492100 100644 (file)
--- a/snd_mix.c
+++ b/snd_mix.c
@@ -296,6 +296,17 @@ void S_PaintChannels(int endtime)
                        if (!S_LoadSound (sfx, true))
                                continue;
 
+                       // if the channel is paused
+                       if (ch->flags & CHANNELFLAG_PAUSED)
+                       {
+                               size_t pausedtime;
+
+                               pausedtime = end - paintedtime;
+                               ch->lastptime += pausedtime;
+                               ch->end += pausedtime;
+                               continue;
+                       }
+
                        // if the sound hasn't been painted last time, update his position
                        if (ch->lastptime < paintedtime)
                        {
index a1c458697e0a53875d8841bde67980aec0039979..d6f1269ffc07a0e6cebd87e786d28ca605f7abd0 100755 (executable)
@@ -72,14 +72,23 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
 {
 }
 
-void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol,  float attenuation)
+int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol,  float attenuation)
 {
+       return -1;
 }
 
 void S_StopSound (int entnum, int entchannel)
 {
 }
 
+void S_PauseGameSounds (void)
+{
+}
+
+void S_ResumeGameSounds (void)
+{
+}
+
 sfx_t *S_GetCached(const char *name)
 {
        return NULL;
diff --git a/sound.h b/sound.h
index 8aff39c8f29164d8ba81a7a26d618e69d26c3bb2..4107320a23d3c6b0af537f9f3ead3a199456ceb1 100644 (file)
--- a/sound.h
+++ b/sound.h
@@ -69,6 +69,8 @@ typedef struct
 // channel_t flags
 #define CHANNELFLAG_NONE               0
 #define CHANNELFLAG_FORCELOOP  (1 << 0) // force looping even if the sound is not looped
+#define CHANNELFLAG_LOCALSOUND (1 << 1) // non-game sound (ex: menu sound)
+#define CHANNELFLAG_PAUSED             (1 << 2)
 
 typedef struct
 {
@@ -99,10 +101,12 @@ struct snd_fetcher_s
 void S_Init (void);
 void S_Startup (void);
 void S_Shutdown (void);
-void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol,  float attenuation);
+int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol,  float attenuation);
 void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation);
 void S_StopSound (int entnum, int entchannel);
 void S_StopAllSounds(qboolean clear);
+void S_PauseGameSounds (void);
+void S_ResumeGameSounds (void);
 void S_ClearBuffer (void);
 void S_Update(vec3_t origin, vec3_t forward, vec3_t left, vec3_t up);
 void S_ExtraUpdate (void);