- added SWP's parser for theme music definitions.

Because, why not? The SWCustom I use already contains them.
However, since the original source does not play theme MIDIs - only CDA, there's a switch to disable them.
This commit is contained in:
Christoph Oelckers 2019-12-09 20:12:54 +01:00
parent e62f6cbc20
commit 6ef1f96b40
5 changed files with 69 additions and 26 deletions

View file

@ -1027,20 +1027,8 @@ LEVEL_INFO LevelInfo[MAX_LEVELS+2] = // Shareware
};
#endif*/
const char *ThemeSongs[6] =
{
"THEME.MID",
"ENDLEV3.VOC",
"SERPENT.MID",
"SUMO.MID",
"ZILLA.MID"
"ENDING.MID"
};
int ThemeTrack[6] =
{
2,3,13,13,13,14
};
FString ThemeSongs[6];
int ThemeTrack[6];
void InitNewGame(void)
{
@ -1575,7 +1563,7 @@ void ResetKeyRange(uint8_t* kb, uint8_t* ke)
void PlayTheme()
{
// start music at logo
PlaySong(nullptr, "theme.mid", RedBookSong[0]);
PlaySong(nullptr, ThemeSongs[0], ThemeTrack[0]);
DSPRINTF(ds,"After music stuff...");
MONO_PRINT(ds);
@ -1679,7 +1667,7 @@ void CreditsLevel(void)
while (FX_SoundActive(handle)) ;
// try 14 then 2 then quit
if (!PlaySong(nullptr, nullptr, 14, true))
if (!PlaySong(nullptr, ThemeSongs[5], ThemeTrack[5], true))
{
if (!PlaySong(nullptr, nullptr, 2, true))
{
@ -2220,7 +2208,7 @@ void BonusScreen(PLAYERp pp)
totalclock = ototalclock = 0;
limit = synctics;
PlaySong(nullptr, voc[DIGI_ENDLEV].name, 3);
PlaySong(nullptr, ThemeSongs[1], ThemeTrack[1]);
// special case code because I don't care any more!
if (FinishAnim)
@ -2535,7 +2523,7 @@ void StatScreen(PLAYERp mpp)
inputState.ClearKeyStatus(KEYSC_SPACE);
inputState.ClearKeyStatus(KEYSC_ENTER);
PlaySong(nullptr, voc[DIGI_ENDLEV].name, 3);
PlaySong(nullptr, ThemeSongs[1], ThemeTrack[1]);
while (!inputState.GetKeyStatus(KEYSC_SPACE) && !inputState.GetKeyStatus(KEYSC_ENTER))
{

View file

@ -953,7 +953,7 @@ typedef struct
extern LEVEL_INFO LevelInfo[MAX_LEVELS_REG+2];
extern int ThemeTrack[6]; // w
extern const char *ThemeSongs[6]; //
extern FString ThemeSongs[6]; //
#define MAX_EPISODE_NAME_LEN 24
extern char EpisodeNames[3][MAX_EPISODE_NAME_LEN+2];

View file

@ -404,6 +404,7 @@ enum
CM_MAXAMMO,
CM_DAMAGEMIN,
CM_DAMAGEMAX,
CM_THEME,
CM_SECRET,
CM_QUIT,
};
@ -424,6 +425,7 @@ static const struct _tokset
{ "inventory", CM_INVENTORY },
{ "weapon", CM_WEAPON },
{ "needkey", CM_NEEDKEY },
{ "theme", CM_THEME },
{ "secret", CM_SECRET },
{ "quit", CM_QUIT },
},
@ -475,14 +477,20 @@ static const struct _tokset
{ "maxdamage", CM_DAMAGEMAX },
{ "pickup", CM_AMOUNT },
{ "weaponpickup",CM_WEAPON },
}
;
},
cm_theme_tokens[] = {
{ "song", CM_SONG },
{ "music", CM_SONG },
{ "cdatrack", CM_CDATRACK },
{ "cdtrack", CM_CDATRACK },
};
#define cm_numtokens (sizeof(cm_tokens)/sizeof(cm_tokens[0]))
#define cm_map_numtokens (sizeof(cm_map_tokens)/sizeof(cm_map_tokens[0]))
#define cm_episode_numtokens (sizeof(cm_episode_tokens)/sizeof(cm_episode_tokens[0]))
#define cm_skill_numtokens (sizeof(cm_skill_tokens)/sizeof(cm_skill_tokens[0]))
#define cm_inventory_numtokens (sizeof(cm_inventory_tokens)/sizeof(cm_inventory_tokens[0]))
#define cm_weapons_numtokens (sizeof(cm_weapons_tokens)/sizeof(cm_weapons_tokens[0]))
#define cm_theme_numtokens (sizeof(cm_theme_tokens)/sizeof(cm_theme_tokens[0]))
static int cm_transtok(const char *tok, const struct _tokset *set, const unsigned num)
@ -964,6 +972,51 @@ void LoadCustomInfoFromScript(const char *filename)
}
break;
}
case CM_THEME:
{
char *epnumptr;
char *name = NULL;
int trak = -1;
if (scriptfile_getnumber(script, &curmap)) break; epnumptr = script->ltextptr;
if (scriptfile_getbraces(script, &braceend)) break;
if ((unsigned)--curmap >= 6u)
{
initprintf("Error: theme number %d not in range 1-6 on line %s:%d\n",
curmap, script->filename,
scriptfile_getlinum(script,epnumptr));
script->textptr = braceend;
break;
}
while (script->textptr < braceend)
{
if (!(token = scriptfile_gettoken(script))) break;
if (token == braceend) break;
switch (cm_transtok(token, cm_theme_tokens, cm_theme_numtokens))
{
case CM_SONG:
if (scriptfile_getstring(script, &name)) break;
break;
case CM_CDATRACK:
if (scriptfile_getnumber(script, &trak)) break;
break;
default:
initprintf("Error on line %s:%d\n",
script->filename,
scriptfile_getlinum(script,script->ltextptr));
break;
}
}
if (name)
{
ThemeSongs[curmap] = name;
}
if (trak >= 2)
{
ThemeTrack[curmap] = trak;
}
break;
}
case CM_SECRET:
case CM_QUIT:
default:

