mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-03 06:20:57 +00:00
cd_sdl.c: Simplified, making it similar to cd_linux.c or cd_bsd.c by
performing checks every two seconds in CDAudio_Update() and caching the last check time. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@498 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
433f753405
commit
0fd1150b47
1 changed files with 5 additions and 23 deletions
|
@ -45,7 +45,6 @@ static qboolean enabled = true;
|
||||||
static qboolean playLooping = false;
|
static qboolean playLooping = false;
|
||||||
static byte remap[100];
|
static byte remap[100];
|
||||||
static byte playTrack;
|
static byte playTrack;
|
||||||
static double endOfTrack = -1.0, pausetime = -1.0;
|
|
||||||
static SDL_CD *cd_handle;
|
static SDL_CD *cd_handle;
|
||||||
static int cd_dev = -1;
|
static int cd_dev = -1;
|
||||||
static float old_cdvolume;
|
static float old_cdvolume;
|
||||||
|
@ -78,8 +77,6 @@ static int CDAudio_GetAudioDiskInfo(void)
|
||||||
|
|
||||||
int CDAudio_Play(byte track, qboolean looping)
|
int CDAudio_Play(byte track, qboolean looping)
|
||||||
{
|
{
|
||||||
int len_m, len_s, len_f;
|
|
||||||
|
|
||||||
if (!cd_handle || !enabled)
|
if (!cd_handle || !enabled)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -123,18 +120,6 @@ int CDAudio_Play(byte track, qboolean looping)
|
||||||
playTrack = track;
|
playTrack = track;
|
||||||
playing = true;
|
playing = true;
|
||||||
|
|
||||||
FRAMES_TO_MSF(cd_handle->track[track-1].length, &len_m, &len_s, &len_f);
|
|
||||||
endOfTrack = realtime + ((double)len_m * 60.0) + (double)len_s + (double)len_f / (double)CD_FPS;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Add the pregap for the next track. This means that disc-at-once CDs
|
|
||||||
* won't loop smoothly, but they wouldn't anyway so it doesn't really
|
|
||||||
* matter. SDL doesn't give us pregap information anyway, so you'll
|
|
||||||
* just have to live with it.
|
|
||||||
*/
|
|
||||||
endOfTrack += 2.0;
|
|
||||||
pausetime = -1.0;
|
|
||||||
|
|
||||||
if (bgmvolume.value == 0) /* don't bother advancing */
|
if (bgmvolume.value == 0) /* don't bother advancing */
|
||||||
CDAudio_Pause ();
|
CDAudio_Pause ();
|
||||||
|
|
||||||
|
@ -154,8 +139,6 @@ void CDAudio_Stop(void)
|
||||||
|
|
||||||
wasPlaying = false;
|
wasPlaying = false;
|
||||||
playing = false;
|
playing = false;
|
||||||
pausetime = -1.0;
|
|
||||||
endOfTrack = -1.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDAudio_Pause(void)
|
void CDAudio_Pause(void)
|
||||||
|
@ -171,7 +154,6 @@ void CDAudio_Pause(void)
|
||||||
|
|
||||||
wasPlaying = playing;
|
wasPlaying = playing;
|
||||||
playing = false;
|
playing = false;
|
||||||
pausetime = realtime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDAudio_Resume(void)
|
void CDAudio_Resume(void)
|
||||||
|
@ -188,8 +170,6 @@ void CDAudio_Resume(void)
|
||||||
if (SDL_CDResume(cd_handle) == -1)
|
if (SDL_CDResume(cd_handle) == -1)
|
||||||
Con_Printf ("Unable to resume CD-ROM: %s\n", SDL_GetError());
|
Con_Printf ("Unable to resume CD-ROM: %s\n", SDL_GetError());
|
||||||
playing = true;
|
playing = true;
|
||||||
endOfTrack += realtime - pausetime;
|
|
||||||
pausetime = -1.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CD_f (void)
|
static void CD_f (void)
|
||||||
|
@ -366,6 +346,8 @@ static qboolean CDAudio_SetVolume (float value)
|
||||||
void CDAudio_Update(void)
|
void CDAudio_Update(void)
|
||||||
{
|
{
|
||||||
CDstatus curstat;
|
CDstatus curstat;
|
||||||
|
Uint32 timechk;
|
||||||
|
static Uint32 lastchk;
|
||||||
|
|
||||||
if (!cd_handle || !enabled)
|
if (!cd_handle || !enabled)
|
||||||
return;
|
return;
|
||||||
|
@ -373,14 +355,14 @@ void CDAudio_Update(void)
|
||||||
if (old_cdvolume != bgmvolume.value)
|
if (old_cdvolume != bgmvolume.value)
|
||||||
CDAudio_SetVolume (bgmvolume.value);
|
CDAudio_SetVolume (bgmvolume.value);
|
||||||
|
|
||||||
if (playing && realtime > endOfTrack)
|
timechk = SDL_GetTicks ();
|
||||||
|
if (playing && lastchk < timechk)
|
||||||
{
|
{
|
||||||
// curstat = cd_handle->status;
|
lastchk = timechk + 2000; /* two seconds between chks */
|
||||||
curstat = SDL_CDStatus(cd_handle);
|
curstat = SDL_CDStatus(cd_handle);
|
||||||
if (curstat != CD_PLAYING && curstat != CD_PAUSED)
|
if (curstat != CD_PLAYING && curstat != CD_PAUSED)
|
||||||
{
|
{
|
||||||
playing = false;
|
playing = false;
|
||||||
endOfTrack = -1.0;
|
|
||||||
if (playLooping)
|
if (playLooping)
|
||||||
CDAudio_Play(playTrack, true);
|
CDAudio_Play(playTrack, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue