From 3de5a2d1d19b8783c71ca472f535508104939682 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 8 Feb 2025 17:46:58 +0100 Subject: [PATCH] throw music vars into a struct "mapmusic_t" simplifies everything, keepmusic vars use it too --- src/dehacked.c | 6 ++-- src/doomstat.h | 16 ++++++--- src/g_game.c | 9 ++--- src/p_saveg.c | 2 +- src/p_spec.c | 20 +++++------ src/p_user.c | 10 +++--- src/s_sound.c | 91 ++++++++++++++++++++++++-------------------------- src/s_sound.h | 2 +- 8 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 34a658abc..97d27c8af 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9232,8 +9232,8 @@ int LUA_EnumLib(lua_State *L) PUSHGETTER(globalweather, u8); PUSHGETTER(levelskynum, i32); PUSHGETTER(globallevelskynum, i32); - PUSHGETTER(mapmusflags, u16); - PUSHGETTER(mapmusposition, u32); + PUSHGETTER(mapmusic.flags, u16); + PUSHGETTER(mapmusic.position, u32); PUSHGETTER(gravity, fxp); PUSHGETTER(gamespeed, u8); PUSHGETTER(encoremode, bool); @@ -9250,7 +9250,7 @@ int LUA_EnumLib(lua_State *L) 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 b3290b884..b0be7113d 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -30,16 +30,22 @@ // ============================= // 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 + UINT16 flags; // Track and reset bit + UINT32 position; // Position to jump to + UINT32 resume; // Saved Position when music was stopped +} mapmusic_t; +extern mapmusic_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 5c19d8472..3ee2136e6 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -85,10 +85,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; +mapmusic_t mapmusic; INT16 gamemap = 1; INT16 maptol; @@ -2302,7 +2299,7 @@ void G_PlayerReborn(INT32 player) if (p-players == consoleplayer) { - if (mapmusflags & MUSIC_RELOADRESET) + if (mapmusic.flags & MUSIC_RELOADRESET) { S_HandleReloadResetMusic(); songcredit = true; @@ -3982,7 +3979,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 1b9653b9b..394db050f 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3353,7 +3353,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/p_spec.c b/src/p_spec.c index 670951163..d95abfd48 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2080,7 +2080,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 413: // Change music - if (keepmusic && (leveltime <= MUSICSTARTTIME)) // why check for starttime? cause encore music Zzz... + if (keepmapmusic && (leveltime <= MUSICSTARTTIME)) // why check for starttime? cause encore music Zzz... return; if (cv_ignoremusicchanges.value && (leveltime >= MUSICSTARTTIME) && !fromlapexec) // keep lap music intanct tho @@ -2128,19 +2128,19 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Change the music and apply position/fade operations else { - strncpy(mapmusname, sides[line->sidenum[0]].text, 7); - mapmusname[6] = 0; + strncpy(mapmusic.name, sides[line->sidenum[0]].text, 7); + mapmusic.name[6] = 0; - mapmusflags = tracknum & MUSIC_TRACKMASK; + mapmusic.flags = tracknum & MUSIC_TRACKMASK; if (!(line->flags & ML_BLOCKMONSTERS)) - mapmusflags |= MUSIC_RELOADRESET; + mapmusic.flags |= MUSIC_RELOADRESET; if (line->flags & ML_BOUNCY) - mapmusflags |= MUSIC_FORCERESET; + mapmusic.flags |= MUSIC_FORCERESET; - mapmusposition = position; - mapmusresume = 0; + mapmusic.position = position; + mapmusic.resume = 0; - S_ChangeMusicEx(mapmusname, mapmusflags, !(line->flags & ML_EFFECT4), position, + S_ChangeMusicEx(mapmusic.name, mapmusic.flags, !(line->flags & ML_EFFECT4), position, !(line->flags & ML_EFFECT2) ? prefadems : 0, !(line->flags & ML_EFFECT2) ? postfadems : 0); @@ -2167,7 +2167,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 sfxnum; //dont play any funky sound intros that may interfere with the music - if ((skipintromus || keepmusic) && (leveltime < MUSICSTARTTIME)) + if ((skipintromus || keepmapmusic) && (leveltime < MUSICSTARTTIME)) return; sfxnum = sides[line->sidenum[0]].toptexture; //P_AproxDistance(line->dx, line->dy)>>FRACBITS; diff --git a/src/p_user.c b/src/p_user.c index 388d09f28..ce95e8ad8 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -788,14 +788,14 @@ void P_RestoreMusic(player_t *player) if (G_RaceGametype() && player->laps >= (UINT8)(cv_numlaps.value - 1)) S_SpeedMusic(1.2f); #endif - if (mapmusresume && cv_resume.value) // mapmusresume will be 0 anyways when birdmusic stuff is disabled - position = mapmusresume; + if (mapmusic.resume && cv_resume.value) // mapmusresume will be 0 anyways when birdmusic stuff is disabled + position = mapmusic.resume; else - position = mapmusposition; + position = mapmusic.position; - S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0, S_GetRestoreMusicFadeIn()); + S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, position, 0, S_GetRestoreMusicFadeIn()); S_ClearRestoreMusicFadeInCvar(); - mapmusresume = 0; + mapmusic.resume = 0; } } } diff --git a/src/s_sound.c b/src/s_sound.c index 514d71716..ccba37418 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -117,13 +117,10 @@ consvar_t cv_keepmusic = {"keepmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, N 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 keepmusicresume = false; -static char keepmusname[7]; -static UINT32 keepmusresume = 0; -static UINT16 keepmusflags = 0; -static UINT32 keepmusposition = 0; +mapmusic_t keepmusic; static void S_SetKeepMusResume(void); static void S_SetKeepMusicStuff(void); @@ -1824,7 +1821,7 @@ 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(); @@ -1953,7 +1950,7 @@ 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, mapmusname)) + if (stricmp(music_name, mapmusic.name)) return true; for (size_t i = 0; i < sizeof(musicexception_list)/sizeof(musicexception_list[0]); i++) @@ -1969,14 +1966,14 @@ static boolean S_CheckMusicException(void) void S_ResetKeepAndSpecialMus(void) { - keepmusic = skipintromus = false; + keepmapmusic = skipintromus = false; } static void S_SetKeepMusResume(void) { - if (strcasecmp(music_name, mapmusname) == 0) + if (strcasecmp(music_name, mapmusic.name) == 0) { - keepmusresume = I_GetSongPosition(); + keepmusic.resume = I_GetSongPosition(); } } @@ -1988,18 +1985,18 @@ static void S_SetKeepMusicStuff(void) return; } - strncpy(keepmusname, mapmusname, 7); - CONS_Printf("saved %s\n", keepmusname); - keepmusflags = mapmusflags; - keepmusposition = mapmusposition; + strncpy(keepmusic.name, mapmusic.name, 7); + CONS_Printf("saved %s\n", keepmusic.name); + keepmusic.flags = mapmusic.flags; + keepmusic.position = mapmusic.position; } static void S_ClearKeepMusicPosition(void) { - memset(keepmusname, 0, sizeof(keepmusname)); - keepmusresume = 0; - keepmusflags = 0; - keepmusposition = 0; + memset(keepmusic.name, 0, sizeof(keepmusic.name)); + keepmusic.resume = 0; + keepmusic.flags = 0; + keepmusic.position = 0; } void S_CopyKeepMusicStuff(void) @@ -2009,10 +2006,10 @@ void S_CopyKeepMusicStuff(void) return; } - CONS_Printf("using %s\n", keepmusname); - strncpy(mapmusname, keepmusname, 7); - mapmusflags = keepmusflags; - mapmusposition = keepmusposition; + CONS_Printf("using %s\n", keepmusic.name); + strncpy(mapmusic.name, keepmusic.name, 7); + mapmusic.flags = keepmusic.flags; + mapmusic.position = keepmusic.position; } // determine if we should keep the music on a map restart @@ -2026,16 +2023,16 @@ void S_KeepMusic(void) if (!cv_keepmusic.value) { - keepmusic = keepmusicresume = false; + keepmapmusic = keepmusicresume = false; } else if (oldmap == gamemap && oldencore == encoremode) { - keepmusicresume = (musicchanged && keepmusresume); - keepmusic = (!musicchanged || keepmusicresume); + keepmusicresume = (musicchanged && keepmusic.resume); + keepmapmusic = (!musicchanged || keepmusicresume); } else { - keepmusic = keepmusicresume = false; + keepmapmusic = keepmusicresume = false; S_ClearKeepMusicPosition(); } @@ -2045,23 +2042,23 @@ void S_KeepMusic(void) void S_HandleReloadResetMusic(void) { - if (!(mapmusflags & MUSIC_RELOADRESET)) + if (!(mapmusic.flags & MUSIC_RELOADRESET)) return; - if (keepmusic) + if (keepmapmusic) { // this is horrible, this copies over everything about the mapmusic into temporary variables to reuse S_CopyKeepMusicStuff(); } else { - strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname, 7); - mapmusname[6] = 0; - mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); - mapmusposition = mapheaderinfo[gamemap-1]->muspos; + strncpy(mapmusic.name, mapheaderinfo[gamemap-1]->musname, 7); + mapmusic.name[6] = 0; + mapmusic.flags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); + mapmusic.position = mapheaderinfo[gamemap-1]->muspos; } - mapmusresume = 0; + mapmusic.resume = 0; } // @@ -2073,11 +2070,11 @@ void S_InitMapMusic(void) { 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 (keepmusicresume) - S_ChangeMusicEx(mapmusname, mapmusflags, true, keepmusresume, 0, 500); + S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, keepmusic.resume, 0, 500); return; } @@ -2102,7 +2099,7 @@ void S_InitMapMusic(void) if (leveltime < MUSICSTARTTIME) // SRB2Kart S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); - //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); + //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusic.position, 0, 0); } void S_StartMapMusic(void) @@ -2111,13 +2108,13 @@ 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); + S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, mapmusic.position, 0, 0); if (leveltime == MUSICSTARTTIME) S_ShowMusicCredit(); return; @@ -2129,7 +2126,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(); } } @@ -2179,7 +2176,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")) @@ -2207,19 +2204,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); S_ShowMusicCredit(); if (argc > 3) diff --git a/src/s_sound.h b/src/s_sound.h index 3297c9ccc..1d3438fcd 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))