From 530cac8673f251ef64369a4e6d136e0a06135f9d Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 27 Nov 2019 19:53:46 -0800 Subject: [PATCH 01/20] 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 21b668f28..3d8fd6925 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 @@ -283,6 +285,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 2a904faff..bef91bfb6 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 1617da2a3..260dd3125 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; @@ -554,6 +566,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; @@ -561,12 +575,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) @@ -848,6 +885,8 @@ boolean I_SetSongPosition(UINT32 position) // NOT if position input is greater than song length. music_bytes = 0; + music_stutter_bytes = 0; + return true; } } @@ -892,6 +931,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 1e5041375c46ad83cf829a5eeed0835bc9e94075 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 27 Nov 2019 20:25:23 -0800 Subject: [PATCH 02/20] 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 d5084dff2..a3dac710d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1377,6 +1377,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 04d71125389d56812fe7945afa3ae4e7eafb9679 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 27 Nov 2019 20:40:12 -0800 Subject: [PATCH 03/20] 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 3d8fd6925..a2c987d0e 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 7d1012e85e28f58dc7a7c4c67f99743981f67e46 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 27 Nov 2019 21:00:08 -0800 Subject: [PATCH 04/20] 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 a3dac710d..f5d34fc0a 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1378,7 +1378,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[] = @@ -6417,12 +6417,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 d1dce97d15279339f38d9f08da13c882ad589bc8 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 27 Nov 2019 21:03:25 -0800 Subject: [PATCH 05/20] 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 260dd3125..1590496ff 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -579,7 +579,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 e9c0e65e0efa458d3ce7a391af7bf906cc850034 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 28 Nov 2019 17:09:06 -0800 Subject: [PATCH 06/20] 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 1590496ff..52610575e 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -564,17 +564,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; @@ -599,6 +593,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 8524c3749dd9b598751db52e82469c515c17d54d Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 28 Nov 2019 22:05:49 -0800 Subject: [PATCH 07/20] 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 404d7f181..3498c7cfc 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -985,6 +985,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 7bd183664..49af6e509 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -529,6 +529,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 de482fe7f..62bffbc7f 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -118,6 +118,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 666855f53..c79c74b8f 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1244,10 +1244,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 @@ -1256,7 +1262,8 @@ void P_RestoreMusic(player_t *player) if (G_RaceGametype() && player->laps >= (UINT8)(cv_numlaps.value)) 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 a2c987d0e..8f9223bc4 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1563,6 +1563,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; @@ -1946,6 +1947,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) @@ -2167,6 +2170,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 bef91bfb6..c082b3dd6 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 911dd5733406d0f2d3c5af0da82579e71fff4965 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 01:56:44 -0800 Subject: [PATCH 08/20] 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 3498c7cfc..5cca6637f 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -988,6 +988,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 f4f7acfd0..c65d368d5 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 49af6e509..31baf6b3d 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -80,6 +80,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; @@ -532,6 +533,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 62bffbc7f..c5b3e5dc3 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -121,6 +121,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 c79c74b8f..7172bebd1 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1188,6 +1188,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; @@ -1262,8 +1264,14 @@ void P_RestoreMusic(player_t *player) if (G_RaceGametype() && player->laps >= (UINT8)(cv_numlaps.value)) 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 8f9223bc4..036462edb 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2073,6 +2073,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 7023ccc239a0cb9c08bf26c2f718d1d5676a819f Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 02:55:45 -0800 Subject: [PATCH 09/20] 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 5cca6637f..7b274d0a1 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -988,6 +988,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 31baf6b3d..9e4a2df63 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -533,6 +533,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 @@ -2751,7 +2754,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 c5b3e5dc3..201db19d9 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -121,6 +121,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 905cf1c1f..e4331e039 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2116,6 +2116,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); @@ -2330,6 +2331,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 f6888ab004de7ba6bdc1cf6e3af20db1199b620b Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 03:01:01 -0800 Subject: [PATCH 10/20] 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 9e4a2df63..39f1bbb3f 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2750,6 +2750,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 c4070ef5c..260d4a4f5 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2517,6 +2517,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 036462edb..3cb5ef7fe 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2232,6 +2232,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 @@ -2306,6 +2307,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 15e82919034f35e75ae7dfd5e8e7dfa896cb6a68 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 03:01:41 -0800 Subject: [PATCH 11/20] 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 7172bebd1..5fee0ac9b 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1271,6 +1271,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 c082b3dd6..8e94f8e16 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 80c7cc3c879cb39e6d04878813d04f033f528f2a Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 03:24:10 -0800 Subject: [PATCH 12/20] 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 39f1bbb3f..f5aab99a9 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2755,18 +2755,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 e4331e039..12fbcf6dd 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2331,19 +2331,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 5fee0ac9b..80f206d7c 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1189,6 +1189,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; @@ -1269,10 +1271,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 e6eac8cd3d8dda525a089d402fdca6a822f49c17 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 03:31:50 -0800 Subject: [PATCH 13/20] 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 f5d34fc0a..a3dac710d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1378,7 +1378,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[] = @@ -6417,23 +6417,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 3ae147b01b2400bfd5ae5455155b71ff40935061 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 03:32:24 -0800 Subject: [PATCH 14/20] 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 a3dac710d..d5084dff2 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1377,8 +1377,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 d99d1994da2e898dea753c0093883f5d34fbe325 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 16:17:09 -0800 Subject: [PATCH 15/20] 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 f5aab99a9..0a62b27f9 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2596,6 +2596,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; @@ -2755,8 +2758,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 80f206d7c..5fee0ac9b 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1189,8 +1189,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; @@ -1271,25 +1269,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 dd1715aa15838493bef505df575d9943aabb84f1 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 17:23:40 -0800 Subject: [PATCH 16/20] 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 5fee0ac9b..6af902dc2 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1248,12 +1248,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 3cb5ef7fe..4e26a1d7b 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 @@ -295,6 +299,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); @@ -1564,6 +1569,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; @@ -1949,6 +1955,7 @@ static void S_UnloadMusic(void) music_looping = false; music_refade_cv = 0; + music_usage = 0; } static boolean S_PlayMusic(boolean looping, UINT32 fadeinms) @@ -1956,6 +1963,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))) { @@ -2188,6 +2197,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 8e94f8e16..5c173138e 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 52610575e..77fcc0914 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; @@ -942,7 +943,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 7e0aa16e70d14a41e368143d8d13657665724d06 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 17:38:55 -0800 Subject: [PATCH 17/20] 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 7b274d0a1..f5affa0d5 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -991,6 +991,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 0a62b27f9..b8bd6467a 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -536,6 +536,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 201db19d9..8dd9c2680 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -124,6 +124,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 6af902dc2..8d32827f9 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1247,15 +1247,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 4e26a1d7b..1575788e3 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2075,6 +2075,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 5c173138e..0aa93c623 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 5e671b3483dd82217332680b5dc5e096b51806eb Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 11 Mar 2020 19:39:06 -0700 Subject: [PATCH 18/20] 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 29579ad50..674060f49 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -7101,9 +7101,11 @@ void K_MoveKartPlayer(player_t *player, boolean onground) P_SetScale(overlay, player->mo->scale); } player->kartstuff[k_invincibilitytimer] = itemtime+(2*TICRATE); // 10 seconds + if (P_IsDisplayPlayer(player)) + S_ChangeMusicSpecial("kinvnc"); + else + S_StartSound(player->mo, (cv_kartinvinsfx.value ? sfx_alarmg : sfx_kinvnc)); P_RestoreMusic(player); - if (!P_IsDisplayPlayer(player)) - S_StartSound(player->mo, (cv_kartinvinsfx.value ? sfx_alarmi : sfx_kinvnc)); K_PlayPowerGloatSound(player->mo); player->kartstuff[k_itemamount]--; } @@ -7304,9 +7306,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_IsDisplayPlayer(player)) + if (P_IsDisplayPlayer(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 8d32827f9..5fee0ac9b 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1247,13 +1247,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 8490919257eb74851d809afdbf8bf52d9a0d51e1 Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 19 Apr 2020 22:06:22 -0700 Subject: [PATCH 19/20] Bye death fades --- src/d_netcmd.c | 3 --- src/g_game.c | 29 ----------------------------- src/g_game.h | 3 --- src/p_inter.c | 18 ------------------ 4 files changed, 53 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 1dea735cb..4f3319174 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -989,9 +989,6 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_invincmusicfade); CV_RegisterVar(&cv_growmusicfade); - CV_RegisterVar(&cv_respawnfademusicout); - CV_RegisterVar(&cv_respawnfademusicback); - CV_RegisterVar(&cv_resetspecialmusic); CV_RegisterVar(&cv_resume); diff --git a/src/g_game.c b/src/g_game.c index 164000479..e15c3f2c0 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -527,9 +527,6 @@ 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_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}; @@ -2592,9 +2589,6 @@ 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; @@ -2754,31 +2748,8 @@ 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/g_game.h b/src/g_game.h index 8dd9c2680..64847ef62 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -121,9 +121,6 @@ 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_resetspecialmusic; extern consvar_t cv_resume; diff --git a/src/p_inter.c b/src/p_inter.c index 5f09bdac3..e83315a12 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2117,7 +2117,6 @@ 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); @@ -2332,23 +2331,6 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) } target->player->playerstate = PST_DEAD; - 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 (target->player == &players[consoleplayer]) { // don't die in auto map, From feceb97df0ea66e4d7317baaa0d889554fdafcef Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 19 Apr 2020 22:08:37 -0700 Subject: [PATCH 20/20] 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 1575788e3..5391bf2ab 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