From f5ad32b1ea4ec08272f87bfaa5131adb4b071b43 Mon Sep 17 00:00:00 2001 From: Reki Date: Fri, 28 May 2021 13:57:55 -0400 Subject: [PATCH] Added localsound to CLVM with compat with FTEQW's implementation (ish) --- clvm_cmds.c | 2 +- prvm_cmds.c | 11 ++++++++--- snd_main.c | 31 +++++++++++++++++++++++++++++++ sound.h | 1 + 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/clvm_cmds.c b/clvm_cmds.c index 218a6314..f3c5c601 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -5124,7 +5124,7 @@ NULL, // #173 NULL, // #174 NULL, // #175 NULL, // #176 -NULL, // #177 +VM_localsound, // #177 NULL, // #178 NULL, // #179 // DOOMBRINGER range #180-#199 diff --git a/prvm_cmds.c b/prvm_cmds.c index 6a3e9ba1..82d0ab26 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -558,18 +558,23 @@ void VM_random(prvm_prog_t *prog) ========= VM_localsound -localsound(string sample) +localsound(string sample, float channel, float volume) ========= */ void VM_localsound(prvm_prog_t *prog) { const char *s; + int chan; + float vol; - VM_SAFEPARMCOUNT(1,VM_localsound); + VM_SAFEPARMCOUNT(3, VM_localsound); s = PRVM_G_STRING(OFS_PARM0); + chan = PRVM_G_INT(OFS_PARM1); + vol = PRVM_G_FLOAT(OFS_PARM2); - if(!S_LocalSound (s)) + + if(!S_LocalSound2 (s, chan, vol)) { PRVM_G_FLOAT(OFS_RETURN) = -4; VM_Warning(prog, "VM_localsound: Failed to play %s for %s !\n", s, prog->name); diff --git a/snd_main.c b/snd_main.c index e57b519a..7c177dc6 100644 --- a/snd_main.c +++ b/snd_main.c @@ -2293,3 +2293,34 @@ qbool S_LocalSound (const char *sound) channels[ch_ind].flags |= CHANNELFLAG_LOCALSOUND; return true; } + +qbool S_LocalSound2 (const char *sound, int chnl, float vlume) +{ + sfx_t *sfx; + int ch_ind; + + if (!snd_initialized.integer || nosound.integer) + return true; + + sfx = S_PrecacheSound (sound, true, false); + if (!sfx) + { + Con_Printf("S_LocalSound: can't precache %s\n", sound); + return false; + } + + // menu sounds must not be freed on level change + sfx->flags |= SFXFLAG_MENUSOUND; + + // Reki 5-28-2021 + // A small hack to try to support lazy QC practices + if (vlume == 0) + vlume = 1; + + ch_ind = S_StartSound (cl.viewentity, chnl, sfx, vec3_origin, vlume, 0); + if (ch_ind < 0) + return false; + + channels[ch_ind].flags |= CHANNELFLAG_LOCALSOUND; + return true; +} diff --git a/sound.h b/sound.h index cf7b4fa4..2645ee61 100644 --- a/sound.h +++ b/sound.h @@ -101,6 +101,7 @@ sfx_t *S_FindName(const char *name); int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation); int S_StartSound_StartPosition_Flags (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float startposition, int flags, float fspeed); qbool S_LocalSound (const char *s); +qbool S_LocalSound2 (const char *s, int chnl, float vlume); void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation); void S_StopSound (int entnum, int entchannel); -- 2.39.2