From 3711f71bdc082e993167259c6dee6bf0eaddd824 Mon Sep 17 00:00:00 2001 From: Spoike Date: Tue, 13 May 2014 23:21:20 +0000 Subject: [PATCH] add getsoundtime builtin to csqc. needs testing. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4655 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/pr_csqc.c | 8 ++++++++ engine/client/snd_dma.c | 24 ++++++++++++++++++++++++ engine/client/sound.h | 3 ++- engine/server/pr_cmds.c | 4 ++-- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/engine/client/pr_csqc.c b/engine/client/pr_csqc.c index 4a13ea1b8..b95819c2d 100644 --- a/engine/client/pr_csqc.c +++ b/engine/client/pr_csqc.c @@ -2833,6 +2833,13 @@ static void QCBUILTIN PF_checkextension (pubprogfuncs_t *prinst, struct globalva G_FLOAT(OFS_RETURN) = false; } +void QCBUILTIN PF_getsoundtime (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals) +{ + wedict_t *entity = G_WEDICT(prinst, OFS_PARM0); + int channel = G_FLOAT(OFS_PARM1); + + G_FLOAT(OFS_RETURN) = S_GetSoundTime(entity, channel); +} static void QCBUILTIN PF_cs_sound(pubprogfuncs_t *prinst, struct globalvars_s *pr_globals) { const char *sample; @@ -4842,6 +4849,7 @@ static struct { {"loadfromdata", PF_loadfromdata, 529}, {"loadfromfile", PF_loadfromfile, 530}, + {"getsoundtime", PF_getsoundtime, 533}, {"soundlength", PF_soundlength, 534}, {"buf_loadfile", PF_buf_loadfile, 535}, {"buf_writefile", PF_buf_writefile, 536}, diff --git a/engine/client/snd_dma.c b/engine/client/snd_dma.c index be91a80a0..b7356bf5d 100644 --- a/engine/client/snd_dma.c +++ b/engine/client/snd_dma.c @@ -2339,6 +2339,30 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f S_UnlockMixer(); } +float S_GetSoundTime(int entnum, int entchannel) +{ + int i; + float result = -1; //if we didn't find one + soundcardinfo_t *sc; + S_LockMixer(); + for (sc = sndcardinfo; sc && result == -1; sc = sc->next) + { + for (i = 0; i < sc->total_chans; i++) + { + if (sc->channel[i].entnum == entnum && sc->channel[i].entchannel == entchannel && sc->channel[i].sfx) + { + result = (sc->channel[i].pos>>PITCHSHIFT) / (float)snd_speed; //the time into the sound, ignoring play rate. + break; + } + } + //we found one on this sound device card, ignore others. + if (result != -1) + break; + } + S_UnlockMixer(); + return result; +} + qboolean S_IsPlayingSomewhere(sfx_t *s) { soundcardinfo_t *si; diff --git a/engine/client/sound.h b/engine/client/sound.h index 5a81b8d51..c40d5bb8c 100644 --- a/engine/client/sound.h +++ b/engine/client/sound.h @@ -94,7 +94,7 @@ typedef struct int flags; // cf_ flags int looping; // where to loop, -1 = no looping int entnum; // to allow overriding a specific sound - int entchannel; //int audio_fd + int entchannel; // to avoid overriding a specific sound too easily vec3_t origin; // origin of sound effect vec_t dist_mult; // distance multiplier (attenuation/clipK) int master_vol; // 0-255 master volume @@ -116,6 +116,7 @@ typedef struct soundcardinfo_s soundcardinfo_t; void S_Init (void); void S_Startup (void); void S_Shutdown (qboolean final); +float S_GetSoundTime(int entnum, int entchannel); void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float timeofs, float pitchadj); void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation); void S_StopSound (int entnum, int entchannel); diff --git a/engine/server/pr_cmds.c b/engine/server/pr_cmds.c index 94707448e..21d54d520 100644 --- a/engine/server/pr_cmds.c +++ b/engine/server/pr_cmds.c @@ -9687,8 +9687,8 @@ BuiltinList_t BuiltinList[] = { //nq qw h2 ebfs //end mvdsv extras //restart dp extras // {"log", PF_Fixme, 0, 0, 0, 532, "float(string mname)", true}, -// {"getsoundtime", VM_getsoundtime, 0, 0, 0, 533, "float(entity e, float channel)" STUB}, - {"soundlength", PF_Ignore, 0, 0, 0, 534, "float(string sample)" STUB}, + {"getsoundtime", PF_Ignore, 0, 0, 0, 533, "float(entity e, float channel)"}, + {"soundlength", PF_Ignore, 0, 0, 0, 534, "float(string sample)"}, {"buf_loadfile", PF_buf_loadfile, 0, 0, 0, 535, "float(string filename, float bufhandle)"}, {"buf_writefile", PF_buf_writefile, 0, 0, 0, 536, "float(float filehandle, float bufhandle, optional float startpos, optional float numstrings)"}, // {"bufstr_find", PF_Fixme, 0, 0, 0, 537, "float(float bufhandle, string match, float matchrule, float startpos)"},