View file

@ -308,6 +308,7 @@ InitFX(void)
}
extern short Level;
CVAR(Bool, sw_nothememidi, false, CVAR_ARCHIVE)
SWBOOL PlaySong(const char* mapname, const char* song_file_name, int cdaudio_track, bool isThemeTrack) //(nullptr, nullptr, -1, false) starts the normal level music.
{
@ -316,8 +317,8 @@ SWBOOL PlaySong(const char* mapname, const char* song_file_name, int cdaudio_tra
// Get the music defined for the current level.
}
// Play CD audio if enabled or if this is a theme track.
if (cdaudio_track >= 0 && (mus_redbook || isThemeTrack))
// Play CD audio if enabled.
if (cdaudio_track >= 0 && mus_redbook)
{
FStringf trackname("track%02d.ogg", cdaudio_track);
if (!Mus_Play(nullptr, trackname, true))
@ -325,6 +326,7 @@ SWBOOL PlaySong(const char* mapname, const char* song_file_name, int cdaudio_tra
buildprintf("Can't find CD track %i!\n", cdaudio_track);
}
}
else if (isThemeTrack && sw_nothememidi) return false; // The original SW source only used CD Audio for theme tracks, so this is optional.
return Mus_Play(nullptr, song_file_name, true);
}

View file

@ -883,7 +883,7 @@ BossHealthMeter(void)
serpwasseen = TRUE;
if (!SW_SHAREWARE)
{
PlaySong(nullptr, nullptr, ThemeTrack[2], true);
PlaySong(nullptr, ThemeSongs[2], ThemeTrack[2], true);
}
}
else if (i == 1 && !sumowasseen)
@ -891,7 +891,7 @@ BossHealthMeter(void)
sumowasseen = TRUE;
if (!SW_SHAREWARE)
{
PlaySong(nullptr, nullptr, ThemeTrack[3], true);
PlaySong(nullptr, ThemeSongs[3], ThemeTrack[3], true);
}
}
else if (i == 2 && !zillawasseen)
@ -899,7 +899,7 @@ BossHealthMeter(void)
zillawasseen = TRUE;
if (!SW_SHAREWARE)
{
PlaySong(nullptr, nullptr, ThemeTrack[4], true);
PlaySong(nullptr, ThemeSongs[4], ThemeTrack[4], true);
}
}
}