Fade out music upon dying or level change: 2.1 frontport

This commit is contained in:
mazmazz 2019-03-15 04:21:17 -04:00
parent 8afaaa80a1
commit 7346684bd8
5 changed files with 50 additions and 6 deletions

View file

@ -89,6 +89,7 @@ extern INT32 lastwipetic;
void F_WipeStartScreen(void);
void F_WipeEndScreen(void);
void F_RunWipe(UINT8 wipetype, boolean drawMenu);
tic_t F_GetWipeLength(UINT8 wipetype);
enum
{

View file

@ -378,3 +378,30 @@ void F_RunWipe(UINT8 wipetype, boolean drawMenu)
WipeInAction = false;
#endif
}
/** Returns tic length of wipe
* One lump equals one tic
*/
tic_t F_GetWipeLength(UINT8 wipetype)
{
#ifdef NOWIPE
return 0;
#else
static char lumpname[10] = "FADEmmss";
lumpnum_t lumpnum;
UINT8 wipeframe;
if (wipetype > 99)
return 0;
for (wipeframe = 0; wipeframe < 100; wipeframe++)
{
sprintf(&lumpname[4], "%.2hu%.2hu", (UINT16)wipetype, (UINT16)wipeframe);
lumpnum = W_CheckNumForName(lumpname);
if (lumpnum == LUMPERROR)
return --wipeframe;
}
return --wipeframe;
#endif
}

View file

@ -1305,6 +1305,7 @@ static menuitem_t OP_SoundOptionsMenu[] =
{IT_HEADER, NULL, "Advanced", NULL, 103}, // 50
{IT_STRING | IT_CVAR, NULL, "Closed Captioning", &cv_closedcaptioning, 115}, // 56
{IT_STRING | IT_CVAR, NULL, "Reset Music Upon Dying", &cv_resetmusic, 127}, // 62
};
static menuitem_t OP_DataOptionsMenu[] =

View file

@ -2693,6 +2693,12 @@ boolean P_SetupLevel(boolean skipprecip)
S_StartSound(NULL, sfx_s3kaf);
// Fade music! Time it to S3KAF: 0.25 seconds is snappy.
if (cv_resetmusic.value ||
strnicmp(S_MusicName(),
(mapmusflags & MUSIC_RELOADRESET) ? mapheaderinfo[gamemap-1]->musname : mapmusname, 7))
S_FadeOutStopMusic(MUSICRATE/4); //FixedMul(FixedDiv(F_GetWipeLength(wipedefs[wipe_speclevel_towhite])*NEWTICRATERATIO, NEWTICRATE), MUSICRATE)
F_WipeStartScreen();
V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 0);
@ -2700,6 +2706,7 @@ boolean P_SetupLevel(boolean skipprecip)
F_RunWipe(wipedefs[wipe_speclevel_towhite], false);
nowtime = lastwipetic;
// Hold on white for extra effect.
while (nowtime < endtime)
{
@ -2720,14 +2727,17 @@ boolean P_SetupLevel(boolean skipprecip)
if (!titlemapinaction)
{
// As oddly named as this is, this handles music only.
// We should be fine starting it here.
S_Start();
// Let's fade to black here
// But only if we didn't do the special stage wipe
if (rendermode != render_none && !ranspecialwipe)
{
// Fade out music here. Deduct 2 tics so the fade volume actually reaches 0
if (cv_resetmusic.value ||
strnicmp(S_MusicName(),
(mapmusflags & MUSIC_RELOADRESET) ? mapheaderinfo[gamemap-1]->musname : mapmusname, 7))
S_FadeOutStopMusic(FixedMul(
FixedDiv((F_GetWipeLength(wipedefs[wipe_level_toblack])-2)*NEWTICRATERATIO, NEWTICRATE), MUSICRATE));
F_WipeStartScreen();
V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31);
@ -2735,6 +2745,10 @@ boolean P_SetupLevel(boolean skipprecip)
F_RunWipe(wipedefs[wipe_level_toblack], false);
}
// As oddly named as this is, this handles music only.
// We should be fine starting it here.
S_Start();
if (ranspecialwipe == 2)
{
pausedelay = -3; // preticker plus one

View file

@ -104,7 +104,7 @@ consvar_t cv_closedcaptioning = {"closedcaptioning", "Off", CV_SAVE|CV_CALL, CV_
consvar_t cv_numChannels = {"snd_channels", "32", CV_SAVE|CV_CALL, CV_Unsigned, SetChannelsNum, 0, NULL, NULL, 0, 0, NULL};
static consvar_t surround = {"surround", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_resetmusic = {"resetmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_resetmusic = {"resetmusic", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL};
// Sound system toggles, saved into the config
consvar_t cv_gamedigimusic = {"digimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameDigiMusic_OnChange, 0, NULL, NULL, 0, 0, NULL};
@ -1613,7 +1613,8 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32
return;
}
if (prefadems && S_MusicPlaying()) // queue music change for after fade // allow even if the music is the same
if (prefadems) // queue music change for after fade // allow even if the music is the same
// && S_MusicPlaying() // Let the delay happen even if we're not playing music
{
CONS_Debug(DBG_DETAILED, "Now fading out song %s\n", music_name);
S_QueueMusic(newmusic, mflags, looping, position, fadeinms);