From cf22ff4047c6cac2ee44bb3ecf554ca0f9eed819 Mon Sep 17 00:00:00 2001 From: divverent Date: Wed, 15 Apr 2009 22:38:54 +0000 Subject: [PATCH] DP_QC_GETTIME_CDTRACK: extension to query the playing time of the current cd track. Beware: the timing is currently not exact. Might get improved later. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8930 d7cf8633-e32d-0410-b094-e92efae38249 --- cd_shared.c | 7 +++++++ cdaudio.h | 2 +- prvm_cmds.c | 8 ++++++-- snd_3dras.c | 6 ++++++ snd_main.c | 16 ++++++++++++++++ snd_null.c | 6 ++++++ sound.h | 1 + svvm_cmds.c | 1 + 8 files changed, 44 insertions(+), 3 deletions(-) diff --git a/cd_shared.c b/cd_shared.c index c57be339..8a47f7b7 100644 --- a/cd_shared.c +++ b/cd_shared.c @@ -281,6 +281,13 @@ void CDAudio_Play (int track, qboolean looping) CDAudio_Play_byName(buf, looping); } +float CDAudio_GetPosition () +{ + if(faketrack != -1) + return S_GetChannelPosition(faketrack); + return -1; +} + void CDAudio_Stop (void) { if (!enabled) diff --git a/cdaudio.h b/cdaudio.h index 2b9729e3..ff96a3db 100644 --- a/cdaudio.h +++ b/cdaudio.h @@ -47,4 +47,4 @@ void CDAudio_Resume(void); int CDAudio_Startup(void); void CDAudio_Shutdown(void); void CDAudio_Update(void); - +float CDAudio_GetPosition(void); diff --git a/prvm_cmds.c b/prvm_cmds.c index bba2a724..c1be177c 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -2117,7 +2117,7 @@ void VM_substring(void) start = bound(0, start, slength); if (length < 0) // FTE_STRINGS feature - length += slength - start; + length += slength - start + 1; maxlen = min((int)sizeof(string) - 1, slength - start); length = bound(0, length, maxlen); @@ -2610,6 +2610,7 @@ float gettime(void) ========= */ extern double host_starttime; +float CDAudio_GetPosition(void); void VM_gettime(void) { int timer_index; @@ -2635,7 +2636,10 @@ void VM_gettime(void) PRVM_G_FLOAT(OFS_RETURN) = (float) (Sys_DoubleTime() - realtime); break; case 3: // GETTIME_UPTIME - PRVM_G_FLOAT(OFS_RETURN) = (float) Sys_DoubleTime() - host_starttime; + PRVM_G_FLOAT(OFS_RETURN) = (float) (Sys_DoubleTime() - host_starttime); + break; + case 4: // GETTIME_CDTRACK + PRVM_G_FLOAT(OFS_RETURN) = (float) CDAudio_GetPosition(); break; default: VM_Warning("VM_gettime: %s: unsupported timer specified, returning realtime\n", PRVM_NAME); diff --git a/snd_3dras.c b/snd_3dras.c index cff3ec91..4df5c09e 100644 --- a/snd_3dras.c +++ b/snd_3dras.c @@ -1002,6 +1002,12 @@ void S_SetChannelVolume (unsigned int ch_ind, float fvol){ } } +float S_GetChannelPosition (unsigned int ch_ind) +{ + // FIXME unsupported + return -1; +} + void S_BlockSound (void){ soundblocked++; } diff --git a/snd_main.c b/snd_main.c index 8075c6c1..e4a4934a 100644 --- a/snd_main.c +++ b/snd_main.c @@ -1598,6 +1598,22 @@ void S_SetChannelVolume (unsigned int ch_ind, float fvol) channels[ch_ind].master_vol = (int)(fvol * 255.0f); } +float S_GetChannelPosition (unsigned int ch_ind) +{ + // note: this is NOT accurate yet + int s; + channel_t *ch = &channels[ch_ind]; + sfx_t *sfx = ch->sfx; + + s = ch->pos; + /* + if(!snd_usethreadedmixing) + s += _snd_mixahead.value * S_GetSoundRate(); + */ + return (s % sfx->total_length) / (float) S_GetSoundRate(); +} + + /* ================= diff --git a/snd_null.c b/snd_null.c index c8aa0874..ab5b4c6e 100755 --- a/snd_null.c +++ b/snd_null.c @@ -141,3 +141,9 @@ int S_GetSoundChannels(void) { return 0; } + +float S_GetChannelPosition (unsigned int ch_ind) +{ + return -1; +} + diff --git a/sound.h b/sound.h index c77737e6..183b71e0 100644 --- a/sound.h +++ b/sound.h @@ -83,6 +83,7 @@ void S_PauseGameSounds (qboolean toggle); void S_StopChannel (unsigned int channel_ind, qboolean lockmutex); qboolean S_SetChannelFlag (unsigned int ch_ind, unsigned int flag, qboolean value); void S_SetChannelVolume (unsigned int ch_ind, float fvol); +float S_GetChannelPosition (unsigned int ch_ind); void S_BlockSound (void); void S_UnblockSound (void); diff --git a/svvm_cmds.c b/svvm_cmds.c index 324082b5..bb689358 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -84,6 +84,7 @@ char *vm_sv_extensions = "DP_QC_GETTAGINFO " "DP_QC_GETTAGINFO_BONEPROPERTIES " "DP_QC_GETTIME " +"DP_QC_GETTIME_CDTRACK " "DP_QC_MINMAXBOUND " "DP_QC_MULTIPLETEMPSTRINGS " "DP_QC_NUM_FOR_EDICT " -- 2.39.2