Optionally only resync Invincibility and Grow music

This commit is contained in:
James R 2019-11-29 17:23:40 -08:00
parent d99d1994da
commit dd1715aa15
5 changed files with 46 additions and 1 deletions

View file

@ -159,6 +159,7 @@ boolean I_SetSongPosition(UINT32 position);
UINT32 I_GetSongPosition(void);
void I_UpdateSongLagThreshold (void);
void I_UpdateSongLagConditions (void);
/// ------------------------
// MUSIC PLAYBACK

View file

@ -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

View file

@ -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
/// ------------------------

View file

@ -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);

View file

@ -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;
}
/// ------------------------