]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Added CHANNELFLAG_TRAPEZOID falloff technique
authorReki <spiper212@gmail.com>
Wed, 19 May 2021 02:30:41 +0000 (22:30 -0400)
committerReki <spiper212@gmail.com>
Wed, 19 May 2021 02:30:41 +0000 (22:30 -0400)
clvm_cmds.c
snd_main.c
sound.h
svvm_cmds.c

index 6c784bf902d8cee5f283188cde22348bdabf0b66..8cf1791aa17ed96d431304f178bf73a7cbe4b3ef 100644 (file)
@@ -207,7 +207,7 @@ static void VM_CL_sound (prvm_prog_t *prog)
        else
        {
                // LadyHavoc: we only let the qc set certain flags, others are off-limits
-               flags = (int)PRVM_G_FLOAT(OFS_PARM6) & (CHANNELFLAG_RELIABLE | CHANNELFLAG_FORCELOOP | CHANNELFLAG_PAUSED | CHANNELFLAG_FULLVOLUME | CHANNELFLAG_BGMVOLUME);
+               flags = (int)PRVM_G_FLOAT(OFS_PARM6) & (CHANNELFLAG_RELIABLE | CHANNELFLAG_FORCELOOP | CHANNELFLAG_PAUSED | CHANNELFLAG_FULLVOLUME | CHANNELFLAG_BGMVOLUME | CHANNELFLAG_TRAPEZOID);
        }
 
        // sound_starttime exists instead of sound_startposition because in a
index 3daf4ffdec1c439de5b2c530bfdef2d78181a567..94d9b23d6c6634960ab906c77316688a9845767e 100644 (file)
@@ -1395,12 +1395,28 @@ static void SND_Spatialize_WithSfx(channel_t *ch, qbool isstatic, sfx_t *sfx)
                // calculate stereo seperation and distance attenuation
                VectorSubtract(listener_origin, ch->origin, source_vec);
                dist = VectorLength(source_vec);
-               f = dist * ch->distfade;
+               
+               if (ch->flags & CHANNELFLAG_TRAPEZOID)
+               {
+                       if (dist < ch->distfade * 0.4)
+                       {
+                               f = 1.0;
+                       }
+                       else
+                       {
+                               f = dist * (ch->distfade / 0.6);
+                               f = 1.0 - f;
+                       }
+               }
+               else
+               {
+                       f = dist * ch->distfade;
 
-               f =
-                       ((snd_attenuation_exponent.value == 0) ? 1.0 : pow(1.0 - min(1.0, f), (double)snd_attenuation_exponent.value))
-                       *
-                       ((snd_attenuation_decibel.value == 0) ? 1.0 : pow(0.1, 0.1 * snd_attenuation_decibel.value * f));
+                       f =
+                               ((snd_attenuation_exponent.value == 0) ? 1.0 : pow(1.0 - min(1.0, f), (double)snd_attenuation_exponent.value))
+                               *
+                               ((snd_attenuation_decibel.value == 0) ? 1.0 : pow(0.1, 0.1 * snd_attenuation_decibel.value * f));
+               }
 
                intensity = mastervol * f;
                if (intensity > 0)
@@ -1706,6 +1722,7 @@ qbool S_SetChannelFlag (unsigned int ch_ind, unsigned int flag, qbool value)
                flag != CHANNELFLAG_PAUSED &&
                flag != CHANNELFLAG_FULLVOLUME &&
                flag != CHANNELFLAG_BGMVOLUME &&
+               flag != CHANNELFLAG_TRAPEZOID &&
                flag != CHANNELFLAG_LOCALSOUND)
                return false;
 
diff --git a/sound.h b/sound.h
index 1590a6970b5e16cacacb1e1cd525b05421f739e9..cf7b4fa480c52de19044f59a1e93247f13bc877f 100644 (file)
--- a/sound.h
+++ b/sound.h
@@ -38,9 +38,10 @@ struct cmd_state_s;
 #define CHANNELFLAG_RELIABLE   (1 << 0) // send as reliable message (only used on server)
 #define CHANNELFLAG_FORCELOOP  (1 << 1) // force looping even if the sound is not looped
 #define CHANNELFLAG_LOCALSOUND (1 << 2) // INTERNAL USE. Not settable by S_SetChannelFlag
-#define CHANNELFLAG_PAUSED     (1 << 3) // pause status
+#define CHANNELFLAG_PAUSED             (1 << 3) // pause status
 #define CHANNELFLAG_FULLVOLUME (1 << 4) // isn't affected by the general volume
 #define CHANNELFLAG_BGMVOLUME  (1 << 8) // uses bgmvolume instead of volume
+#define CHANNELFLAG_TRAPEZOID  (1 << 9) // uses trapezoidal falloff instead of linear
 
 // ====================================================================
 // Types and variables
index a8bf069cdc305c71063863388ae52bb60ec7cba4..5fabf63a8e350a7db5bcdccdc5af5611b9cc0c76 100644 (file)
@@ -566,7 +566,7 @@ static void VM_SV_sound(prvm_prog_t *prog)
        else
        {
                // LadyHavoc: we only let the qc set certain flags, others are off-limits
-               flags = (int)PRVM_G_FLOAT(OFS_PARM6) & (CHANNELFLAG_RELIABLE | CHANNELFLAG_FORCELOOP | CHANNELFLAG_PAUSED | CHANNELFLAG_FULLVOLUME | CHANNELFLAG_BGMVOLUME);
+               flags = (int)PRVM_G_FLOAT(OFS_PARM6) & (CHANNELFLAG_RELIABLE | CHANNELFLAG_FORCELOOP | CHANNELFLAG_PAUSED | CHANNELFLAG_FULLVOLUME | CHANNELFLAG_BGMVOLUME | CHANNELFLAG_TRAPEZOID);
        }
 
        if (nvolume < 0 || nvolume > 255)