From dd1715aa15838493bef505df575d9943aabb84f1 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Nov 2019 17:23:40 -0800 Subject: [PATCH] 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; } /// ------------------------