]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
fixed bug with engine sounds (for TE_ effects) and local sounds (menu, etc) being...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 20 Nov 2004 18:05:23 +0000 (18:05 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 20 Nov 2004 18:05:23 +0000 (18:05 +0000)
keep play/play2/playvol sounds around until level change (so they're not being constantly unloaded and reloaded when used repeatedly)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4777 d7cf8633-e32d-0410-b094-e92efae38249

snd_main.c
snd_main.h

index 3672c6807fcbca3f3c8525a454a7afa28c6367b0..7f01b52e9a9021eaf9d5b423ef2ff7b5f5535cf2 100644 (file)
@@ -320,7 +320,7 @@ void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds)
        for (i = 1; i < numsounds; i++)
        {
                sfx = S_FindName (serversound[i]);
-               if (sfx != NULL)
+               if (sfx != NULL && !(sfx->flags & SFXFLAG_SERVERSOUND))
                {
                        sfx->locks++;
                        sfx->flags |= SFXFLAG_SERVERSOUND;
@@ -359,8 +359,11 @@ sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean lock)
        if (sfx == NULL)
                return NULL;
 
-       if (lock)
+       if (lock && !(sfx->flags & SFXFLAG_PERMANENT))
+       {
+               sfx->flags |= SFXFLAG_PERMANENT;
                sfx->locks++;
+       }
 
        if (!nosound.integer && snd_precache.integer)
                S_LoadSound(sfx, complain);
@@ -934,20 +937,26 @@ static void S_Play_Common(float fvol, float attenuation)
        i = 1;
        while (i<Cmd_Argc())
        {
-               if (!strrchr(Cmd_Argv(i), '.'))
-                       snprintf(name, sizeof(name), "%s.wav", Cmd_Argv(i));
-               else
-                       strlcpy(name, Cmd_Argv(i), sizeof(name));
+               strlcpy(name, Cmd_Argv(i), sizeof(name));
+               if (!strrchr(name, '.'))
+                       strlcat(name, ".wav", sizeof(name));
+               i++;
                sfx = S_PrecacheSound (name, true, false);
+               // add a lock and the serversound flag to the sfx so it will be kept
+               // until level change
+               if (sfx && !(sfx->flags & SFXFLAG_SERVERSOUND))
+               {
+                       sfx->flags |= SFXFLAG_SERVERSOUND;
+                       sfx->locks++;
+               }
+
 
                // If we need to get the volume from the command line
                if (fvol == -1.0f)
                {
-                       fvol = atof(Cmd_Argv(i+1));
-                       i += 2;
-               }
-               else
+                       fvol = atof(Cmd_Argv(i));
                        i++;
+               }
 
                ch_ind = S_StartSound(-1, 0, sfx, listener_origin, fvol, attenuation);
 
@@ -1008,7 +1017,7 @@ qboolean S_LocalSound (const char *sound)
        if (!snd_initialized.integer || nosound.integer)
                return true;
 
-       sfx = S_PrecacheSound (sound, true, false);
+       sfx = S_PrecacheSound (sound, true, true);
        if (!sfx)
        {
                Con_Printf("S_LocalSound: can't precache %s\n", sound);
index d9ecb0c66d7c2c403130b92d54d809c05e1f04b8..aa36d0154381f954cd57fc86e7b6fe83c8bf3e86 100644 (file)
@@ -43,6 +43,7 @@ typedef struct
 #define SFXFLAG_FILEMISSING            (1 << 0) // wasn't able to load the associated sound file
 #define SFXFLAG_SERVERSOUND            (1 << 1) // the sfx is part of the server precache list
 #define SFXFLAG_STREAMED               (1 << 2) // informative only. You shouldn't need to know that
+#define SFXFLAG_PERMANENT              (1 << 3) // the sfx is used by the client code and should not be purged (even if it is also in the server precache list)
 
 typedef struct snd_fetcher_s snd_fetcher_t;
 struct sfx_s