]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_dma.c
Added a CHANNELFLAG_LOCALSOUND flag for channels playing a client-side sound, such...
[xonotic/darkplaces.git] / snd_dma.c
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;
 }