From: Reki Date: Wed, 19 May 2021 02:30:41 +0000 (-0400) Subject: Added CHANNELFLAG_TRAPEZOID falloff technique X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d1f423f4334fb4b2548700c04d88169fefa26db9;p=xonotic%2Fdarkplaces.git Added CHANNELFLAG_TRAPEZOID falloff technique --- diff --git a/clvm_cmds.c b/clvm_cmds.c index 6c784bf9..8cf1791a 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -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 diff --git a/snd_main.c b/snd_main.c index 3daf4ffd..94d9b23d 100644 --- a/snd_main.c +++ b/snd_main.c @@ -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 1590a697..cf7b4fa4 100644 --- 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 diff --git a/svvm_cmds.c b/svvm_cmds.c index a8bf069c..5fabf63a 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -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)