]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_main.c
CONTRIBUTING: Fix typos
[xonotic/darkplaces.git] / snd_main.c
index 6f3bf31e1294bd9f313377db4c08ebd6b1c9c29e..03d7e33e76ae59c9892810a11809bb2532dac5b3 100644 (file)
@@ -183,6 +183,7 @@ cvar_t snd_spatialization_prologic_frontangle = {CF_CLIENT | CF_ARCHIVE, "snd_sp
 cvar_t snd_spatialization_occlusion = {CF_CLIENT | CF_ARCHIVE, "snd_spatialization_occlusion", "1", "enable occlusion testing on spatialized sounds, which simply quiets sounds that are blocked by the world; 1 enables PVS method, 2 enables LineOfSight method, 3 enables both"};
 
 // Cvars declared in snd_main.h (shared with other snd_*.c files)
+cvar_t snd_waterfx = {CF_CLIENT | CF_ARCHIVE, "snd_waterfx", "1", "underwater sound filter strength"};
 cvar_t _snd_mixahead = {CF_CLIENT | CF_ARCHIVE, "_snd_mixahead", "0.15", "how much sound to mix ahead of time"};
 cvar_t snd_streaming = {CF_CLIENT | CF_ARCHIVE, "snd_streaming", "1", "enables keeping compressed ogg sound files compressed, decompressing them only as needed, otherwise they will be decompressed completely at load (may use a lot of memory); when set to 2, streaming is performed even if this would waste memory"};
 cvar_t snd_streaming_length = {CF_CLIENT | CF_ARCHIVE, "snd_streaming_length", "1", "decompress sounds completely if they are less than this play time when snd_streaming is 1"};
@@ -276,9 +277,9 @@ static void S_Play_Common (cmd_state_t *cmd, float fvol, float attenuation)
        while (i < Cmd_Argc (cmd))
        {
                // Get the name, and appends ".wav" as an extension if there's none
-               strlcpy (name, Cmd_Argv(cmd, i), sizeof (name));
+               dp_strlcpy (name, Cmd_Argv(cmd, i), sizeof (name));
                if (!strrchr (name, '.'))
-                       strlcat (name, ".wav", sizeof (name));
+                       dp_strlcat (name, ".wav", sizeof (name));
                i++;
 
                // If we need to get the volume from the command line
@@ -812,6 +813,7 @@ void S_Init(void)
        Cvar_RegisterVariable(&ambient_fade);
        Cvar_RegisterVariable(&snd_noextraupdate);
        Cvar_RegisterVariable(&snd_show);
+       Cvar_RegisterVariable(&snd_waterfx);
        Cvar_RegisterVariable(&_snd_mixahead);
        Cvar_RegisterVariable(&snd_swapstereo); // for people with backwards sound wiring
        Cvar_RegisterVariable(&snd_channellayout);
@@ -927,7 +929,7 @@ sfx_t *S_FindName (const char *name)
        // Add a sfx_t struct for this sound
        sfx = (sfx_t *)Mem_Alloc (snd_mempool, sizeof (*sfx));
        memset (sfx, 0, sizeof(*sfx));
-       strlcpy (sfx->name, name, sizeof (sfx->name));
+       dp_strlcpy (sfx->name, name, sizeof (sfx->name));
        sfx->memsize = sizeof(*sfx);
        sfx->next = known_sfx;
        known_sfx = sfx;
@@ -1226,7 +1228,7 @@ static void SND_Spatialize_WithSfx(channel_t *ch, qbool isstatic, sfx_t *sfx)
                {
                        //Con_Printf("-- entnum %i origin %f %f %f neworigin %f %f %f\n", ch->entnum, ch->origin[0], ch->origin[1], ch->origin[2], cl.entities[ch->entnum].state_current.origin[0], cl.entities[ch->entnum].state_current.origin[1], cl.entities[ch->entnum].state_current.origin[2]);
 
-                       if (ch->entnum > MAX_EDICTS)
+                       if (CLVM_prog->loaded && ch->entnum > MAX_EDICTS)
                                if (!CL_VM_GetEntitySoundOrigin(ch->entnum, ch->origin))
                                        ch->entnum = MAX_EDICTS; // entity was removed, disown sound
                }
@@ -1240,7 +1242,7 @@ static void SND_Spatialize_WithSfx(channel_t *ch, qbool isstatic, sfx_t *sfx)
                        else
                                Matrix4x4_OriginFromMatrix(&cl.entities[ch->entnum].render.matrix, ch->origin);
                }
-               else if (cl.csqc_server2csqcentitynumber[ch->entnum])
+               else if (CLVM_prog->loaded && cl.csqc_server2csqcentitynumber[ch->entnum])
                {
                        //Con_Printf("-- entnum %i (client %i) origin %f %f %f neworigin %f %f %f\n", ch->entnum, cl.csqc_server2csqcentitynumber[ch->entnum], ch->origin[0], ch->origin[1], ch->origin[2], cl.entities[ch->entnum].state_current.origin[0], cl.entities[ch->entnum].state_current.origin[1], cl.entities[ch->entnum].state_current.origin[2]);
 
@@ -1850,7 +1852,6 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
        S_PlaySfxOnChannel (sfx, target_chan, CHANNELFLAG_FORCELOOP, origin, fvol, attenuation, true, 0, 0, 0, 1.0f);
 }
 
-
 /*
 ===================
 S_UpdateAmbientSounds
@@ -1870,7 +1871,10 @@ static void S_UpdateAmbientSounds (void)
        if (cl.worldmodel && cl.worldmodel->brush.AmbientSoundLevelsForPoint)
                cl.worldmodel->brush.AmbientSoundLevelsForPoint(cl.worldmodel, listener_origin, ambientlevels, sizeof(ambientlevels));
 
+
        // Calc ambient sound levels
+       S_SetUnderwaterIntensity();
+
        for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
        {
                chan = &channels[ambient_channel];