From d542c2440dfd93c853e7c16b2c611f105671c973 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Sep 2018 15:50:12 -0400 Subject: [PATCH 1/7] musicplus-feature-endoflevel 2.2 -> 2.1 backport --- src/dehacked.c | 2 ++ src/doomstat.h | 3 +++ src/g_game.c | 2 +- src/lua_maplib.c | 4 +++- src/p_setup.c | 3 ++- src/p_user.c | 39 +++++++++++++++++++++++++++++++++++++++ src/s_sound.h | 6 ++++++ src/y_inter.c | 10 ++++++++-- 8 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index e2df11142..002ad8071 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -1205,6 +1205,8 @@ static void readlevelheader(MYFILE *f, INT32 num) mapheaderinfo[num-1]->skynum = (INT16)i; else if (fastcmp(word, "INTERSCREEN")) strncpy(mapheaderinfo[num-1]->interscreen, word2, 8); + else if (fastcmp(word, "MUSICINTERFADEOUT")) + mapheaderinfo[num-1]->musicinterfadeout = (UINT32)get_number(word2); else if (fastcmp(word, "PRECUTSCENENUM")) mapheaderinfo[num-1]->precutscenenum = (UINT8)i; else if (fastcmp(word, "CUTSCENENUM")) diff --git a/src/doomstat.h b/src/doomstat.h index d6fd046b4..cbeb4de42 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -246,6 +246,9 @@ typedef struct UINT8 numGradedMares; ///< Internal. For grade support. nightsgrades_t *grades; ///< NiGHTS grades. Allocated dynamically for space reasons. Be careful. + // Music stuff. + UINT32 musicinterfadeout; ///< Fade out level music on intermission screen in milliseconds + // Lua stuff. // (This is not ifdeffed so the map header structure can stay identical, just in case.) UINT8 numCustomOptions; ///< Internal. For Lua custom value support. diff --git a/src/g_game.c b/src/g_game.c index 6be4cf96e..0c53d17ff 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3541,7 +3541,7 @@ void G_InitNew(UINT8 pultmode, const char *mapname, boolean resetplayer, boolean { // Clear a bunch of variables tokenlist = token = sstimer = redscore = bluescore = lastmap = 0; - countdown = countdown2 = 0; + countdown = countdown2 = exitfadestarted = 0; for (i = 0; i < MAXPLAYERS; i++) { diff --git a/src/lua_maplib.c b/src/lua_maplib.c index a1d7994bf..b68574a7f 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1211,7 +1211,9 @@ static int mapheaderinfo_get(lua_State *L) if (!header->interscreen[i]) break; lua_pushlstring(L, header->interscreen, i); - } else if (fastcmp(field,"runsoc")) + } else if (fastcmp(field,"musicinterfadeout")) + lua_pushinteger(L, header->musicinterfadeout); + else if (fastcmp(field,"runsoc")) lua_pushstring(L, header->runsoc); else if (fastcmp(field,"scriptname")) lua_pushstring(L, header->scriptname); diff --git a/src/p_setup.c b/src/p_setup.c index 6c6b9153d..424aed5bc 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -227,6 +227,7 @@ static void P_ClearSingleMapHeaderInfo(INT16 i) mapheaderinfo[num]->menuflags = 0; // TODO grades support for delfile (pfft yeah right) P_DeleteGrades(num); + mapheaderinfo[num]->musicinterfadeout = 0; // an even further impossibility, delfile custom opts support mapheaderinfo[num]->customopts = NULL; mapheaderinfo[num]->numCustomOptions = 0; @@ -2189,7 +2190,7 @@ static void P_LevelInitStuff(void) players[i].lives = cv_startinglives.value; } - players[i].realtime = countdown = countdown2 = 0; + players[i].realtime = countdown = countdown2 = exitfadestarted = 0; players[i].gotcontinue = false; diff --git a/src/p_user.c b/src/p_user.c index 03b037fed..1d34ba5f1 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8789,6 +8789,45 @@ void P_PlayerThink(player_t *player) if (player->exiting && countdown2) player->exiting = 5; + // Same check as below, just at 1 second before + // so we can fade music + if (!exitfadestarted && + player->exiting <= 1*TICRATE && + (!multiplayer || gametype == GT_COOP ? !mapheaderinfo[gamemap-1]->musicinterfadeout : true) && + // don't fade if we're fading during intermission. follows Y_StartIntermission intertype = int_coop + (gametype == GT_RACE || gametype == GT_COMPETITION ? countdown2 == 0 : true) && // don't fade on timeout + player->lives > 0 && // don't fade on game over (competition) + P_IsLocalPlayer(player)) + { + if (cv_playersforexit.value) + { + INT32 i, total = 0, exiting = 0; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator || players[i].bot) + continue; + if (players[i].lives <= 0) + continue; + + total++; + if (players[i].exiting && players[i].exiting < 1*TICRATE+1) + exiting++; + } + + if (!total || ((4*exiting)/total) >= cv_playersforexit.value) + { + exitfadestarted = true; + S_FadeOutStopMusic(1*MUSICRATE); + } + } + else + { + exitfadestarted = true; + S_FadeOutStopMusic(1*MUSICRATE); + } + } + if (player->exiting == 2 || countdown2 == 2) { if (cv_playersforexit.value) // Count to be sure everyone's exited diff --git a/src/s_sound.h b/src/s_sound.h index 538707ffb..852ed4c27 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -23,6 +23,12 @@ // mask used to indicate sound origin is player item pickup #define PICKUP_SOUND 0x8000 +// Game state stuff + +boolean exitfadestarted; + +// Sound stuff + extern consvar_t stereoreverse; extern consvar_t cv_soundvolume, cv_digmusicvolume, cv_midimusicvolume; extern consvar_t cv_numChannels; diff --git a/src/y_inter.c b/src/y_inter.c index e7df165bf..1f4b49ddf 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -696,7 +696,10 @@ void Y_Ticker(void) boolean anybonuses = false; if (!intertic) // first time only - S_ChangeMusicInternal("lclear", false); // don't loop it + if (mapheaderinfo[gamemap-1]->musicinterfadeout) + S_FadeOutStopMusic(mapheaderinfo[gamemap-1]->musicinterfadeout); + else + S_ChangeMusicInternal("_clear", false); // don't loop it if (intertic < TICRATE) // one second pause before tally begins return; @@ -757,7 +760,10 @@ void Y_Ticker(void) if (!intertic) // first time only { - S_ChangeMusicInternal("lclear", false); // don't loop it + if (mapheaderinfo[gamemap-1]->musicinterfadeout) + S_FadeOutStopMusic(mapheaderinfo[gamemap-1]->musicinterfadeout); + else + S_ChangeMusicInternal("_clear", false); // don't loop it tallydonetic = 0; } From 1dd47e850b976ece7b01ef22d6573bcadc6bac94 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Sep 2018 23:27:00 -0400 Subject: [PATCH 2/7] EndOfLevel: Check player->exiting > 0 && <= TICRATE, fixes start-of-level fading in 2.1 Braces in y_inter.c --- src/p_user.c | 2 +- src/y_inter.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/p_user.c b/src/p_user.c index 1d34ba5f1..ae7bba582 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8792,7 +8792,7 @@ void P_PlayerThink(player_t *player) // Same check as below, just at 1 second before // so we can fade music if (!exitfadestarted && - player->exiting <= 1*TICRATE && + player->exiting > 0 && player->exiting <= 1*TICRATE && (!multiplayer || gametype == GT_COOP ? !mapheaderinfo[gamemap-1]->musicinterfadeout : true) && // don't fade if we're fading during intermission. follows Y_StartIntermission intertype = int_coop (gametype == GT_RACE || gametype == GT_COMPETITION ? countdown2 == 0 : true) && // don't fade on timeout diff --git a/src/y_inter.c b/src/y_inter.c index 1f4b49ddf..5e9cb7112 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -696,10 +696,12 @@ void Y_Ticker(void) boolean anybonuses = false; if (!intertic) // first time only + { if (mapheaderinfo[gamemap-1]->musicinterfadeout) S_FadeOutStopMusic(mapheaderinfo[gamemap-1]->musicinterfadeout); else S_ChangeMusicInternal("_clear", false); // don't loop it + } if (intertic < TICRATE) // one second pause before tally begins return; From b057b2932df1eede66e45c9eafb09108d4aa20fe Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Sep 2018 23:28:39 -0400 Subject: [PATCH 3/7] EndOfLevel: 2.1 dehacked setup fix --- src/p_setup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index 424aed5bc..38182ecb6 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -187,6 +187,8 @@ static void P_ClearSingleMapHeaderInfo(INT16 i) mapheaderinfo[num]->mustrack = 0; DEH_WriteUndoline("MUSICPOS", va("%d", mapheaderinfo[num]->mustrack), UNDO_NONE); mapheaderinfo[num]->muspos = 0; + DEH_WriteUndoline("MUSICINTERFADEOUT", va("%d", mapheaderinfo[num]->musicinterfadeout), UNDO_NONE); + mapheaderinfo[num]->musicinterfadeout = 0; DEH_WriteUndoline("FORCECHARACTER", va("%d", mapheaderinfo[num]->forcecharacter), UNDO_NONE); mapheaderinfo[num]->forcecharacter[0] = '\0'; DEH_WriteUndoline("WEATHER", va("%d", mapheaderinfo[num]->weather), UNDO_NONE); @@ -227,7 +229,6 @@ static void P_ClearSingleMapHeaderInfo(INT16 i) mapheaderinfo[num]->menuflags = 0; // TODO grades support for delfile (pfft yeah right) P_DeleteGrades(num); - mapheaderinfo[num]->musicinterfadeout = 0; // an even further impossibility, delfile custom opts support mapheaderinfo[num]->customopts = NULL; mapheaderinfo[num]->numCustomOptions = 0; From 481c0d7623f77fe405401bfeaa5e645e108c9093 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Sep 2018 23:32:00 -0400 Subject: [PATCH 4/7] EndOfLevel: 2.1 _clear -> lclear music in y_inter --- src/y_inter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/y_inter.c b/src/y_inter.c index 5e9cb7112..c20753e83 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -700,7 +700,7 @@ void Y_Ticker(void) if (mapheaderinfo[gamemap-1]->musicinterfadeout) S_FadeOutStopMusic(mapheaderinfo[gamemap-1]->musicinterfadeout); else - S_ChangeMusicInternal("_clear", false); // don't loop it + S_ChangeMusicInternal("lclear", false); // don't loop it } if (intertic < TICRATE) // one second pause before tally begins @@ -765,7 +765,7 @@ void Y_Ticker(void) if (mapheaderinfo[gamemap-1]->musicinterfadeout) S_FadeOutStopMusic(mapheaderinfo[gamemap-1]->musicinterfadeout); else - S_ChangeMusicInternal("_clear", false); // don't loop it + S_ChangeMusicInternal("lclear", false); // don't loop it tallydonetic = 0; } From b5fc27c5450845f724c394524fc88a918bceb420 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 15 Mar 2019 01:00:50 -0400 Subject: [PATCH 5/7] Implement MUSICINTERFADEOUT level header --- src/dehacked.c | 2 ++ src/doomstat.h | 1 + src/lua_maplib.c | 4 +++- src/p_setup.c | 2 ++ src/y_inter.c | 8 ++++++-- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 6978dd16a..a5fddfea2 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -1198,6 +1198,8 @@ static void readlevelheader(MYFILE *f, INT32 num) mapheaderinfo[num-1]->mustrack = ((UINT16)i - 1); else if (fastcmp(word, "MUSICPOS")) mapheaderinfo[num-1]->muspos = (UINT32)get_number(word2); + else if (fastcmp(word, "MUSICINTERFADEOUT")) + mapheaderinfo[num-1]->musicinterfadeout = (UINT32)get_number(word2); else if (fastcmp(word, "MUSICINTER")) deh_strlcpy(mapheaderinfo[num-1]->musintername, word2, sizeof(mapheaderinfo[num-1]->musintername), va("Level header %d: intermission music", num)); diff --git a/src/doomstat.h b/src/doomstat.h index 716c4d654..82654ba1a 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -248,6 +248,7 @@ typedef struct nightsgrades_t *grades; ///< NiGHTS grades. Allocated dynamically for space reasons. Be careful. // Music stuff. + UINT32 musicinterfadeout; ///< Fade out level music on intermission screen in milliseconds char musintername[7]; ///< Intermission screen music. // Lua stuff. diff --git a/src/lua_maplib.c b/src/lua_maplib.c index d77e636b3..2715f807f 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1489,7 +1489,9 @@ static int mapheaderinfo_get(lua_State *L) if (!header->interscreen[i]) break; lua_pushlstring(L, header->interscreen, i); - } else if (fastcmp(field,"runsoc")) + } else if (fastcmp(field,"musicinterfadeout")) + lua_pushinteger(L, header->musicinterfadeout); + else if (fastcmp(field,"runsoc")) lua_pushstring(L, header->runsoc); else if (fastcmp(field,"scriptname")) lua_pushstring(L, header->scriptname); diff --git a/src/p_setup.c b/src/p_setup.c index 4409ec356..e6aa635e5 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -189,6 +189,8 @@ static void P_ClearSingleMapHeaderInfo(INT16 i) mapheaderinfo[num]->mustrack = 0; DEH_WriteUndoline("MUSICPOS", va("%d", mapheaderinfo[num]->muspos), UNDO_NONE); mapheaderinfo[num]->muspos = 0; + DEH_WriteUndoline("MUSICINTERFADEOUT", va("%d", mapheaderinfo[num]->musicinterfadeout), UNDO_NONE); + mapheaderinfo[num]->musicinterfadeout = 0; DEH_WriteUndoline("MUSICINTER", mapheaderinfo[num]->musintername, UNDO_NONE); mapheaderinfo[num]->musintername[0] = '\0'; DEH_WriteUndoline("FORCECHARACTER", va("%d", mapheaderinfo[num]->forcecharacter), UNDO_NONE); diff --git a/src/y_inter.c b/src/y_inter.c index e6e5a1d22..ab4c21692 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -697,7 +697,9 @@ void Y_Ticker(void) if (!intertic) // first time only { - if (mapheaderinfo[gamemap-1]->musintername[0] && S_MusicExists(mapheaderinfo[gamemap-1]->musintername, !midi_disabled, !digital_disabled)) + if (mapheaderinfo[gamemap-1]->musicinterfadeout) + S_FadeOutStopMusic(mapheaderinfo[gamemap-1]->musicinterfadeout); + else if (mapheaderinfo[gamemap-1]->musintername[0] && S_MusicExists(mapheaderinfo[gamemap-1]->musintername, !midi_disabled, !digital_disabled)) S_ChangeMusicInternal(mapheaderinfo[gamemap-1]->musintername, false); // don't loop it else S_ChangeMusicInternal("lclear", false); // don't loop it @@ -762,7 +764,9 @@ void Y_Ticker(void) if (!intertic) // first time only { - if (mapheaderinfo[gamemap-1]->musintername[0] && S_MusicExists(mapheaderinfo[gamemap-1]->musintername, !midi_disabled, !digital_disabled)) + if (mapheaderinfo[gamemap-1]->musicinterfadeout) + S_FadeOutStopMusic(mapheaderinfo[gamemap-1]->musicinterfadeout); + else if (mapheaderinfo[gamemap-1]->musintername[0] && S_MusicExists(mapheaderinfo[gamemap-1]->musintername, !midi_disabled, !digital_disabled)) S_ChangeMusicInternal(mapheaderinfo[gamemap-1]->musintername, false); // don't loop it else S_ChangeMusicInternal("lclear", false); // don't loop it From 587a51a95786d982d65dd22f2ea1741cb0a5e519 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 15 Mar 2019 03:47:30 -0400 Subject: [PATCH 6/7] Fix end-of-level fading for cv_playersforexit (Code in p_user.c was from 2.2, where cv_playersforexit has different values so that the player exit check works differently) --- src/p_user.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index 97ee04a28..edc4d8a58 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8836,7 +8836,7 @@ void P_PlayerThink(player_t *player) { if (cv_playersforexit.value) { - INT32 i, total = 0, exiting = 0; + INT32 i; for (i = 0; i < MAXPLAYERS; i++) { @@ -8845,12 +8845,11 @@ void P_PlayerThink(player_t *player) if (players[i].lives <= 0) continue; - total++; - if (players[i].exiting && players[i].exiting < 1*TICRATE+1) - exiting++; + if (!players[i].exiting || players[i].exiting > 1*TICRATE) + break; } - if (!total || ((4*exiting)/total) >= cv_playersforexit.value) + if (i == MAXPLAYERS) { exitfadestarted = true; S_FadeOutStopMusic(1*MUSICRATE); From f18103a473dbd0f52d5cf293d6a04496547fc2a8 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 15 Mar 2019 11:01:41 -0400 Subject: [PATCH 7/7] Declare exitfadestarted properly --- src/doomstat.h | 1 + src/g_game.c | 1 + src/s_sound.h | 6 ------ 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/doomstat.h b/src/doomstat.h index d9132798f..4511cf297 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -131,6 +131,7 @@ extern UINT8 skincolor_redteam, skincolor_blueteam, skincolor_redring, skincolor extern tic_t countdowntimer; extern boolean countdowntimeup; +extern boolean exitfadestarted; typedef struct { diff --git a/src/g_game.c b/src/g_game.c index cba9c6575..ac814fa64 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -130,6 +130,7 @@ UINT8 skincolor_bluering = SKINCOLOR_STEELBLUE; tic_t countdowntimer = 0; boolean countdowntimeup = false; +boolean exitfadestarted = false; cutscene_t *cutscenes[128]; diff --git a/src/s_sound.h b/src/s_sound.h index 3a5188c2f..157b8b1cc 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -23,12 +23,6 @@ // mask used to indicate sound origin is player item pickup #define PICKUP_SOUND 0x8000 -// Game state stuff - -boolean exitfadestarted; - -// Sound stuff - extern consvar_t stereoreverse; extern consvar_t cv_soundvolume, cv_digmusicvolume, cv_midimusicvolume; extern consvar_t cv_numChannels;