From 280eaa59ec9f7f813d00b6311f251ee397311074 Mon Sep 17 00:00:00 2001 From: dresk Date: Sun, 16 Sep 2007 23:20:50 +0000 Subject: [PATCH] Added optional CSQC function CSQC_Event_Sound with the following parameters : float entitynum, float channel, string soundname, float volume, float attenuation, vector position . This function, if provided, is called whenever a sound packet arrives from the server. If the function returns true, the sound call is skipped in the engine, otherwise it is played as normal. Function intention is to provide additional feedback on sound events (without touching the packet stream). git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7565 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_parse.c | 4 +++- csprogs.c | 24 ++++++++++++++++++++++++ progsvm.h | 1 + prvm_edict.c | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cl_parse.c b/cl_parse.c index 1dd0aed4..e0c102e5 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -184,6 +184,7 @@ void QW_CL_StartUpload(unsigned char *data, int size); //static qboolean QW_CL_IsUploading(void); static void QW_CL_StopUpload(void); void CL_VM_UpdateIntermissionState(int intermission); +qboolean CL_VM_Event_Sound(int sound_num, int volume, int channel, float attenuation, int ent, vec3_t pos); /* ================== @@ -267,7 +268,8 @@ void CL_ParseStartSoundPacket(int largesoundindex) if (ent >= cl.max_entities) CL_ExpandEntities(ent); - S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0f, attenuation); + if( !CL_VM_Event_Sound(sound_num, volume / 255.0f, channel, attenuation, ent, pos) ) + S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0f, attenuation); } /* diff --git a/csprogs.c b/csprogs.c index 518f28e7..90aeb940 100644 --- a/csprogs.c +++ b/csprogs.c @@ -3,6 +3,7 @@ #include "clprogdefs.h" #include "csprogs.h" #include "cl_collision.h" +#include "snd_main.h" //============================================================================ // Client prog handling @@ -448,6 +449,29 @@ void CL_VM_UpdateShowingScoresState (int showingscores) CSQC_END } } +qboolean CL_VM_Event_Sound(int sound_num, int volume, int channel, float attenuation, int ent, vec3_t pos) +{ + qboolean r = false; + if(cl.csqc_loaded) + { + CSQC_BEGIN + if(prog->funcoffsets.CSQC_Event_Sound) + { + prog->globals.client->time = cl.time; + PRVM_G_FLOAT(OFS_PARM0) = ent; + PRVM_G_FLOAT(OFS_PARM1) = channel; + PRVM_G_INT(OFS_PARM2) = PRVM_SetTempString(cl.sound_name[sound_num] ); + PRVM_G_FLOAT(OFS_PARM3) = volume; + PRVM_G_FLOAT(OFS_PARM4) = attenuation; + VectorCopy(pos, PRVM_G_VECTOR(OFS_PARM5) ); + PRVM_ExecuteProgram(prog->funcoffsets.CSQC_Event_Sound, "QC function CSQC_Event_Sound is missing"); + r = CSQC_RETURNVAL; + } + CSQC_END + } + + return r; +} void CL_VM_UpdateCoopDeathmatchGlobals (int gametype) { // Avoid global names for clean(er) coding diff --git a/progsvm.h b/progsvm.h index 43b34bee..ff2c3bbf 100644 --- a/progsvm.h +++ b/progsvm.h @@ -255,6 +255,7 @@ typedef struct prvm_prog_funcoffsets_s func_t CSQC_Ent_Remove; // csqc func_t CSQC_Ent_Update; // csqc func_t CSQC_Event; // csqc [515]: engine call this for its own needs so csqc can do some things according to what engine it's running on. example: to say about edicts increase, whatever... + func_t CSQC_Event_Sound; // csqc : called by engine when an incoming sound packet arrives so CSQC can act on it func_t CSQC_Init; // csqc func_t CSQC_InputEvent; // csqc func_t CSQC_Parse_CenterPrint; // csqc diff --git a/prvm_edict.c b/prvm_edict.c index 02d15dba..4d4be14b 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -1418,6 +1418,7 @@ void PRVM_FindOffsets(void) prog->funcoffsets.CSQC_Ent_Remove = PRVM_ED_FindFunctionOffset("CSQC_Ent_Remove"); prog->funcoffsets.CSQC_Ent_Update = PRVM_ED_FindFunctionOffset("CSQC_Ent_Update"); prog->funcoffsets.CSQC_Event = PRVM_ED_FindFunctionOffset("CSQC_Event"); + prog->funcoffsets.CSQC_Event_Sound = PRVM_ED_FindFunctionOffset("CSQC_Event_Sound"); prog->funcoffsets.CSQC_Init = PRVM_ED_FindFunctionOffset("CSQC_Init"); prog->funcoffsets.CSQC_InputEvent = PRVM_ED_FindFunctionOffset("CSQC_InputEvent"); prog->funcoffsets.CSQC_Parse_CenterPrint = PRVM_ED_FindFunctionOffset("CSQC_Parse_CenterPrint"); -- 2.39.2