]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Added localsound to CLVM with compat with FTEQW's implementation (ish)
authorReki <spiper212@gmail.com>
Fri, 28 May 2021 17:57:55 +0000 (13:57 -0400)
committerReki <spiper212@gmail.com>
Fri, 28 May 2021 17:57:55 +0000 (13:57 -0400)
clvm_cmds.c
prvm_cmds.c
snd_main.c
sound.h

index 218a63149e673a0ce216d1932c80c1c87134e839..f3c5c60153178771701ab7246540d81d0e817688 100644 (file)
@@ -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
index 6a3e9ba1e23665845a18fb8d102ff858a1a6524f..82d0ab26e702395d6df615fa66ae280eecc341b9 100644 (file)
@@ -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);
index e57b519ad7b135dec5b4be6f2fb90f15bd800e7f..7c177dc6c7b696019c1930481f88e6f1454d6963 100644 (file)
@@ -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 cf7b4fa480c52de19044f59a1e93247f13bc877f..2645ee61b424d448a30c7abae8fef0e5ba1649b8 100644 (file)
--- 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);