Compare commits

...

4 Commits

Author SHA1 Message Date
Misa 8e5714439a Unindent musicclass::play() from previous two commits
As always, the actual unindenting happens in a separate commit in order
to minimize diff noise.
2021-01-04 05:09:23 -05:00
Misa f64cf4f831 Invert t comparison with -1 and un-nest rest of function
This is also another conditional where the rest of the function is
nested. Furthermore, in order to not repeat ourselves, I've also decided
to unconditionally assign currentsong to t, because if t is -1
currentsong gets assigned to -1 anyway - so it's the same thing, but
it's much easier to see and think about.
2021-01-04 05:09:23 -05:00
Misa fe5bacfdc2 Invert currentsong check and un-nest rest of function
This removes an indentation level, and makes it easier to reason about
the function since you essentially now view it as the function returning
right there.
2021-01-04 05:09:23 -05:00
Misa 96c479a11f Fix whitespace inconsistency in musicclass::play()
Spaces are used around operators and keywords accordingly, and blank
lines are used to visually separate lines of code from each other.
2021-01-04 05:09:23 -05:00
1 changed files with 44 additions and 39 deletions

View File

@ -180,61 +180,66 @@ void musicclass::play(int t, const double position_sec /*= 0.0*/, const int fade
t %= num_pppppp_tracks;
}
if(mmmmmm && !usingmmmmmm)
if (mmmmmm && !usingmmmmmm)
{
t += num_mmmmmm_tracks;
}
safeToProcessMusic = true;
musicVolume = MIX_MAX_VOLUME;
if (currentsong !=t)
if (currentsong == t)
{
if (t != -1)
return;
}
currentsong = t;
if (t == -1)
{
return;
}
if (!INBOUNDS_VEC(t, musicTracks))
{
puts("play() out-of-bounds!");
currentsong = -1;
return;
}
if (currentsong == 0 || currentsong == 7 || (!map.custommode && (currentsong == 0+num_mmmmmm_tracks || currentsong == 7+num_mmmmmm_tracks)))
{
// Level Complete theme, no fade in or repeat
if (Mix_FadeInMusicPos(musicTracks[t].m_music, 0, 0, position_sec) == -1)
{
currentsong = t;
if (!INBOUNDS_VEC(t, musicTracks))
printf("Mix_FadeInMusicPos: %s\n", Mix_GetError());
}
}
else
{
if (Mix_FadingMusic() == MIX_FADING_OUT)
{
// We're already fading out
nicechange = t;
nicefade = true;
currentsong = -1;
if (quick_fade)
{
puts("play() out-of-bounds!");
currentsong = -1;
return;
}
if (currentsong == 0 || currentsong == 7 || (!map.custommode && (currentsong == 0+num_mmmmmm_tracks || currentsong == 7+num_mmmmmm_tracks)))
{
// Level Complete theme, no fade in or repeat
if(Mix_FadeInMusicPos(musicTracks[t].m_music, 0, 0, position_sec)==-1)
{
printf("Mix_FadeInMusicPos: %s\n", Mix_GetError());
}
Mix_FadeOutMusic(500); // fade out quicker
}
else
{
if (Mix_FadingMusic() == MIX_FADING_OUT)
{
// We're already fading out
nicechange = t;
nicefade = true;
currentsong = -1;
if (quick_fade)
{
Mix_FadeOutMusic(500); // fade out quicker
}
else
{
quick_fade = true;
}
}
else if(Mix_FadeInMusicPos(musicTracks[t].m_music, -1, fadein_ms, position_sec)==-1)
{
printf("Mix_FadeInMusicPos: %s\n", Mix_GetError());
}
quick_fade = true;
}
songStart = SDL_GetPerformanceCounter();
}
else
else if (Mix_FadeInMusicPos(musicTracks[t].m_music, -1, fadein_ms, position_sec) == -1)
{
currentsong = -1;
printf("Mix_FadeInMusicPos: %s\n", Mix_GetError());
}
}
songStart = SDL_GetPerformanceCounter();
}
void musicclass::resume(const int fadein_ms /*= 0*/)