diff --git a/src/dehacked.c b/src/dehacked.c index ee4b50684..b8d5f72a7 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9184,8 +9184,6 @@ int LUA_EnumLib(lua_State *L) PUSHGETTER(globalweather, u8); PUSHGETTER(levelskynum, i32); PUSHGETTER(globallevelskynum, i32); - PUSHGETTER(mapmusflags, u16); - PUSHGETTER(mapmusposition, u32); PUSHGETTER(gravity, fxp); PUSHGETTER(gamespeed, u8); PUSHGETTER(encoremode, bool); @@ -9200,9 +9198,19 @@ int LUA_EnumLib(lua_State *L) PUSHGETTER(racecountdown, u32); PUSHGETTER(exitcountdown, u32); + lua_pushcfunction(L, lua_glib_new_getter); + lua_pushliteral(L, "mapmusflags"); + lua_glib_push_u16_getter(L, &mapmusic.flags); + lua_call(L, 2, 0); + + lua_pushcfunction(L, lua_glib_new_getter); + lua_pushliteral(L, "mapmusposition"); + lua_glib_push_u32_getter(L, &mapmusic.position); + lua_call(L, 2, 0); + lua_pushcfunction(L, lua_glib_new_getter); lua_pushliteral(L, "mapmusname"); - lua_glib_push_str_getter(L, mapmusname); + lua_glib_push_str_getter(L, mapmusic.name); lua_call(L, 2, 0); lua_pushcfunction(L, lua_glib_new_getter); diff --git a/src/doomstat.h b/src/doomstat.h index e68f1da89..73e0b17b4 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -30,16 +30,26 @@ // ============================= // Selected by user. -extern INT16 gamemap; -extern char mapmusname[7]; -extern UINT16 mapmusflags; -extern UINT32 mapmusposition; -extern UINT32 mapmusresume; + +typedef struct +{ + char name[7]; // Music name, up to 6-character name + void *data; // Music lump + UINT16 flags; // Track and reset bit + boolean looping; // Is this music looping? + UINT32 position; // Position to jump to + UINT32 resume; // Saved Position when music was stopped + UINT32 fadeinms; // Fade in time in ms (used for queue) +} music_t; + +extern music_t mapmusic; + #define MUSIC_TRACKMASK 0x0FFF // ----************ #define MUSIC_RELOADRESET 0x8000 // *--------------- #define MUSIC_FORCERESET 0x4000 // -*-------------- // Use other bits if necessary. +extern INT16 gamemap; extern INT16 maptol; extern UINT8 globalweather; extern INT32 curWeather; diff --git a/src/g_game.c b/src/g_game.c index c218527a0..7b2b147df 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -84,10 +84,7 @@ static void G_DoStartVote(void); static void G_ResetDemoPlayback(char *pdemoname); -char mapmusname[7]; // Music name -UINT16 mapmusflags; // Track and reset bit -UINT32 mapmusposition; // Position to jump to -UINT32 mapmusresume; +music_t mapmusic; INT16 gamemap = 1; INT16 maptol; @@ -2260,13 +2257,9 @@ void G_PlayerReborn(INT32 player) if (p-players == consoleplayer) { - if (mapmusflags & MUSIC_RELOADRESET) + if (mapmusic.flags & MUSIC_RELOADRESET) { - strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname, 7); - mapmusname[6] = 0; - mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); - mapmusposition = mapheaderinfo[gamemap-1]->muspos; - mapmusresume = 0; + S_HandleReloadResetMusic(); songcredit = true; } } @@ -4024,7 +4017,7 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool globalweather = mapheaderinfo[gamemap-1]->weather; // Don't carry over custom music change to another map. - mapmusflags |= MUSIC_RELOADRESET; + mapmusic.flags |= MUSIC_RELOADRESET; automapactive = false; imcontinuing = false; diff --git a/src/p_saveg.c b/src/p_saveg.c index dc8dfd39b..3525f58e3 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3348,7 +3348,7 @@ FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(savebuffer_t *save, bool // tell the sound code to reset the music since we're skipping what // normally sets this flag if (!reloading) - mapmusflags |= MUSIC_RELOADRESET; + mapmusic.flags |= MUSIC_RELOADRESET; G_SetGamestate(READINT16(save->p)); diff --git a/src/s_sound.c b/src/s_sound.c index 7061eaea3..abd5afbd9 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -113,13 +113,15 @@ consvar_t cv_resume = {"resume", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0 consvar_t cv_fading = {"fading", "Off", CV_SAVE|CV_CALL, CV_OnOff, Bird_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_birdmusic = {"birdmusicstuff", "No", CV_SAVE|CV_CALL, CV_YesNo, Bird_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; - consvar_t cv_keepmusic = {"keepmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skipintromusic = {"skipintromusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; //consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -boolean keepmusic = false; // keep the current music on map restart +boolean keepmapmusic = false; // keep the current music on map restart boolean skipintromus = false; // skip the intro fanfare +static boolean resumekeepmusic = false; +static music_t keepmusic; +static void S_SetKeepMusResume(void); #ifdef HAVE_OPENMPT openmpt_module *openmpt_mhandle = NULL; @@ -342,7 +344,7 @@ lumpnum_t S_GetSfxLumpNum(sfxinfo_t *sfx) if (sfxlump != LUMPERROR) return sfxlump; - strlcpy(namebuf, sfx->name, sizeof namebuf); + strlcpy(namebuf, sfx->name, sizeof(namebuf)); sfxlump = W_CheckNumForName(namebuf); if (sfxlump != LUMPERROR) @@ -1192,17 +1194,10 @@ const char *compat_special_music_slots[16] = }; #endif -static char music_name[7]; // up to 6-character name -static void *music_data; -static UINT16 music_flags; -static boolean music_looping; -static consvar_t *music_refade_cv; +static music_t music; +static music_t queue; -static char queue_name[7]; -static UINT16 queue_flags; -static boolean queue_looping; -static UINT32 queue_position; -static UINT32 queue_fadeinms; +static consvar_t *music_refade_cv; /// ------------------------ /// Music Definitions @@ -1474,7 +1469,7 @@ void S_ShowSpecifiedMusicCredit(const char *musname) // void S_ShowMusicCredit(void) { - S_ShowSpecifiedMusicCredit(music_name); + S_ShowSpecifiedMusicCredit(music.name); } musicdef_t **soundtestdefs = NULL; @@ -1553,7 +1548,7 @@ musictype_t S_MusicType(void) const char *S_MusicName(void) { - return music_name; + return music.name; } boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping) @@ -1561,10 +1556,10 @@ boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping) if (!I_SongPlaying()) return false; - strncpy(mname, music_name, 7); + strncpy(mname, music.name, 7); mname[6] = 0; - *mflags = music_flags; - *looping = music_looping; + *mflags = music.flags; + *looping = music.looping; return (boolean)mname[0]; } @@ -1654,9 +1649,9 @@ static boolean S_LoadMusic(const char *mname) if (I_LoadSong(mdata, W_LumpLength(mlumpnum))) { - strncpy(music_name, mname, 7); - music_name[6] = 0; - music_data = mdata; + strncpy(music.name, mname, 7); + music.name[6] = 0; + music.data = mdata; return true; } else @@ -1668,13 +1663,13 @@ static void S_UnloadMusic(void) I_UnloadSong(); #ifndef HAVE_SDL //SDL uses RWOPS - Z_ChangeTag(music_data, PU_CACHE); + Z_ChangeTag(music.data, PU_CACHE); #endif - music_data = NULL; + music.data = NULL; - music_name[0] = 0; - music_flags = 0; - music_looping = false; + music.name[0] = 0; + music.flags = 0; + music.looping = false; music_refade_cv = 0; } @@ -1703,21 +1698,21 @@ static boolean S_PlayMusic(boolean looping, UINT32 fadeinms) static void S_QueueMusic(const char *mmusic, UINT16 mflags, boolean looping, UINT32 position, UINT32 fadeinms) { - strncpy(queue_name, mmusic, 7); - queue_flags = mflags; - queue_looping = looping; - queue_position = position; - queue_fadeinms = fadeinms; + strncpy(queue.name, mmusic, 7); + queue.flags = mflags; + queue.looping = looping; + queue.position = position; + queue.fadeinms = fadeinms; } static void S_ClearQueue(void) { - queue_name[0] = queue_flags = queue_looping = queue_position = queue_fadeinms = 0; + queue.name[0] = queue.flags = queue.looping = queue.position = queue.fadeinms = 0; } static void S_ChangeMusicToQueue(void) { - S_ChangeMusicEx(queue_name, queue_flags, queue_looping, queue_position, 0, queue_fadeinms); + S_ChangeMusicEx(queue.name, queue.flags, queue.looping, queue.position, 0, queue.fadeinms); S_ClearQueue(); } @@ -1746,7 +1741,7 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 strncpy(newmusic, mmusic, 6); strncpy(checkmusic, mmusic, 6); - if (LUA_HookMusicChange(music_name, &hook_param)) + if (LUA_HookMusicChange(music.name, &hook_param)) return; // No Music (empty string) @@ -1761,12 +1756,12 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 if (prefadems && S_MusicPlaying()) // queue music change for after fade // allow even if the music is the same { - CONS_Debug(DBG_DETAILED, "Now fading out song %s\n", music_name); + CONS_Debug(DBG_DETAILED, "Now fading out song %s\n", music.name); S_QueueMusic(newmusic, mflags, looping, position, fadeinms); I_FadeSong(0, prefadems, S_ChangeMusicToQueue); return; } - else if (strnicmp(music_name, newmusic, 6) || (mflags & MUSIC_FORCERESET)) + else if (strnicmp(music.name, newmusic, 6) || (mflags & MUSIC_FORCERESET)) { CONS_Debug(DBG_DETAILED, "Now playing song %s\n", newmusic); @@ -1778,8 +1773,8 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 return; } - music_flags = mflags; - music_looping = looping; + music.flags = mflags; + music.looping = looping; if (!S_PlayMusic(looping, fadeinms)) { @@ -1819,7 +1814,9 @@ void S_StopMusic(void) || demo.title) // SRB2Kart: Demos don't interrupt title screen music return; - mapmusresume = (cv_birdmusic.value && (strcasecmp(music_name, mapmusname) == 0)) ? I_GetSongPosition() : 0; + mapmusic.resume = (cv_birdmusic.value && (strcasecmp(music.name, mapmusic.name) == 0)) ? I_GetSongPosition() : 0; + + S_SetKeepMusResume(); if (I_SongPaused()) I_ResumeSong(); @@ -1946,9 +1943,13 @@ static const char *musicexception_list[] = { // check if the current music is smth we dont want to keep (vote music, etc) static boolean S_CheckMusicException(void) { + if (stricmp(music.name, mapmusic.name)) + return true; + + // in case somehow the mapmusic was replaced with smth we dont want to keep for (size_t i = 0; i < sizeof(musicexception_list)/sizeof(musicexception_list[0]); i++) { - if (!stricmp(music_name, musicexception_list[i]) || !stricmp(checkmusic, musicexception_list[i])) + if (!stricmp(music.name, musicexception_list[i]) || !stricmp(checkmusic, musicexception_list[i])) { return true; } @@ -1959,28 +1960,94 @@ static boolean S_CheckMusicException(void) void S_ResetKeepAndSpecialMus(void) { - keepmusic = skipintromus = false; + keepmapmusic = skipintromus = false; +} + +// saves the current song position everytime a song stops +// so we can resume it in some cases +static void S_SetKeepMusResume(void) +{ + keepmusic.resume = 0; + + if (strcasecmp(music.name, mapmusic.name) == 0) + { + keepmusic.resume = I_GetSongPosition(); + } } // determine if we should keep the music on a map restart +// this gets called BEFORE the level gets loaded in G_DoLoadLevel void S_KeepMusic(void) { - static INT16 oldmap = 0; + static INT16 oldmap = -1; static boolean oldencore = false; - if (!cv_keepmusic.value || gamestate != GS_LEVEL || music_name[0] == 0) + keepmapmusic = resumekeepmusic = false; + + if (!cv_keepmusic.value) { - keepmusic = false; + return; } - else if (oldmap == gamemap && oldencore == encoremode) + + // copy over mapmusicname stuff into temporary var + memset(keepmusic.name, 0, sizeof(keepmusic.name)); + strlcpy(keepmusic.name, mapmusic.name, sizeof(keepmusic.name)); + keepmusic.name[6] = 0; + + if (oldmap == gamemap && oldencore == encoremode) { - keepmusic = !S_CheckMusicException(); + const boolean musicchanged = S_CheckMusicException(); + + resumekeepmusic = (musicchanged && keepmusic.resume); + keepmapmusic = (!musicchanged || resumekeepmusic); } oldencore = encoremode; oldmap = gamemap; } +// Sets up the map music in case it should be reloaded +// Special case for keep music +void S_HandleReloadResetMusic(void) +{ + if (!(mapmusic.flags & MUSIC_RELOADRESET)) + return; + + // replace mapmusic with our saved keepmusic stuff + if (keepmapmusic) + { + // this is horrible, but oh well + strlcpy(mapmusic.name, keepmusic.name, sizeof(mapmusic.name)); + } + else + { + strlcpy(mapmusic.name, mapheaderinfo[gamemap-1]->musname, sizeof(mapmusic.name)); + } + + mapmusic.name[6] = 0; + mapmusic.flags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); + mapmusic.position = mapheaderinfo[gamemap-1]->muspos; + mapmusic.resume = 0; +} + +static boolean S_SkipIntroMusic(void) +{ + boolean skip = cv_skipintromusic.value; + + if (!skip) + return false; + + char *maptitle = G_BuildMapTitle(gamemap); // Zzz... + + // check if menu music is playing, otherwise it may continue playing + if (!stricmp(music.name, "titles") || (maptitle && (!stricmp(maptitle, "Wandering Falls")))) // wandering balls changes its song when the race starts Zzz... + skip = false; + + Z_Free(maptitle); + + return skip; +} + // // Per level startup code. // Kills playing sounds at start of level, @@ -1988,40 +2055,29 @@ void S_KeepMusic(void) // void S_InitMapMusic(void) { - if (mapmusflags & MUSIC_RELOADRESET) - { - strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname, 7); - mapmusname[6] = 0; - mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); - mapmusposition = mapheaderinfo[gamemap-1]->muspos; - mapmusresume = 0; - } + S_HandleReloadResetMusic(); - if (keepmusic) + if (keepmapmusic) + { + // this is kinda silly, but we can use it to fade back into the map song at the saved point, should the current music be different from the map music + if (resumekeepmusic) + { + S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, keepmusic.resume, 0, 500); + } return; + } // Starting ambience should always be restarted // lug: but not when we keep the map music lol S_StopMusic(); - if (cv_skipintromusic.value) - { - char *maptitle = G_BuildMapTitle(gamemap); - // for some reason, occasionally the title screen music doesent seem to be reset in time, so skipping the intro may make it just continue playing it instead, weird.. - skipintromus = true; - if (!stricmp(music_name, "titles") || (maptitle && (!stricmp(maptitle, "Wandering Falls")))) // thanks diggle! - skipintromus = false; - - if (maptitle) - Z_Free(maptitle); - } + skipintromus = S_SkipIntroMusic(); if (skipintromus) return; if (leveltime < MUSICSTARTTIME) // SRB2Kart S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); - //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); } void S_StartMapMusic(void) @@ -2030,15 +2086,18 @@ void S_StartMapMusic(void) if (leveltime > MUSICSTARTTIME) return; - if (keepmusic) + if (keepmapmusic) + { return; + } if (skipintromus) { if (leveltime < starttime) - S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); - if (leveltime == MUSICSTARTTIME) + S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, mapmusic.position, 0, 0); + else if (leveltime == MUSICSTARTTIME) S_ShowMusicCredit(); + return; } @@ -2048,7 +2107,7 @@ void S_StartMapMusic(void) S_StopMusic(); else if (leveltime == MUSICSTARTTIME) // Plays the music after the starting countdown. { - S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); + S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, mapmusic.position, 0, 0); S_ShowMusicCredit(); } } @@ -2098,7 +2157,7 @@ static void Command_Tunes_f(void) if (!strcasecmp(tunearg, "-show")) { CONS_Printf(M_GetText("The current tune is: %s [track %d]\n"), - mapmusname, (mapmusflags & MUSIC_TRACKMASK)); + mapmusic.name, (mapmusic.flags & MUSIC_TRACKMASK)); return; } if (!strcasecmp(tunearg, "-none")) @@ -2126,19 +2185,19 @@ static void Command_Tunes_f(void) track = (UINT16)atoi(COM_Argv(2))-1; if (tunenum) - snprintf(mapmusname, 7, "%sM", G_BuildMapName(tunenum)); + snprintf(mapmusic.name, 7, "%sM", G_BuildMapName(tunenum)); else - strncpy(mapmusname, tunearg, 7); + strncpy(mapmusic.name, tunearg, 7); if (argc > 4) position = (UINT32)atoi(COM_Argv(4)); - mapmusname[6] = 0; - mapmusflags = (track & MUSIC_TRACKMASK); - mapmusposition = position; - mapmusresume = 0; + mapmusic.name[6] = 0; + mapmusic.flags = (track & MUSIC_TRACKMASK); + mapmusic.position = position; + mapmusic.resume = 0; - S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); + S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, mapmusic.position, 0, 0); if (argc > 3) { @@ -2186,7 +2245,7 @@ static void Command_RestartMusic_f(void) //same as RestartAudio but only music g static void Command_ShowMusicCredit_f(void) { - const char *musname = music_name; + const char *musname = music.name; if (COM_Argc() > 1) { diff --git a/src/s_sound.h b/src/s_sound.h index a22e0aaeb..92e206e1b 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -71,7 +71,7 @@ extern consvar_t cv_birdmusic; extern consvar_t cv_keepmusic; extern consvar_t cv_skipintromusic; //extern consvar_t cv_ignoremusicchanges; -extern boolean keepmusic; +extern boolean keepmapmusic; extern boolean skipintromus; #define MUSICSTARTTIME (starttime + (TICRATE/2)) @@ -113,6 +113,7 @@ void S_ResetKeepAndSpecialMus(void); void S_InitMapMusic(void); void S_StartMapMusic(void); +void S_HandleReloadResetMusic(void); void S_KeepMusic(void);