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
This commit is contained in:
Spoike 2014-05-13 23:21:20 +00:00
parent 49249854c3
commit 3711f71bdc
4 changed files with 36 additions and 3 deletions

View File

@ -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},

View File

@ -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;

View File

@ -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);

View File

@ -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)"},