X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=cd_shared.c;h=89dcbdbf633b8ce55d8cbb671d43613d916c83cd;hp=c0f0514c48cb9fa314af94dd33e5e2a2aa34142f;hb=40e0441442aecf796d118da39837fba123a0dedc;hpb=7c320ed3cd5e1738024b3cd3f1fc305940f88dce diff --git a/cd_shared.c b/cd_shared.c index c0f0514c..89dcbdbf 100644 --- a/cd_shared.c +++ b/cd_shared.c @@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // rights reserved. #include "quakedef.h" +#include "cdaudio.h" +#include "sound.h" #define MAXTRACKS 256 @@ -30,7 +32,7 @@ extern void CDAudio_SysCloseDoor (void); extern int CDAudio_SysGetAudioDiskInfo (void); extern float CDAudio_SysGetVolume (void); extern void CDAudio_SysSetVolume (float volume); -extern int CDAudio_SysPlay (qbyte track); +extern int CDAudio_SysPlay (unsigned char track); extern int CDAudio_SysStop (void); extern int CDAudio_SysPause (void); extern int CDAudio_SysResume (void); @@ -40,14 +42,14 @@ extern int CDAudio_SysStartup (void); extern void CDAudio_SysShutdown (void); // used by menu to ghost CD audio slider -cvar_t cdaudioinitialized = {CVAR_READONLY,"cdaudioinitialized","0"}; +cvar_t cdaudioinitialized = {CVAR_READONLY,"cdaudioinitialized","0","indicates if CD Audio system is active"}; static qboolean wasPlaying = false; static qboolean initialized = false; static qboolean enabled = false; static float cdvolume; -static qbyte remap[MAXTRACKS]; -static qbyte maxTrack; +static unsigned char remap[MAXTRACKS]; +static unsigned char maxTrack; static int faketrack = -1; static float saved_vol = 1.0f; @@ -56,8 +58,9 @@ static float saved_vol = 1.0f; qboolean cdValid = false; qboolean cdPlaying = false; qboolean cdPlayLooping = false; -qbyte cdPlayTrack; +unsigned char cdPlayTrack; +cl_cdstate_t cd; static void CDAudio_Eject (void) { @@ -93,29 +96,30 @@ static int CDAudio_GetAudioDiskInfo (void) } -void CDAudio_Play (qbyte track, qboolean looping) +void CDAudio_Play (unsigned char track, qboolean looping) { sfx_t* sfx; + Host_StartVideo(); + if (!enabled) return; track = remap[track]; if (track < 1) { - Con_DPrintf("CDAudio: Bad track number %u.\n", track); + Con_Printf("CDAudio: Bad track number %u.\n", track); return; } - if (cdPlaying && cdPlayTrack == track) + if (cdPlaying && cdPlayTrack == track && faketrack == -1) return; CDAudio_Stop (); // Try playing a fake track (sound file) first - sfx = S_PrecacheSound (va ("cdtracks/track%02u.wav", track), false, true, false); - // FIXME: perhaps force it to be always %03u (but for compatibility?): - if (!sfx) - sfx = S_PrecacheSound (va ("cdtracks/track%03u.wav", track), false, true, false); + sfx = S_PrecacheSound (va ("cdtracks/track%02u.wav", track), false, false); + if (sfx == NULL || !S_IsSoundPrecached (sfx)) + sfx = S_PrecacheSound (va ("cdtracks/track%03u.wav", track), false, false); if (sfx != NULL) { faketrack = S_StartSound (-1, 0, sfx, vec3_origin, cdvolume, 0); @@ -124,7 +128,7 @@ void CDAudio_Play (qbyte track, qboolean looping) if (looping) S_SetChannelFlag (faketrack, CHANNELFLAG_FORCELOOP, true); S_SetChannelFlag (faketrack, CHANNELFLAG_FULLVOLUME, true); - Con_DPrintf ("Fake CD track %u playing...\n", track); + Con_Printf ("Fake CD track %u playing...\n", track); } } @@ -210,6 +214,8 @@ static void CD_f (void) int ret; int n; + Host_StartVideo(); + if (Cmd_Argc() < 2) return; @@ -263,13 +269,13 @@ static void CD_f (void) if (strcasecmp(command, "play") == 0) { - CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), false); + CDAudio_Play((unsigned char)atoi(Cmd_Argv (2)), false); return; } if (strcasecmp(command, "loop") == 0) { - CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), true); + CDAudio_Play((unsigned char)atoi(Cmd_Argv (2)), true); return; } @@ -314,6 +320,20 @@ static void CD_f (void) Con_Printf("Volume is %f\n", cdvolume); return; } + + Con_Printf("CD commands:\n"); + Con_Printf("cd on - enables CD audio system\n"); + Con_Printf("cd off - stops and disables CD audio system\n"); + Con_Printf("cd reset - resets CD audio system (clears track remapping and re-reads disc information)"); + Con_Printf("cd remap [remap2] [remap3] [...] - chooses (possibly emulated) CD tracks to play when a map asks for a particular track, this has many uses\n"); + Con_Printf("cd close - closes CD tray\n"); + Con_Printf("cd eject - stops playing music and opens CD tray to allow you to change disc\n"); + Con_Printf("cd play - plays selected track in remapping table\n"); + Con_Printf("cd loop - plays and repeats selected track in remapping table\n"); + Con_Printf("cd stop - stops playing current CD track\n"); + Con_Printf("cd pause - pauses CD playback\n"); + Con_Printf("cd resume - unpauses CD playback\n"); + Con_Printf("cd info - prints basic disc information (number of tracks, currently playing track, volume level)\n"); } void CDAudio_SetVolume (float newvol) @@ -370,7 +390,7 @@ int CDAudio_Init (void) Cvar_SetValueQuick(&cdaudioinitialized, true); enabled = true; - Cmd_AddCommand("cd", CD_f); + Cmd_AddCommand("cd", CD_f, "execute a CD drive command (cd on/off/reset/remap/close/play/loop/stop/pause/resume/eject/info) - use cd by itself for usage"); return 0; } @@ -381,22 +401,22 @@ int CDAudio_Startup (void) if (CDAudio_GetAudioDiskInfo()) { - Con_DPrint("CDAudio_Init: No CD in player.\n"); + Con_Print("CDAudio_Init: No CD in player.\n"); cdValid = false; } saved_vol = CDAudio_SysGetVolume (); if (saved_vol < 0.0f) { - Con_DPrint ("Can't get initial CD volume\n"); + Con_Print ("Can't get initial CD volume\n"); saved_vol = 1.0f; } else - Con_DPrintf ("Initial CD volume: %g\n", saved_vol); + Con_Printf ("Initial CD volume: %g\n", saved_vol); initialized = true; - Con_DPrint("CD Audio Initialized\n"); + Con_Print("CD Audio Initialized\n"); return 0; }