]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
csqc: Implement builtin #177 "localsound"
authorCloudwalk <cloudwalk009@gmail.com>
Thu, 22 Jul 2021 22:25:49 +0000 (18:25 -0400)
committerCloudwalk <cloudwalk009@gmail.com>
Thu, 22 Jul 2021 22:25:49 +0000 (18:25 -0400)
clvm_cmds.c
dpdefs/csprogsdefs.qc
prvm_cmds.c
snd_main.c
snd_null.c
sound.h

index cbb31b42eccf63961cf031b02573968b71cda183..2a2cefa68a67f07024856b4f513eae87c56bbb55 100644 (file)
@@ -5114,7 +5114,7 @@ NULL,                                                     // #173
 NULL,                                                  // #174
 NULL,                                                  // #175
 NULL,                                                  // #176
-NULL,                                                  // #177
+VM_localsound,                                 // #177
 NULL,                                                  // #178
 NULL,                                                  // #179
 NULL,                                                  // #180
index 489abf0a576dff8d048cc201d04449aade866b7f..f4aa574ca4bf3ea3287dabfe1842c394eefa9c64 100644 (file)
@@ -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
 
index b731bcde2468c9b0f5f3a618d0babd2115be3de5..3ef0b74cf939fc417757249a4e328f1a5d0dcfb8 100644 (file)
@@ -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);
index 72f8d0058f89a316edf7a199591d509d996d38cd..ebf84b9bfd599e29601877a9e12971fa4116b872 100644 (file)
@@ -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);
+}
index f487874a40c35b1505a016eb8038623f39b5443d..f290ed152546b99be1f01caf19ff91059d159479 100755 (executable)
@@ -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 697ded8e26e31af98ac2f39b6749d27345b543d6..5a9a72dfb738decd52f953ebb82446582543bc54 100644 (file)
--- 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);