mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Factor fade amount calculation to separate function
This makes it so to reuse this code, we don't have to copy-paste it. Additionally, I added a check for the milliseconds being 0, to avoid a division by zero. Logically and mathematically, if the fade amount is 0 milliseconds, then that means the fade should happen instantly - however, dividing by zero is undefined (both in math and in C/C++), so this check needs to be added.
This commit is contained in:
parent
f6ea05f521
commit
92b3c0b413
2 changed files with 13 additions and 1 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "BinaryBlob.h"
|
||||
#include "Game.h"
|
||||
#include "Map.h"
|
||||
#include "UtilityClass.h"
|
||||
|
||||
|
@ -273,10 +274,20 @@ void musicclass::silencedasmusik(void)
|
|||
musicVolume = 0;
|
||||
}
|
||||
|
||||
void musicclass::setfadeamount(const int fade_ms)
|
||||
{
|
||||
if (fade_ms == 0)
|
||||
{
|
||||
FadeVolAmountPerFrame = MIX_MAX_VOLUME;
|
||||
return;
|
||||
}
|
||||
FadeVolAmountPerFrame = MIX_MAX_VOLUME / (fade_ms / game.get_timestep());
|
||||
}
|
||||
|
||||
void musicclass::fadeMusicVolumeIn(int ms)
|
||||
{
|
||||
m_doFadeInVol = true;
|
||||
FadeVolAmountPerFrame = MIX_MAX_VOLUME / (ms / 33);
|
||||
setfadeamount(ms);
|
||||
}
|
||||
|
||||
void musicclass::fadeout(const bool quick_fade_ /*= true*/)
|
||||
|
|
|
@ -19,6 +19,7 @@ public:
|
|||
void resume(const int fadein_ms = 0);
|
||||
void haltdasmusik(void);
|
||||
void silencedasmusik(void);
|
||||
void setfadeamount(const int fade_ms);
|
||||
void fadeMusicVolumeIn(int ms);
|
||||
void fadeout(const bool quick_fade_ = true);
|
||||
void fadein(void);
|
||||
|
|
Loading…
Reference in a new issue