]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
DP_QC_GETTIME_CDTRACK: extension to query the playing time of the current cd track.
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 15 Apr 2009 22:38:54 +0000 (22:38 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 15 Apr 2009 22:38:54 +0000 (22:38 +0000)
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
cdaudio.h
prvm_cmds.c
snd_3dras.c
snd_main.c
snd_null.c
sound.h
svvm_cmds.c

index c57be3393c59800225e96bbdb89c4e7d5b788ae9..8a47f7b72f52827552a28e715c3aae76ee7e923e 100644 (file)
@@ -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)
index 2b9729e3f0c26d77ad571f99dcd8cf00d176dadf..ff96a3dbc118013bf6bce906bab601a75a7e4eaa 100644 (file)
--- 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);
index bba2a724fd5c3a0a3686ec166999f897711e9a62..c1be177c09848e343e02748396319cbabc23541b 100644 (file)
@@ -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);
index cff3ec91569eee07b428534daf53353a54023a2f..4df5c09e51a426d1f24ea90bc64364fca5b7b4d6 100644 (file)
@@ -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++;
 }
index 8075c6c1e42a3f1d6d3f6d9378040582dcf800a7..e4a4934a2993458f8044e4bbd6e51e2fa3e00de8 100644 (file)
@@ -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();
+}
+
+
 
 /*
 =================
index c8aa087420ca897e2e9a26e4c44992916bd2099a..ab5b4c6e7f70d39880d70e5444a4b104ce3a87a5 100755 (executable)
@@ -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 c77737e60d6f17d58295042b0a8788056afeeef3..183b71e0607ecf777ac346e2c2bf68ead576d7fd 100644 (file)
--- 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);
index 324082b5925cae853277128a839e8eae782c26dc..bb689358c7f1357c97da7a9c915f61f554a58882 100644 (file)
@@ -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 "