From: Cloudwalk Date: Thu, 22 Jul 2021 22:25:49 +0000 (-0400) Subject: csqc: Implement builtin #177 "localsound" X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b5f2509c170bf13f83cdb0e5d25f9cfc7469e986;p=xonotic%2Fdarkplaces.git csqc: Implement builtin #177 "localsound" --- diff --git a/clvm_cmds.c b/clvm_cmds.c index cbb31b42..2a2cefa6 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -5114,7 +5114,7 @@ NULL, // #173 NULL, // #174 NULL, // #175 NULL, // #176 -NULL, // #177 +VM_localsound, // #177 NULL, // #178 NULL, // #179 NULL, // #180 diff --git a/dpdefs/csprogsdefs.qc b/dpdefs/csprogsdefs.qc index 489abf0a..f4aa574c 100644 --- a/dpdefs/csprogsdefs.qc +++ b/dpdefs/csprogsdefs.qc @@ -435,6 +435,7 @@ string(string s, float start, float length) substring = #116; vector(string) stov = #117; string(string s) strzone = #118; void(string s) strunzone = #119; +void(string s, float chan, float vol) localsound = #177; // FTEQW range #200-#299 diff --git a/prvm_cmds.c b/prvm_cmds.c index b731bcde..3ef0b74c 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -586,18 +586,29 @@ void VM_random(prvm_prog_t *prog) ========= VM_localsound -localsound(string sample) +localsound(string sample, float chan, float vol) ========= */ void VM_localsound(prvm_prog_t *prog) { const char *s; + float chan, vol; - VM_SAFEPARMCOUNT(1,VM_localsound); + VM_SAFEPARMCOUNTRANGE(1, 3,VM_localsound); s = PRVM_G_STRING(OFS_PARM0); - - if(!S_LocalSound (s)) + if(prog->argc == 3) + { + chan = PRVM_G_FLOAT(OFS_PARM1); + vol = PRVM_G_FLOAT(OFS_PARM2) == 0 ? 1 : PRVM_G_FLOAT(OFS_PARM2); + if(!S_LocalSoundEx(s, chan, vol)) + { + PRVM_G_FLOAT(OFS_RETURN) = -4; + VM_Warning(prog, "VM_localsound: Failed to play %s for %s !\n", s, prog->name); + return; + } + } + else if(!S_LocalSound (s)) { 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 72f8d005..ebf84b9b 100644 --- a/snd_main.c +++ b/snd_main.c @@ -2240,7 +2240,7 @@ void S_ExtraUpdate (void) S_PaintAndSubmit(); } -qbool S_LocalSound (const char *sound) +qbool S_LocalSoundEx (const char *sound, int chan, float fvol) { sfx_t *sfx; int ch_ind; @@ -2261,10 +2261,15 @@ qbool S_LocalSound (const char *sound) // fun fact: in Quake 1, this used -1 "replace any entity channel", // which we no longer support anyway // changed by Black in r4297 "Changed S_LocalSound to play multiple sounds at a time." - ch_ind = S_StartSound (cl.viewentity, 0, sfx, vec3_origin, 1, 0); + ch_ind = S_StartSound (cl.viewentity, chan, sfx, vec3_origin, fvol, 0); if (ch_ind < 0) return false; channels[ch_ind].flags |= CHANNELFLAG_LOCALSOUND; return true; } + +qbool S_LocalSound (const char *sound) +{ + return S_LocalSoundEx(sound, 0, 1); +} diff --git a/snd_null.c b/snd_null.c index f487874a..f290ed15 100755 --- a/snd_null.c +++ b/snd_null.c @@ -136,6 +136,11 @@ qbool S_LocalSound (const char *s) return false; } +qbool S_LocalSoundEx (const char *s, int chan, float fvol) +{ + return false; +} + void S_BlockSound (void) { } diff --git a/sound.h b/sound.h index 697ded8e..5a9a72df 100644 --- a/sound.h +++ b/sound.h @@ -98,6 +98,7 @@ sfx_t *S_FindName(const char *name); // S_StartSound returns the channel index, or -1 if an error occurred 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_LocalSoundEx (const char *s, int chan, float fvol); qbool S_LocalSound (const char *s); void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation);