From b1eb59dd43c9d2cdd0edd996efcdef766aea8175 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 27 Nov 2019 19:53:46 -0800 Subject: [PATCH 01/21] Hey it's audio- ....resynching... --- src/i_sound.h | 2 ++ src/s_sound.c | 4 ++++ src/s_sound.h | 2 ++ src/sdl/mixer_sound.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/src/i_sound.h b/src/i_sound.h index 9a5c2930a..422cfb8ff 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -158,6 +158,8 @@ UINT32 I_GetSongLoopPoint(void); boolean I_SetSongPosition(UINT32 position); UINT32 I_GetSongPosition(void); +void I_UpdateSongLagThreshold (void); + /// ------------------------ // MUSIC PLAYBACK /// ------------------------ diff --git a/src/s_sound.c b/src/s_sound.c index 225863211..7611cf605 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -120,6 +120,8 @@ consvar_t cv_gamesounds = {"sounds", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, consvar_t cv_playmusicifunfocused = {"playmusicifunfocused", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, PlayMusicIfUnfocused_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_playsoundifunfocused = {"playsoundsifunfocused", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, PlaySoundIfUnfocused_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_music_resync_threshold = {"music_resync_threshold", "100", CV_SAVE|CV_CALL, CV_Unsigned, I_UpdateSongLagThreshold}; + #define S_MAX_VOLUME 127 // when to clip out sounds @@ -286,6 +288,8 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_playmusicifunfocused); CV_RegisterVar(&cv_playsoundifunfocused); + CV_RegisterVar(&cv_music_resync_threshold); + COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); diff --git a/src/s_sound.h b/src/s_sound.h index eeb1f0ab0..530049328 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -36,6 +36,8 @@ extern consvar_t cv_gamesounds; extern consvar_t cv_playmusicifunfocused; extern consvar_t cv_playsoundifunfocused; +extern consvar_t cv_music_resync_threshold; + #ifdef SNDSERV extern consvar_t sndserver_cmd, sndserver_arg; #endif diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index c5650192d..34edda818 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -13,6 +13,12 @@ #if defined(HAVE_SDL) && defined(HAVE_MIXER) && SOUND==SOUND_MIXER +/* +Just for hu_stopped. I promise I didn't +write netcode into the sound code, OKAY? +*/ +#include "../d_clisrv.h" + #include "../sounds.h" #include "../s_sound.h" #include "../i_sound.h" @@ -74,12 +80,16 @@ UINT8 sound_started = false; +static UINT32 stutter_threshold; + static Mix_Music *music; static UINT8 music_volume, sfx_volume, internal_volume; static float loop_point; static float song_length; // length in seconds static boolean songpaused; +static UINT32 music_end_bytes; static UINT32 music_bytes; +static UINT32 music_stutter_bytes; static boolean is_looping; // fading @@ -101,6 +111,8 @@ static void var_cleanup(void) loop_point = song_length =\ music_bytes = fading_source = fading_target =\ fading_timer = fading_duration = 0; + music_end_bytes = 0; + music_stutter_bytes = 0; songpaused = is_looping =\ is_fading = false; @@ -537,6 +549,8 @@ static void do_fading_callback(void) static void count_music_bytes(int chan, void *stream, int len, void *udata) { + UINT32 bytes; + (void)chan; (void)stream; (void)udata; @@ -544,12 +558,35 @@ static void count_music_bytes(int chan, void *stream, int len, void *udata) if (!music || I_SongType() == MU_GME || I_SongType() == MU_MOD || I_SongType() == MU_MID) return; music_bytes += len; + if (hu_stopped) + { + music_stutter_bytes += len; + } + else + { + if (music_stutter_bytes >= stutter_threshold) + { + /* + This would be after looping. If we're too near to the start of the + file, subtracting the delta will just underflow. + */ + if (music_stutter_bytes > music_bytes) + { + /* We already know where the end is because we looped. */ + bytes = ( music_end_bytes - ( music_stutter_bytes - music_bytes )); + } + else + bytes = ( music_bytes - music_stutter_bytes ); + I_SetSongPosition((int)( bytes/4/44100.0*1000 )); + } + } } static void music_loop(void) { if (is_looping) { + music_end_bytes = music_bytes; Mix_PlayMusic(music, 0); Mix_SetMusicPosition(loop_point); music_bytes = loop_point*44100.0L*4; //assume 44.1khz, 4-byte length (see I_GetSongPosition) @@ -831,6 +868,8 @@ boolean I_SetSongPosition(UINT32 position) // NOT if position input is greater than song length. music_bytes = 0; + music_stutter_bytes = 0; + return true; } } @@ -875,6 +914,12 @@ UINT32 I_GetSongPosition(void) // 8M: 1 | 8S: 2 | 16M: 2 | 16S: 4 } +void +I_UpdateSongLagThreshold (void) +{ + stutter_threshold = cv_music_resync_threshold.value/1000.0*(4*44100); +} + /// ------------------------ /// Music Playback /// ------------------------ From 12c53012e4a90d51265ab0c329f23932694f1fe4 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 27 Nov 2019 20:25:23 -0800 Subject: [PATCH 02/21] Menu option for music resync --- src/m_menu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/m_menu.c b/src/m_menu.c index 480c887b6..51084e56e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1343,6 +1343,8 @@ static menuitem_t OP_SoundOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Play Music While Unfocused", &cv_playmusicifunfocused, 125}, {IT_STRING|IT_CVAR, NULL, "Play SFX While Unfocused", &cv_playsoundifunfocused, 135}, + + {IT_STRING|IT_CVAR, NULL, "Music Resynch Threshold (MS)", &cv_music_resync_threshold, 150}, }; static menuitem_t OP_DataOptionsMenu[] = From b4091004667f0808f5bfac7a954247b4ab8beb88 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 27 Nov 2019 20:40:12 -0800 Subject: [PATCH 03/21] Limit music resync threshold to one second --- src/s_sound.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index 7611cf605..e6c76909c 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -120,7 +120,16 @@ consvar_t cv_gamesounds = {"sounds", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, consvar_t cv_playmusicifunfocused = {"playmusicifunfocused", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, PlayMusicIfUnfocused_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_playsoundifunfocused = {"playsoundsifunfocused", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, PlaySoundIfUnfocused_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_music_resync_threshold = {"music_resync_threshold", "100", CV_SAVE|CV_CALL, CV_Unsigned, I_UpdateSongLagThreshold}; +static CV_PossibleValue_t music_resync_threshold_cons_t[] = { + {0, "MIN"}, + {1000, "MAX"}, + + {0} +}; +consvar_t cv_music_resync_threshold = { + "music_resync_threshold", "100", CV_SAVE|CV_CALL, + music_resync_threshold_cons_t, I_UpdateSongLagThreshold +}; #define S_MAX_VOLUME 127 From ff119f322ad0b1d04b07ab874a09915fc54072df Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 27 Nov 2019 21:00:08 -0800 Subject: [PATCH 04/21] More intuitive menu for music resync option --- src/m_menu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index 51084e56e..2e5261257 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1344,7 +1344,7 @@ static menuitem_t OP_SoundOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Play Music While Unfocused", &cv_playmusicifunfocused, 125}, {IT_STRING|IT_CVAR, NULL, "Play SFX While Unfocused", &cv_playsoundifunfocused, 135}, - {IT_STRING|IT_CVAR, NULL, "Music Resynch Threshold (MS)", &cv_music_resync_threshold, 150}, + {IT_STRING|IT_CVAR|IT_CV_NOPRINT, NULL, "Music Resynch Threshold", &cv_music_resync_threshold, 150}, }; static menuitem_t OP_DataOptionsMenu[] = @@ -6577,12 +6577,23 @@ static void M_DrawSkyRoom(void) (midi_disabled ? warningflags : highlightflags), (midi_disabled ? "OFF" : "ON"));*/ + V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, + currentMenu->y+currentMenu->menuitems[12].alphaKey, + highlightflags, + ( (cv_music_resync_threshold.value) ? + va("%s MS", cv_music_resync_threshold.string) : "OFF" )); + if (itemOn == 0) lengthstring = 8*(sound_disabled ? 3 : 2); else if (itemOn == 2) lengthstring = 8*(digital_disabled ? 3 : 2); /*else if (itemOn == 5) lengthstring = 8*(midi_disabled ? 3 : 2);*/ + else if (itemOn == 12) + { + lengthstring = 8*( (cv_music_resync_threshold.value) ? + strlen(cv_music_resync_threshold.string) + 3 : 3 ); + } } for (i = 0; i < currentMenu->numitems; ++i) From e27d54f0fa29c733de80adde84ed3201f0c9a871 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 27 Nov 2019 21:03:25 -0800 Subject: [PATCH 05/21] Don't resync if it's disabled --- src/sdl/mixer_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 34edda818..678155b8b 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -562,7 +562,7 @@ static void count_music_bytes(int chan, void *stream, int len, void *udata) { music_stutter_bytes += len; } - else + else if (stutter_threshold) { if (music_stutter_bytes >= stutter_threshold) { From 7f0fa6987a871f53481957e1a0a6cf6e82143751 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 28 Nov 2019 17:09:06 -0800 Subject: [PATCH 06/21] Only resync music if in a level --- src/sdl/mixer_sound.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 678155b8b..30463fbbc 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -547,17 +547,11 @@ static void do_fading_callback(void) /// Music Hooks /// ------------------------ -static void count_music_bytes(int chan, void *stream, int len, void *udata) +static void +Countstutter (int len) { UINT32 bytes; - (void)chan; - (void)stream; - (void)udata; - - if (!music || I_SongType() == MU_GME || I_SongType() == MU_MOD || I_SongType() == MU_MID) - return; - music_bytes += len; if (hu_stopped) { music_stutter_bytes += len; @@ -582,6 +576,20 @@ static void count_music_bytes(int chan, void *stream, int len, void *udata) } } +static void count_music_bytes(int chan, void *stream, int len, void *udata) +{ + (void)chan; + (void)stream; + (void)udata; + + if (!music || I_SongType() == MU_GME || I_SongType() == MU_MOD || I_SongType() == MU_MID) + return; + music_bytes += len; + + if (gamestate == GS_LEVEL) + Countstutter(len); +} + static void music_loop(void) { if (is_looping) From 823ff04e2add46d87b77424244a61717cdd14f99 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 28 Nov 2019 22:05:49 -0800 Subject: [PATCH 07/21] Fade level music back in after Invincibility and Grow Cvars are invincibilitymusicfade and growmusicfade. Both measure milliseconds. --- src/d_netcmd.c | 3 +++ src/g_game.c | 3 +++ src/g_game.h | 3 +++ src/p_user.c | 9 ++++++++- src/s_sound.c | 18 ++++++++++++++++++ src/s_sound.h | 3 +++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 4a90de333..fe18ba733 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -972,6 +972,9 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_soundtest); + CV_RegisterVar(&cv_invincmusicfade); + CV_RegisterVar(&cv_growmusicfade); + // ingame object placing COM_AddCommand("objectplace", Command_ObjectPlace_f); COM_AddCommand("writethings", Command_Writethings_f); diff --git a/src/g_game.c b/src/g_game.c index d9d7b7f12..ddbe65987 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -519,6 +519,9 @@ consvar_t cv_fireaxis4 = {"joyaxis4_fire", "Z-Axis", CV_SAVE, joyaxis_cons_t, NU consvar_t cv_driftaxis4 = {"joyaxis4_drift", "Z-Rudder", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_deadzone4 = {"joy4_deadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_invincmusicfade = {"invincmusicfade", "300", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_growmusicfade = {"growmusicfade", "500", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; + #if MAXPLAYERS > 16 #error "please update player_name table using the new value for MAXPLAYERS" diff --git a/src/g_game.h b/src/g_game.h index 493be5d49..dcbe84db0 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -124,6 +124,9 @@ extern consvar_t cv_turnaxis3,cv_moveaxis3,cv_brakeaxis3,cv_aimaxis3,cv_lookaxis extern consvar_t cv_turnaxis4,cv_moveaxis4,cv_brakeaxis4,cv_aimaxis4,cv_lookaxis4,cv_fireaxis4,cv_driftaxis4,cv_deadzone4; extern consvar_t cv_ghost_besttime, cv_ghost_bestlap, cv_ghost_last, cv_ghost_guest, cv_ghost_staff; +extern consvar_t cv_invincmusicfade; +extern consvar_t cv_growmusicfade; + typedef enum { AXISNONE = 0, diff --git a/src/p_user.c b/src/p_user.c index cb6b7bd62..83a296a39 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1275,10 +1275,16 @@ void P_RestoreMusic(player_t *player) // Item - Grow if (wantedmus == 2) + { S_ChangeMusicInternal("kgrow", true); + S_SetRestoreMusicFadeInCvar(&cv_growmusicfade); + } // Item - Invincibility else if (wantedmus == 1) + { S_ChangeMusicInternal("kinvnc", true); + S_SetRestoreMusicFadeInCvar(&cv_invincmusicfade); + } else { #if 0 @@ -1287,7 +1293,8 @@ void P_RestoreMusic(player_t *player) if (G_RaceGametype() && player->laps >= (UINT8)(cv_numlaps.value - 1)) S_SpeedMusic(1.2f); #endif - S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); + S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, + S_GetRestoreMusicFadeIn()); } } } diff --git a/src/s_sound.c b/src/s_sound.c index e6c76909c..84d9d241d 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1565,6 +1565,7 @@ 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 char queue_name[7]; static UINT16 queue_flags; @@ -1948,6 +1949,8 @@ static void S_UnloadMusic(void) music_name[0] = 0; music_flags = 0; music_looping = false; + + music_refade_cv = 0; } static boolean S_PlayMusic(boolean looping, UINT32 fadeinms) @@ -2169,6 +2172,21 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) } } +void +S_SetRestoreMusicFadeInCvar (consvar_t *cv) +{ + music_refade_cv = cv; +} + +int +S_GetRestoreMusicFadeIn (void) +{ + if (music_refade_cv) + return music_refade_cv->value; + else + return 0; +} + /// ------------------------ /// Music Fading /// ------------------------ diff --git a/src/s_sound.h b/src/s_sound.h index 530049328..b1f558df8 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -186,6 +186,9 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 #define S_ChangeMusicInternal(a,b) S_ChangeMusicEx(a,0,b,0,0,0) #define S_ChangeMusic(a,b,c) S_ChangeMusicEx(a,b,c,0,0,0) +void S_SetRestoreMusicFadeInCvar (consvar_t *cvar); +int S_GetRestoreMusicFadeIn (void); + // Stops the music. void S_StopMusic(void); From b6b7ec92edf9a2812a4946ba8127d327fbb4aadc Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 01:56:44 -0800 Subject: [PATCH 08/21] Restore level music to where it left off Toggleable via the resume cvar. --- src/d_netcmd.c | 2 ++ src/doomstat.h | 1 + src/g_game.c | 2 ++ src/g_game.h | 2 ++ src/p_user.c | 10 +++++++++- src/s_sound.c | 3 +++ 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index fe18ba733..e885b44a2 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -975,6 +975,8 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_invincmusicfade); CV_RegisterVar(&cv_growmusicfade); + CV_RegisterVar(&cv_resume); + // ingame object placing COM_AddCommand("objectplace", Command_ObjectPlace_f); COM_AddCommand("writethings", Command_Writethings_f); diff --git a/src/doomstat.h b/src/doomstat.h index 232a5af8e..39b057ad0 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -34,6 +34,7 @@ extern INT16 gamemap; extern char mapmusname[7]; extern UINT16 mapmusflags; extern UINT32 mapmusposition; +extern UINT32 mapmusresume; #define MUSIC_TRACKMASK 0x0FFF // ----************ #define MUSIC_RELOADRESET 0x8000 // *--------------- #define MUSIC_FORCERESET 0x4000 // -*-------------- diff --git a/src/g_game.c b/src/g_game.c index ddbe65987..8738d15da 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -85,6 +85,7 @@ static void G_DoStartVote(void); char mapmusname[7]; // Music name UINT16 mapmusflags; // Track and reset bit UINT32 mapmusposition; // Position to jump to +UINT32 mapmusresume; INT16 gamemap = 1; INT16 maptol; @@ -522,6 +523,7 @@ consvar_t cv_deadzone4 = {"joy4_deadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_con consvar_t cv_invincmusicfade = {"invincmusicfade", "300", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_growmusicfade = {"growmusicfade", "500", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_resume = {"resume", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; #if MAXPLAYERS > 16 #error "please update player_name table using the new value for MAXPLAYERS" diff --git a/src/g_game.h b/src/g_game.h index dcbe84db0..1acdd72b7 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -127,6 +127,8 @@ extern consvar_t cv_ghost_besttime, cv_ghost_bestlap, cv_ghost_last, cv_ghost_gu extern consvar_t cv_invincmusicfade; extern consvar_t cv_growmusicfade; +extern consvar_t cv_resume; + typedef enum { AXISNONE = 0, diff --git a/src/p_user.c b/src/p_user.c index 83a296a39..e98badbab 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1219,6 +1219,8 @@ boolean P_EndingMusic(player_t *player) // void P_RestoreMusic(player_t *player) { + UINT32 position; + if (!P_IsLocalPlayer(player)) // Only applies to a local player return; @@ -1293,8 +1295,14 @@ void P_RestoreMusic(player_t *player) if (G_RaceGametype() && player->laps >= (UINT8)(cv_numlaps.value - 1)) S_SpeedMusic(1.2f); #endif - S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, + if (mapmusresume && cv_resume.value) + position = mapmusresume; + else + position = mapmusposition; + + S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0, S_GetRestoreMusicFadeIn()); + mapmusresume = 0; } } } diff --git a/src/s_sound.c b/src/s_sound.c index 84d9d241d..a31b93b31 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2075,6 +2075,9 @@ void S_StopMusic(void) || demo.title) // SRB2Kart: Demos don't interrupt title screen music return; + if (strcasecmp(music_name, mapmusname) == 0) + mapmusresume = I_GetSongPosition(); + if (I_SongPaused()) I_ResumeSong(); From 651e28758710728bfc8a1986b278e27fe8c8870a Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 02:55:45 -0800 Subject: [PATCH 09/21] Death fades music Cvars are respawnfademusicout and respawnfademusicback. Both measure milliseconds. --- src/d_netcmd.c | 3 +++ src/g_game.c | 17 ++++++++++++++++- src/g_game.h | 3 +++ src/p_inter.c | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index e885b44a2..9269008b9 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -975,6 +975,9 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_invincmusicfade); CV_RegisterVar(&cv_growmusicfade); + CV_RegisterVar(&cv_respawnfademusicout); + CV_RegisterVar(&cv_respawnfademusicback); + CV_RegisterVar(&cv_resume); // ingame object placing diff --git a/src/g_game.c b/src/g_game.c index 8738d15da..fcffa51f7 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -523,6 +523,9 @@ consvar_t cv_deadzone4 = {"joy4_deadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_con consvar_t cv_invincmusicfade = {"invincmusicfade", "300", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_growmusicfade = {"growmusicfade", "500", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_respawnfademusicout = {"respawnfademusicout", "1000", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_respawnfademusicback = {"respawnfademusicback", "500", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_resume = {"resume", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; #if MAXPLAYERS > 16 @@ -2767,7 +2770,19 @@ void G_PlayerReborn(INT32 player) } } - P_RestoreMusic(p); + if (S_MusicPlaying()) + { + P_RestoreMusic(p); + /* mid-way fading out, fade back up */ + S_FadeMusic(100, cv_respawnfademusicback.value); + } + else + { + /* this could be considered a hack, but I like it ...kinda */ + S_SetRestoreMusicFadeInCvar(&cv_respawnfademusicback); + P_RestoreMusic(p); + } + if (songcredit) S_ShowMusicCredit(); diff --git a/src/g_game.h b/src/g_game.h index 1acdd72b7..8104114f3 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -127,6 +127,9 @@ extern consvar_t cv_ghost_besttime, cv_ghost_bestlap, cv_ghost_last, cv_ghost_gu extern consvar_t cv_invincmusicfade; extern consvar_t cv_growmusicfade; +extern consvar_t cv_respawnfademusicout; +extern consvar_t cv_respawnfademusicback; + extern consvar_t cv_resume; typedef enum diff --git a/src/p_inter.c b/src/p_inter.c index abb12811e..df7aab723 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2106,6 +2106,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) { mobjtype_t item; mobj_t *mo; + int ms; //if (inflictor && (inflictor->type == MT_SHELL || inflictor->type == MT_FIREBALL)) // P_SetTarget(&target->tracer, inflictor); @@ -2319,6 +2320,20 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) } target->player->playerstate = PST_DEAD; + if (netgame || multiplayer) + ms = cv_respawntime.value * 1000; + else + ms = 1000; + + /* + If the time spent with the music paused is less than half + a second, continue playing the song (just mute it). + */ + if (( ms - cv_respawnfademusicout.value ) < 500) + S_FadeMusic(0, cv_respawnfademusicout.value); + else + S_FadeOutStopMusic(cv_respawnfademusicout.value); + if (target->player == &players[consoleplayer]) { // don't die in auto map, From b428549994178b2d90dae543eed0b1fc9aa5647e Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 03:01:01 -0800 Subject: [PATCH 10/21] Reset mapmusresume on level load etc. This is probably important, right? --- src/g_game.c | 1 + src/p_spec.c | 1 + src/s_sound.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/src/g_game.c b/src/g_game.c index fcffa51f7..d8dbebfed 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2766,6 +2766,7 @@ void G_PlayerReborn(INT32 player) mapmusname[6] = 0; mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); mapmusposition = mapheaderinfo[gamemap-1]->muspos; + mapmusresume = 0; songcredit = true; } } diff --git a/src/p_spec.c b/src/p_spec.c index 04d69c9b9..9e6faf505 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2478,6 +2478,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) mapmusflags |= MUSIC_FORCERESET; mapmusposition = position; + mapmusresume = 0; S_ChangeMusicEx(mapmusname, mapmusflags, !(line->flags & ML_EFFECT4), position, !(line->flags & ML_EFFECT2) ? prefadems : 0, diff --git a/src/s_sound.c b/src/s_sound.c index a31b93b31..4f54336cc 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2234,6 +2234,7 @@ void S_Start(void) mapmusname[6] = 0; mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); mapmusposition = mapheaderinfo[gamemap-1]->muspos; + mapmusresume = 0; } //if (cv_resetmusic.value) // Starting ambience should always be restarted @@ -2308,6 +2309,7 @@ static void Command_Tunes_f(void) mapmusname[6] = 0; mapmusflags = (track & MUSIC_TRACKMASK); mapmusposition = position; + mapmusresume = 0; S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); From aec7682d92a8203cdcc1e3884036a9d87b072da1 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 03:01:41 -0800 Subject: [PATCH 11/21] Reset the music fade in cvar pointer too This fixes a bug with death fades. --- src/p_user.c | 1 + src/s_sound.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/p_user.c b/src/p_user.c index e98badbab..3f0f09d5a 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1302,6 +1302,7 @@ void P_RestoreMusic(player_t *player) S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0, S_GetRestoreMusicFadeIn()); + S_ClearRestoreMusicFadeInCvar(); mapmusresume = 0; } } diff --git a/src/s_sound.h b/src/s_sound.h index b1f558df8..0a0f9cf50 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -187,6 +187,8 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 #define S_ChangeMusic(a,b,c) S_ChangeMusicEx(a,b,c,0,0,0) void S_SetRestoreMusicFadeInCvar (consvar_t *cvar); +#define S_ClearRestoreMusicFadeInCvar() \ + S_SetRestoreMusicFadeInCvar(0) int S_GetRestoreMusicFadeIn (void); // Stops the music. From 119d60eb16c45d90a8b5fced819cfcd59e30b815 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 03:24:10 -0800 Subject: [PATCH 12/21] 3 AM Moment: The death fades now only apply to local players --- src/g_game.c | 13 +------------ src/p_inter.c | 27 +++++++++++++++------------ src/p_user.c | 21 +++++++++++++++++++-- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index d8dbebfed..cea848de3 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2771,18 +2771,7 @@ void G_PlayerReborn(INT32 player) } } - if (S_MusicPlaying()) - { - P_RestoreMusic(p); - /* mid-way fading out, fade back up */ - S_FadeMusic(100, cv_respawnfademusicback.value); - } - else - { - /* this could be considered a hack, but I like it ...kinda */ - S_SetRestoreMusicFadeInCvar(&cv_respawnfademusicback); - P_RestoreMusic(p); - } + P_RestoreMusic(p); if (songcredit) S_ShowMusicCredit(); diff --git a/src/p_inter.c b/src/p_inter.c index df7aab723..7fe77cb02 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2320,19 +2320,22 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) } target->player->playerstate = PST_DEAD; - if (netgame || multiplayer) - ms = cv_respawntime.value * 1000; - else - ms = 1000; + if (P_IsLocalPlayer(target->player)) + { + if (netgame || multiplayer) + ms = cv_respawntime.value * 1000; + else + ms = 1000; - /* - If the time spent with the music paused is less than half - a second, continue playing the song (just mute it). - */ - if (( ms - cv_respawnfademusicout.value ) < 500) - S_FadeMusic(0, cv_respawnfademusicout.value); - else - S_FadeOutStopMusic(cv_respawnfademusicout.value); + /* + If the time spent with the music paused is less than half + a second, continue playing the song (just mute it). + */ + if (( ms - cv_respawnfademusicout.value ) < 500) + S_FadeMusic(0, cv_respawnfademusicout.value); + else + S_FadeOutStopMusic(cv_respawnfademusicout.value); + } if (target->player == &players[consoleplayer]) { diff --git a/src/p_user.c b/src/p_user.c index 3f0f09d5a..b840ab785 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1220,6 +1220,8 @@ boolean P_EndingMusic(player_t *player) void P_RestoreMusic(player_t *player) { UINT32 position; + boolean playing; + int fadein; if (!P_IsLocalPlayer(player)) // Only applies to a local player return; @@ -1300,10 +1302,25 @@ void P_RestoreMusic(player_t *player) else position = mapmusposition; - S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0, - S_GetRestoreMusicFadeIn()); + playing = S_MusicPlaying(); + + /* + So if the music isn't playing, it's + most likely because we were dead. + */ + if (! playing) + fadein = cv_respawnfademusicback.value; + + if (playing || ! fadein) + fadein = S_GetRestoreMusicFadeIn(); + + S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0, fadein); S_ClearRestoreMusicFadeInCvar(); mapmusresume = 0; + + /* mid-way fading out, fade back up */ + if (playing) + S_FadeMusic(100, cv_respawnfademusicback.value); } } } From 8d64faee879a6ae5950284dd8581eaecbf84f839 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 03:31:50 -0800 Subject: [PATCH 13/21] Revert "More intuitive menu for music resync option" This reverts commit ee78597a42b4e5edf5b22466682b9a00da6bcecf. --- src/m_menu.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 2e5261257..51084e56e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1344,7 +1344,7 @@ static menuitem_t OP_SoundOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Play Music While Unfocused", &cv_playmusicifunfocused, 125}, {IT_STRING|IT_CVAR, NULL, "Play SFX While Unfocused", &cv_playsoundifunfocused, 135}, - {IT_STRING|IT_CVAR|IT_CV_NOPRINT, NULL, "Music Resynch Threshold", &cv_music_resync_threshold, 150}, + {IT_STRING|IT_CVAR, NULL, "Music Resynch Threshold (MS)", &cv_music_resync_threshold, 150}, }; static menuitem_t OP_DataOptionsMenu[] = @@ -6577,23 +6577,12 @@ static void M_DrawSkyRoom(void) (midi_disabled ? warningflags : highlightflags), (midi_disabled ? "OFF" : "ON"));*/ - V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, - currentMenu->y+currentMenu->menuitems[12].alphaKey, - highlightflags, - ( (cv_music_resync_threshold.value) ? - va("%s MS", cv_music_resync_threshold.string) : "OFF" )); - if (itemOn == 0) lengthstring = 8*(sound_disabled ? 3 : 2); else if (itemOn == 2) lengthstring = 8*(digital_disabled ? 3 : 2); /*else if (itemOn == 5) lengthstring = 8*(midi_disabled ? 3 : 2);*/ - else if (itemOn == 12) - { - lengthstring = 8*( (cv_music_resync_threshold.value) ? - strlen(cv_music_resync_threshold.string) + 3 : 3 ); - } } for (i = 0; i < currentMenu->numitems; ++i) From 48deaacf288d3df0888eff5b518128ef9bb012af Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 03:32:24 -0800 Subject: [PATCH 14/21] Revert "Menu option for music resync" This reverts commit a210874ae421007d0bc97b827b4e52c9b076cd90. --- src/m_menu.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 51084e56e..480c887b6 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1343,8 +1343,6 @@ static menuitem_t OP_SoundOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Play Music While Unfocused", &cv_playmusicifunfocused, 125}, {IT_STRING|IT_CVAR, NULL, "Play SFX While Unfocused", &cv_playsoundifunfocused, 135}, - - {IT_STRING|IT_CVAR, NULL, "Music Resynch Threshold (MS)", &cv_music_resync_threshold, 150}, }; static menuitem_t OP_DataOptionsMenu[] = From 8c0df23a91ad4efb269a88ad9f56b739f5e32903 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 16:17:09 -0800 Subject: [PATCH 15/21] Let invincibility and grow music fades work again --- src/g_game.c | 26 ++++++++++++++++++++++++++ src/p_user.c | 21 ++------------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index cea848de3..e4c73c329 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2612,6 +2612,9 @@ void G_PlayerReborn(INT32 player) INT32 respawnflip; boolean songcredit = false; + boolean local; + boolean playing; + score = players[player].score; marescore = players[player].marescore; lives = players[player].lives; @@ -2771,8 +2774,31 @@ void G_PlayerReborn(INT32 player) } } + /* I'm putting this here because lol */ + + local = P_IsLocalPlayer(p); + + if (local) + { + playing = S_MusicPlaying(); + + /* + Fade it in with the same call to avoid + max volume for a few milliseconds (?). + */ + if (! playing) + S_SetRestoreMusicFadeInCvar(&cv_respawnfademusicback); + } + P_RestoreMusic(p); + if (local) + { + /* mid-way fading out, fade back up */ + if (playing) + S_FadeMusic(100, cv_respawnfademusicback.value); + } + if (songcredit) S_ShowMusicCredit(); diff --git a/src/p_user.c b/src/p_user.c index b840ab785..3f0f09d5a 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1220,8 +1220,6 @@ boolean P_EndingMusic(player_t *player) void P_RestoreMusic(player_t *player) { UINT32 position; - boolean playing; - int fadein; if (!P_IsLocalPlayer(player)) // Only applies to a local player return; @@ -1302,25 +1300,10 @@ void P_RestoreMusic(player_t *player) else position = mapmusposition; - playing = S_MusicPlaying(); - - /* - So if the music isn't playing, it's - most likely because we were dead. - */ - if (! playing) - fadein = cv_respawnfademusicback.value; - - if (playing || ! fadein) - fadein = S_GetRestoreMusicFadeIn(); - - S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0, fadein); + S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0, + S_GetRestoreMusicFadeIn()); S_ClearRestoreMusicFadeInCvar(); mapmusresume = 0; - - /* mid-way fading out, fade back up */ - if (playing) - S_FadeMusic(100, cv_respawnfademusicback.value); } } } From ea8123abb47471f92fa608fabad83bd9bb3e00d6 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 17:23:40 -0800 Subject: [PATCH 16/21] Optionally only resync Invincibility and Grow music --- src/i_sound.h | 1 + src/p_user.c | 2 ++ src/s_sound.c | 22 ++++++++++++++++++++++ src/s_sound.h | 9 +++++++++ src/sdl/mixer_sound.c | 13 ++++++++++++- 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/i_sound.h b/src/i_sound.h index 422cfb8ff..93e3f6dd0 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -159,6 +159,7 @@ boolean I_SetSongPosition(UINT32 position); UINT32 I_GetSongPosition(void); void I_UpdateSongLagThreshold (void); +void I_UpdateSongLagConditions (void); /// ------------------------ // MUSIC PLAYBACK diff --git a/src/p_user.c b/src/p_user.c index 3f0f09d5a..04e9f446b 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1279,12 +1279,14 @@ void P_RestoreMusic(player_t *player) if (wantedmus == 2) { S_ChangeMusicInternal("kgrow", true); + S_SetMusicUsage(MUS_SPECIAL); S_SetRestoreMusicFadeInCvar(&cv_growmusicfade); } // Item - Invincibility else if (wantedmus == 1) { S_ChangeMusicInternal("kinvnc", true); + S_SetMusicUsage(MUS_SPECIAL); S_SetRestoreMusicFadeInCvar(&cv_invincmusicfade); } else diff --git a/src/s_sound.c b/src/s_sound.c index 4f54336cc..d82be2608 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -130,6 +130,10 @@ consvar_t cv_music_resync_threshold = { "music_resync_threshold", "100", CV_SAVE|CV_CALL, music_resync_threshold_cons_t, I_UpdateSongLagThreshold }; +consvar_t cv_music_resync_powerups_only = { + "music_resync_powerups_only", "No", CV_SAVE|CV_CALL, + CV_YesNo, I_UpdateSongLagConditions +}; #define S_MAX_VOLUME 127 @@ -298,6 +302,7 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_playsoundifunfocused); CV_RegisterVar(&cv_music_resync_threshold); + CV_RegisterVar(&cv_music_resync_powerups_only); COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); @@ -1566,6 +1571,7 @@ static void *music_data; static UINT16 music_flags; static boolean music_looping; static consvar_t *music_refade_cv; +static int music_usage; static char queue_name[7]; static UINT16 queue_flags; @@ -1951,6 +1957,7 @@ static void S_UnloadMusic(void) music_looping = false; music_refade_cv = 0; + music_usage = 0; } static boolean S_PlayMusic(boolean looping, UINT32 fadeinms) @@ -1958,6 +1965,8 @@ static boolean S_PlayMusic(boolean looping, UINT32 fadeinms) if (S_MusicDisabled()) return false; + I_UpdateSongLagConditions(); + if ((!fadeinms && !I_PlaySong(looping)) || (fadeinms && !I_FadeInPlaySong(fadeinms, looping))) { @@ -2190,6 +2199,19 @@ S_GetRestoreMusicFadeIn (void) return 0; } +void +S_SetMusicUsage (int type) +{ + music_usage = type; + I_UpdateSongLagConditions(); +} + +int +S_MusicUsage (void) +{ + return music_usage; +} + /// ------------------------ /// Music Fading /// ------------------------ diff --git a/src/s_sound.h b/src/s_sound.h index 0a0f9cf50..44eb0c06a 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -37,6 +37,7 @@ extern consvar_t cv_playmusicifunfocused; extern consvar_t cv_playsoundifunfocused; extern consvar_t cv_music_resync_threshold; +extern consvar_t cv_music_resync_powerups_only; #ifdef SNDSERV extern consvar_t sndserver_cmd, sndserver_arg; @@ -178,6 +179,11 @@ UINT32 S_GetMusicPosition(void); // Music Playback // +enum +{ + MUS_SPECIAL = 1,/* powerups--invincibility, grow */ +}; + // Start music track, arbitrary, given its name, and set whether looping // note: music flags 12 bits for tracknum (gme, other formats with more than one track) // 13-15 aren't used yet @@ -191,6 +197,9 @@ void S_SetRestoreMusicFadeInCvar (consvar_t *cvar); S_SetRestoreMusicFadeInCvar(0) int S_GetRestoreMusicFadeIn (void); +void S_SetMusicUsage (int type); +int S_MusicUsage (void); + // Stops the music. void S_StopMusic(void); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 30463fbbc..f871851dc 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -80,6 +80,7 @@ write netcode into the sound code, OKAY? UINT8 sound_started = false; +static UINT32 stutter_threshold_user; static UINT32 stutter_threshold; static Mix_Music *music; @@ -925,7 +926,17 @@ UINT32 I_GetSongPosition(void) void I_UpdateSongLagThreshold (void) { - stutter_threshold = cv_music_resync_threshold.value/1000.0*(4*44100); + stutter_threshold_user = cv_music_resync_threshold.value/1000.0*(4*44100); + I_UpdateSongLagConditions(); +} + +void +I_UpdateSongLagConditions (void) +{ + if (! cv_music_resync_powerups_only.value || S_MusicUsage() == MUS_SPECIAL) + stutter_threshold = stutter_threshold_user; + else + stutter_threshold = 0; } /// ------------------------ From 0528e4a686ba47708307ff8e0b16658541187d11 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 17:38:55 -0800 Subject: [PATCH 17/21] Reset Invincibility (and Grow) music to the start if stacked Toggleable via the resetspecialmusic cvar. --- src/d_netcmd.c | 2 ++ src/g_game.c | 2 ++ src/g_game.h | 2 ++ src/p_user.c | 6 ++---- src/s_sound.c | 9 +++++++++ src/s_sound.h | 2 ++ 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 9269008b9..9c2dd6d80 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -978,6 +978,8 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_respawnfademusicout); CV_RegisterVar(&cv_respawnfademusicback); + CV_RegisterVar(&cv_resetspecialmusic); + CV_RegisterVar(&cv_resume); // ingame object placing diff --git a/src/g_game.c b/src/g_game.c index e4c73c329..41365e40e 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -526,6 +526,8 @@ consvar_t cv_growmusicfade = {"growmusicfade", "500", CV_SAVE, CV_Unsigned, NULL consvar_t cv_respawnfademusicout = {"respawnfademusicout", "1000", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_respawnfademusicback = {"respawnfademusicback", "500", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_resetspecialmusic = {"resetspecialmusic", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_resume = {"resume", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; #if MAXPLAYERS > 16 diff --git a/src/g_game.h b/src/g_game.h index 8104114f3..7a340f668 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -130,6 +130,8 @@ extern consvar_t cv_growmusicfade; extern consvar_t cv_respawnfademusicout; extern consvar_t cv_respawnfademusicback; +extern consvar_t cv_resetspecialmusic; + extern consvar_t cv_resume; typedef enum diff --git a/src/p_user.c b/src/p_user.c index 04e9f446b..b3079101d 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1278,15 +1278,13 @@ void P_RestoreMusic(player_t *player) // Item - Grow if (wantedmus == 2) { - S_ChangeMusicInternal("kgrow", true); - S_SetMusicUsage(MUS_SPECIAL); + S_ChangeMusicSpecial("kgrow"); S_SetRestoreMusicFadeInCvar(&cv_growmusicfade); } // Item - Invincibility else if (wantedmus == 1) { - S_ChangeMusicInternal("kinvnc", true); - S_SetMusicUsage(MUS_SPECIAL); + S_ChangeMusicSpecial("kinvnc"); S_SetRestoreMusicFadeInCvar(&cv_invincmusicfade); } else diff --git a/src/s_sound.c b/src/s_sound.c index d82be2608..6acbee8cd 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2077,6 +2077,15 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 } } +void +S_ChangeMusicSpecial (const char *mmusic) +{ + if (cv_resetspecialmusic.value) + S_ChangeMusic(mmusic, MUSIC_FORCERESET, true); + else + S_ChangeMusicInternal(mmusic, true); +} + void S_StopMusic(void) { if (!I_SongPlaying() diff --git a/src/s_sound.h b/src/s_sound.h index 44eb0c06a..c433aa974 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -192,6 +192,8 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 #define S_ChangeMusicInternal(a,b) S_ChangeMusicEx(a,0,b,0,0,0) #define S_ChangeMusic(a,b,c) S_ChangeMusicEx(a,b,c,0,0,0) +void S_ChangeMusicSpecial (const char *mmusic); + void S_SetRestoreMusicFadeInCvar (consvar_t *cvar); #define S_ClearRestoreMusicFadeInCvar() \ S_SetRestoreMusicFadeInCvar(0) From 97a58f48befcbf8a43afc2c5dae90e67467845e0 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 11 Mar 2020 19:39:06 -0700 Subject: [PATCH 18/21] Don't reset special music in P_RestoreMusic Because that resets Grow music when you stack Grow over Invincibility, and Invincibility ends. (Also Megamix Themes.) Thanks Snu, for calling P_RestoreMusic every tic! --- src/k_kart.c | 12 ++++++++---- src/p_user.c | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index c4bade950..9e6f861e9 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -5561,9 +5561,11 @@ void K_MoveKartPlayer(player_t *player, boolean onground) P_SetScale(overlay, player->mo->scale); } player->kartstuff[k_invincibilitytimer] = itemtime+(2*TICRATE); // 10 seconds - P_RestoreMusic(player); - if (!P_IsLocalPlayer(player)) + if (P_IsLocalPlayer(player)) + S_ChangeMusicSpecial("kinvnc"); + else S_StartSound(player->mo, (cv_kartinvinsfx.value ? sfx_alarmi : sfx_kinvnc)); + P_RestoreMusic(player); K_PlayPowerGloatSound(player->mo); player->kartstuff[k_itemamount]--; } @@ -5764,9 +5766,11 @@ void K_MoveKartPlayer(player_t *player, boolean onground) if (cv_kartdebugshrink.value && !modeattacking && !player->bot) player->mo->destscale = (6*player->mo->destscale)/8; player->kartstuff[k_growshrinktimer] = itemtime+(4*TICRATE); // 12 seconds - P_RestoreMusic(player); - if (!P_IsLocalPlayer(player)) + if (P_IsLocalPlayer(player)) + S_ChangeMusicSpecial("kgrow"); + else S_StartSound(player->mo, (cv_kartinvinsfx.value ? sfx_alarmg : sfx_kgrow)); + P_RestoreMusic(player); S_StartSound(player->mo, sfx_kc5a); } player->kartstuff[k_itemamount]--; diff --git a/src/p_user.c b/src/p_user.c index b3079101d..3f0f09d5a 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1278,13 +1278,13 @@ void P_RestoreMusic(player_t *player) // Item - Grow if (wantedmus == 2) { - S_ChangeMusicSpecial("kgrow"); + S_ChangeMusicInternal("kgrow", true); S_SetRestoreMusicFadeInCvar(&cv_growmusicfade); } // Item - Invincibility else if (wantedmus == 1) { - S_ChangeMusicSpecial("kinvnc"); + S_ChangeMusicInternal("kinvnc", true); S_SetRestoreMusicFadeInCvar(&cv_invincmusicfade); } else From 8515bc410ec0b5f1e75c6618692793fe041c5f9e Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 19 Apr 2020 22:08:37 -0700 Subject: [PATCH 19/21] C90 moment --- src/s_sound.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 6acbee8cd..eca6029bf 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -126,14 +126,9 @@ static CV_PossibleValue_t music_resync_threshold_cons_t[] = { {0} }; -consvar_t cv_music_resync_threshold = { - "music_resync_threshold", "100", CV_SAVE|CV_CALL, - music_resync_threshold_cons_t, I_UpdateSongLagThreshold -}; -consvar_t cv_music_resync_powerups_only = { - "music_resync_powerups_only", "No", CV_SAVE|CV_CALL, - CV_YesNo, I_UpdateSongLagConditions -}; +consvar_t cv_music_resync_threshold = {"music_resync_threshold", "100", CV_SAVE|CV_CALL, music_resync_threshold_cons_t, I_UpdateSongLagThreshold, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_music_resync_powerups_only = {"music_resync_powerups_only", "No", CV_SAVE|CV_CALL, CV_YesNo, I_UpdateSongLagConditions, 0, NULL, NULL, 0, 0, NULL}; #define S_MAX_VOLUME 127 From 6fbd518b9769844ed5895e8f39f5274983f01c43 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 28 Sep 2020 14:34:17 -0700 Subject: [PATCH 20/21] cv_fading to disable music fading entirely --- src/d_netcmd.c | 1 + src/g_game.c | 9 +++++---- src/g_game.h | 1 + src/p_inter.c | 2 +- src/s_sound.c | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 9c2dd6d80..0a32fda78 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -981,6 +981,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_resetspecialmusic); CV_RegisterVar(&cv_resume); + CV_RegisterVar(&cv_fading); // ingame object placing COM_AddCommand("objectplace", Command_ObjectPlace_f); diff --git a/src/g_game.c b/src/g_game.c index 41365e40e..034713f09 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -529,6 +529,7 @@ consvar_t cv_respawnfademusicback = {"respawnfademusicback", "500", CV_SAVE, CV_ consvar_t cv_resetspecialmusic = {"resetspecialmusic", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_resume = {"resume", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fading = {"fading", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; #if MAXPLAYERS > 16 #error "please update player_name table using the new value for MAXPLAYERS" @@ -2614,7 +2615,7 @@ void G_PlayerReborn(INT32 player) INT32 respawnflip; boolean songcredit = false; - boolean local; + boolean fade; boolean playing; score = players[player].score; @@ -2778,9 +2779,9 @@ void G_PlayerReborn(INT32 player) /* I'm putting this here because lol */ - local = P_IsLocalPlayer(p); + fade = ( cv_fading.value && P_IsLocalPlayer(p) ); - if (local) + if (fade) { playing = S_MusicPlaying(); @@ -2794,7 +2795,7 @@ void G_PlayerReborn(INT32 player) P_RestoreMusic(p); - if (local) + if (fade) { /* mid-way fading out, fade back up */ if (playing) diff --git a/src/g_game.h b/src/g_game.h index 7a340f668..4761f5c31 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -133,6 +133,7 @@ extern consvar_t cv_respawnfademusicback; extern consvar_t cv_resetspecialmusic; extern consvar_t cv_resume; +extern consvar_t cv_fading; typedef enum { diff --git a/src/p_inter.c b/src/p_inter.c index 7fe77cb02..7aec8115f 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2320,7 +2320,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) } target->player->playerstate = PST_DEAD; - if (P_IsLocalPlayer(target->player)) + if (cv_fading.value && P_IsLocalPlayer(target->player)) { if (netgame || multiplayer) ms = cv_respawntime.value * 1000; diff --git a/src/s_sound.c b/src/s_sound.c index eca6029bf..a7ae485d3 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2197,7 +2197,7 @@ S_SetRestoreMusicFadeInCvar (consvar_t *cv) int S_GetRestoreMusicFadeIn (void) { - if (music_refade_cv) + if (music_refade_cv && cv_fading.value) return music_refade_cv->value; else return 0; From 5dcf65df8a9a519af9ab7a11254e76781b39ece1 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 6 Oct 2020 16:59:02 -0700 Subject: [PATCH 21/21] Fix NOMIXER --- src/sdl/sdl_sound.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 929ac79f5..5c93642bd 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1409,6 +1409,9 @@ UINT32 I_GetSongPosition(void) return 0; } +void I_UpdateSongLagThreshold (void) {} +void I_UpdateSongLagConditions (void) {} + /// ------------------------ // MUSIC PLAYBACK /// ------------------------