1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-25 22:18:30 +02:00

Clean up music handling to one place

Previously, setting the actual volume of the music was all over the
place. Which isn't bad, but when I added being able to press N to mute
the music specifically, I should've made it so that there would be a
volume variable somewhere that the game looks at if the music is
unmuted, and otherwise sets the actual volume to 0 if the game is muted.

This resulted in things like #400 and #505 and having to add a bunch of
special-cased checks like game.musicmuted and game.completestop. But
instead of adding a bunch of special-case code, just make it so there's
a central place where Mix_VolumeMusic() actually gets called, and if
some piece of code wants to set the music volume, they can set
music.musicVolume. But the music handling logic in main.cpp gets the
final say on whether to listen to music.musicVolume, or to mute the game
entirely.

This is how the music handling code should have been from the start
(when pressing N to mute the music was added).

Fixes #505.
This commit is contained in:
Misa 2020-10-10 23:42:02 -07:00 committed by Ethan Lee
parent d0b3cfa08c
commit 71c8c54313
2 changed files with 3 additions and 5 deletions

View File

@ -177,7 +177,7 @@ void musicclass::play(int t, const double position_sec /*= 0.0*/, const int fade
t += num_mmmmmm_tracks;
}
safeToProcessMusic = true;
Mix_VolumeMusic(MIX_MAX_VOLUME);
musicVolume = MIX_MAX_VOLUME;
if (currentsong !=t)
{
if (t != -1)
@ -246,7 +246,6 @@ void musicclass::haltdasmusik()
void musicclass::silencedasmusik()
{
Mix_VolumeMusic(0) ;
musicVolume = 0;
}
@ -265,7 +264,6 @@ void musicclass::fadeout()
void musicclass::processmusicfadein()
{
musicVolume += FadeVolAmountPerFrame;
Mix_VolumeMusic(musicVolume);
if (musicVolume >= MIX_MAX_VOLUME)
{
m_doFadeInVol = false;

View File

@ -657,13 +657,13 @@ void inline fixedloop()
{
Mix_Volume(-1,MIX_MAX_VOLUME);
if (game.musicmuted || game.completestop)
if (game.musicmuted)
{
Mix_VolumeMusic(0);
}
else
{
Mix_VolumeMusic(MIX_MAX_VOLUME);
Mix_VolumeMusic(music.musicVolume);
}
}