ref: 6ec6095cb127421fc648781d0820d23d6e7a58a4
parent: 9a4f30c23a7b87e5f5bf3e4e4039c845cba38d66
author: Simon Howard <fraggle@gmail.com>
date: Sun Oct 6 10:58:44 EDT 2013
Finish implementation of Hexen CD audio music mode. Subversion-branch: /branches/v2-branch Subversion-revision: 2694
--- a/src/hexen/p_setup.c
+++ b/src/hexen/p_setup.c
@@ -671,11 +671,6 @@
=================
*/
-// haleyjd FIXME: CDMUSIC
-#ifdef __WATCOMC__
-extern boolean i_CDMusic;
-#endif
-
void P_SetupLevel(int episode, int map, int playermask, skill_t skill)
{
int i;
@@ -690,15 +685,14 @@
= players[i].itemcount = 0;
}
players[consoleplayer].viewz = 1; // will be set by player think
-
-
- // haleyjd FIXME: CDMUSIC
-#ifdef __WATCOMC__
- if (i_CDMusic == false)
+
+ // Waiting-for-level-load song; not played if playing music from CD
+ // (the seek time will be so long it will just make loading take
+ // longer)
+ if (!cdmusic)
{
- S_StartSongName("chess", true); // Waiting-for-level-load song
+ S_StartSongName("chess", true);
}
-#endif
Z_FreeTags(PU_LEVEL, PU_PURGELEVEL - 1);
--- a/src/hexen/s_sound.c
+++ b/src/hexen/s_sound.c
@@ -27,6 +27,7 @@
#include "i_cdmus.h"
#include "i_sound.h"
#include "i_system.h"
+#include "i_timer.h"
#include "m_argv.h"
#include "m_misc.h"
#include "r_local.h"
@@ -41,12 +42,21 @@
void S_ShutDown(void);
-boolean i_CDMusic;
-int i_CDTrack;
-int i_CDCurrentTrack;
-int i_CDMusicLength;
-int oldTic;
+// If true, CD music playback is enabled (snd_musicdevice == SNDDEVICE_CD
+// and CD initialization succeeded).
+boolean cdmusic;
+// Track number of a track to play explicitly chosen by the
+// player using cheats. A value of zero means no track chosen:
+static int cd_custom_track = 0;
+
+// Currently playing track:
+static int cd_current_track = 0;
+
+// Time (MS) at which the currently-playing CD track will finish playing
+// and should be looped. Zero if we are not currently playing a track:
+static int cd_track_end_time = 0;
+
/*
===============================================================================
@@ -93,6 +103,52 @@
//==========================================================================
//
+// Returns true if we are playing a looping CD track and it is time to
+// restart it.
+//
+//==========================================================================
+
+static boolean ShouldRestartCDTrack(void)
+{
+ return cd_track_end_time != 0 && I_GetTimeMS() > cd_track_end_time;
+}
+
+//==========================================================================
+//
+// Start playing a CD track. Returns true for success.
+//
+//==========================================================================
+
+static boolean StartCDTrack(int track, boolean loop)
+{
+ // Already playing? If so, don't bother.
+
+ if (track == cd_current_track && !ShouldRestartCDTrack())
+ {
+ return true;
+ }
+
+ if (I_CDMusPlay(track))
+ {
+ return false;
+ }
+
+ cd_current_track = track;
+
+ if (loop)
+ {
+ cd_track_end_time = I_GetTimeMS() + 1000 * I_CDMusTrackLength(track);
+ }
+ else
+ {
+ cd_track_end_time = 0;
+ }
+
+ return true;
+}
+
+//==========================================================================
+//
// S_StartSong
//
//==========================================================================
@@ -104,33 +160,20 @@
int length;
int track;
- if (i_CDMusic)
- { // Play a CD track, instead
- if (i_CDTrack)
- { // Default to the player-chosen track
- track = i_CDTrack;
+ // If we're in CD music mode, play a CD track, instead:
+ if (cdmusic)
+ {
+ // Default to the player-chosen track
+ if (cd_custom_track != 0)
+ {
+ track = cd_custom_track;
}
else
{
track = P_GetMapCDTrack(gamemap);
}
- if (track == i_CDCurrentTrack && i_CDMusicLength > 0)
- {
- return;
- }
- if (!I_CDMusPlay(track))
- {
- if (loop)
- {
- i_CDMusicLength = 35 * I_CDMusTrackLength(track);
- oldTic = gametic;
- }
- else
- {
- i_CDMusicLength = -1;
- }
- i_CDCurrentTrack = track;
- }
+
+ StartCDTrack(track, loop);
}
else
{
@@ -164,6 +207,44 @@
//==========================================================================
//
+// Play a custom-chosen music track selected by the player.
+//
+// Returns true for success.
+//
+//==========================================================================
+
+boolean S_StartCustomCDTrack(int tracknum)
+{
+ boolean result;
+
+ result = StartCDTrack(tracknum, true);
+
+ if (result)
+ {
+ cd_custom_track = tracknum;
+ }
+
+ return result;
+}
+
+//==========================================================================
+//
+// Get the currently-playing CD track; returns -1 if not playing.
+//
+//==========================================================================
+
+int S_GetCurrentCDTrack(void)
+{
+ if (!cdmusic || cd_current_track == 0)
+ {
+ return -1;
+ }
+
+ return cd_current_track;
+}
+
+//==========================================================================
+//
// S_StartSongName
//
//==========================================================================
@@ -178,7 +259,7 @@
{
return;
}
- if (i_CDMusic)
+ if (cdmusic)
{
cdTrack = 0;
@@ -198,7 +279,7 @@
{
cdTrack = P_GetCDEnd2Track();
}
- else if (!strcmp(songLump, "chess") && !i_CDTrack)
+ else if (!strcmp(songLump, "chess") && cd_custom_track == 0)
{
cdTrack = P_GetCDEnd3Track();
}
@@ -208,24 +289,11 @@
cdTrack = P_GetCDStartTrack();
}
*/
- if (!cdTrack || (cdTrack == i_CDCurrentTrack && i_CDMusicLength > 0))
+ if (!cdTrack)
{
- return;
+ cd_custom_track = 0;
+ StartCDTrack(cdTrack, loop);
}
- if (!I_CDMusPlay(cdTrack))
- {
- if (loop)
- {
- i_CDMusicLength = 35 * I_CDMusTrackLength(cdTrack);
- oldTic = gametic;
- }
- else
- {
- i_CDMusicLength = -1;
- }
- i_CDCurrentTrack = cdTrack;
- i_CDTrack = false;
- }
}
else
{
@@ -595,7 +663,7 @@
void S_PauseSound(void)
{
- if (i_CDMusic)
+ if (cdmusic)
{
I_CDMusStop();
}
@@ -613,7 +681,7 @@
void S_ResumeSound(void)
{
- if (i_CDMusic)
+ if (cdmusic)
{
I_CDMusResume();
}
@@ -638,12 +706,13 @@
int absx;
int absy;
-#ifdef CDMUSIC
- if (i_CDMusic)
+ // If we are looping a CD track, we need to check if it has
+ // finished playing and needs to restart.
+ if (cdmusic && ShouldRestartCDTrack())
{
- I_UpdateCDMusic();
+ StartCDTrack(cd_current_track, true);
}
-#endif
+
if (snd_MaxVolume == 0)
{
return;
@@ -739,21 +808,21 @@
I_PrecacheSounds(S_sfx, NUMSFX);
-#ifdef CDMUSIC
-//TODO
// Attempt to setup CD music
- if (snd_MusicDevice == snd_CDMUSIC)
+ if (snd_musicdevice == SNDDEVICE_CD)
{
ST_Message(" Attempting to initialize CD Music: ");
if (!cdrom)
{
- i_CDMusic = (I_CDMusInit() != -1);
+ cdmusic = (I_CDMusInit() != -1);
}
else
- { // The user is trying to use the cdrom for both game and music
- i_CDMusic = false;
+ {
+ // The user is trying to use the cdrom for both game and music
+ cdmusic = false;
}
- if (i_CDMusic)
+
+ if (cdmusic)
{
ST_Message("initialized.\n");
}
@@ -762,7 +831,6 @@
ST_Message("failed.\n");
}
}
-#endif
}
//==========================================================================
@@ -830,7 +898,7 @@
void S_SetMusicVolume(void)
{
- if (i_CDMusic)
+ if (cdmusic)
{
I_CDMusSetVolume(snd_MusicVolume * 16); // 0-255
}
@@ -840,7 +908,7 @@
}
if (snd_MusicVolume == 0)
{
- if (!i_CDMusic)
+ if (!cdmusic)
{
I_PauseSong();
}
@@ -848,7 +916,7 @@
}
else if (MusicPaused)
{
- if (!i_CDMusic)
+ if (!cdmusic)
{
I_ResumeSong();
}
@@ -867,7 +935,7 @@
I_StopSong();
I_UnRegisterSong(RegisteredSong);
I_ShutdownSound();
- if (i_CDMusic)
+ if (cdmusic)
{
I_CDMusStop();
}
--- a/src/hexen/s_sound.h
+++ b/src/hexen/s_sound.h
@@ -79,6 +79,7 @@
extern int snd_MaxVolume;
extern int snd_MusicVolume;
extern int snd_Channels;
+extern boolean cdmusic;
void S_Start(void);
void S_StartSound(mobj_t * origin, int sound_id);
@@ -95,5 +96,7 @@
void S_GetChannelInfo(SoundInfo_t * s);
void S_SetMusicVolume(void);
boolean S_GetSoundPlayingInfo(mobj_t * mobj, int sound_id);
+boolean S_StartCustomCDTrack(int tracknum);
+int S_GetCurrentCDTrack(void);
#endif
--- a/src/hexen/sb_bar.c
+++ b/src/hexen/sb_bar.c
@@ -26,6 +26,7 @@
// HEADER FILES ------------------------------------------------------------
#include "h2def.h"
+#include "i_cdmus.h"
#include "i_video.h"
#include "m_bbox.h"
#include "m_cheat.h"
@@ -34,8 +35,6 @@
#include "s_sound.h"
#include "v_video.h"
-#include "i_sound.h" // For CD stuff
-
// TYPES -------------------------------------------------------------------
typedef struct Cheat_s
@@ -96,15 +95,6 @@
extern int ArmorIncrement[NUMCLASSES][NUMARMOR];
extern int AutoArmorSave[NUMCLASSES];
-// haleyjd FIXME: CDMUSIC
-#ifdef __WATCOMC__
-extern boolean i_CDMusic;
-extern int i_CDMusicLength;
-extern int i_CDTrack;
-extern int i_CDCurrentTrack;
-extern int oldTic;
-#endif
-
// PUBLIC DATA DECLARATIONS ------------------------------------------------
boolean DebugSound; // Debug flag for displaying sound info
@@ -113,11 +103,6 @@
int inv_ptr;
int ArtifactFlash;
-// haleyjd FIXME: CDMUSIC
-#ifndef __WATCOMC__
-boolean i_CDMusic; // in Watcom, defined in i_ibm
-#endif
-
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static int DisplayTicker = 0;
@@ -1517,7 +1502,7 @@
else if (netgame)
{ // change CD track is the only cheat available in deathmatch
eat = false;
- if (i_CDMusic)
+ if (cdmusic)
{
if (CheatAddKey(&Cheats[0], key, &eat))
{
@@ -1931,22 +1916,21 @@
static void CheatTrackFunc1(player_t * player, Cheat_t * cheat)
{
- // haleyjd FIXME: CDMUSIC
-#ifdef __WATCOMC__
char buffer[80];
- if (!i_CDMusic)
+ if (!cdmusic)
{
return;
}
+
if (I_CDMusInit() == -1)
{
P_SetMessage(player, "ERROR INITIALIZING CD", true);
}
+
sprintf(buffer, "ENTER DESIRED CD TRACK (%.2d - %.2d):\n",
I_CDMusFirstTrack(), I_CDMusLastTrack());
P_SetMessage(player, buffer, true);
-#endif
}
//===========================================================================
@@ -1957,8 +1941,6 @@
static void CheatTrackFunc2(player_t * player, Cheat_t * cheat)
{
- // haleyjd FIXME: CDMUSIC
-#ifdef __WATCOMC__
char buffer[80];
int track;
char args[2];
@@ -1965,10 +1947,11 @@
cht_GetParam(cheat->seq, args);
- if (!i_CDMusic)
+ if (!cdmusic)
{
return;
}
+
track = (args[0] - '0') * 10 + (args[1] - '0');
if (track < I_CDMusFirstTrack() || track > I_CDMusLastTrack())
{
@@ -1975,23 +1958,21 @@
P_SetMessage(player, "INVALID TRACK NUMBER\n", true);
return;
}
- if (track == i_CDCurrentTrack)
+
+ if (track == S_GetCurrentCDTrack())
{
return;
}
- if (I_CDMusPlay(track))
+
+ if (!S_StartCustomCDTrack(track))
{
sprintf(buffer, "ERROR WHILE TRYING TO PLAY CD TRACK: %.2d\n", track);
P_SetMessage(player, buffer, true);
}
else
- { // No error encountered while attempting to play the track
+ {
+ // No error encountered while attempting to play the track
sprintf(buffer, "PLAYING TRACK: %.2d\n", track);
P_SetMessage(player, buffer, true);
- i_CDMusicLength = 35 * I_CDMusTrackLength(track);
- oldTic = gametic;
- i_CDTrack = track;
- i_CDCurrentTrack = track;
}
-#endif
}
--- a/src/i_cdmus.c
+++ b/src/i_cdmus.c
@@ -42,8 +42,20 @@
{
int drive_num = 0;
+ // The initialize function is re-invoked when the CD track play cheat
+ // is used, so use the opportunity to call SDL_CDStatus() to update
+ // the status of the drive.
+ // TODO: Check this actually works.
+
+ if (cd_handle != NULL)
+ {
+ SDL_CDStatus(cd_handle);
+ cd_Error = 0;
+ return 0;
+ }
+
// TODO: config variable to control CDROM to use.
-
+
cd_handle = SDL_CDOpen(drive_num);
if (cd_handle == NULL)
@@ -53,6 +65,8 @@
return -1;
}
+ printf("I_CDMusInit: Using CD-ROM drive: %s\n", SDL_CDName(drive_num));
+
if (!CD_INDRIVE(cd_handle->status))
{
fprintf(stderr, "I_CDMusInit: '%s': no CD in drive.\n",
@@ -139,8 +153,7 @@
}
}
- /* Don't know? */
-
+ // Don't know?
cd_Error = 1;
return -1;
--- a/src/setup/sound.c
+++ b/src/setup/sound.c
@@ -131,6 +131,7 @@
snd_musicdevice = SNDDEVICE_GUS;
break;
case MUSICMODE_CD:
+ snd_musicdevice = SNDDEVICE_CD;
break;
}
}