added helper functions for setting and getting music and sfx volume
parent
94ce6cbdb9
commit
e981f68a9c
|
@ -1,3 +1,5 @@
|
|||
#include <cmath>
|
||||
|
||||
#include "SoundBase.h"
|
||||
#include "SoundBaseGlobal.h"
|
||||
|
||||
|
@ -172,7 +174,25 @@ void SoundBase::HaltMusic () {
|
|||
mCurrentMusic = NULL;
|
||||
}
|
||||
|
||||
void SoundBase::SetMusicVolume(const float &music_volume) {
|
||||
int mix_volume = static_cast<int> (fabsf(music_volume) * MIX_MAX_VOLUME);
|
||||
|
||||
Mix_VolumeMusic(mix_volume);
|
||||
}
|
||||
|
||||
float SoundBase::GetMusicVolume() {
|
||||
return static_cast<float>(Mix_VolumeMusic(-1)) / static_cast<float>(MIX_MAX_VOLUME);
|
||||
}
|
||||
|
||||
void SoundBase::SetEffectsVolume(const float &effects_volume) {
|
||||
int mix_volume = static_cast<int> (fabsf(effects_volume) * MIX_MAX_VOLUME);
|
||||
|
||||
Mix_Volume(-1, mix_volume);
|
||||
}
|
||||
|
||||
float SoundBase::GetEffectsVolume() {
|
||||
return static_cast<float>(Mix_Volume(-1, -1)) / static_cast<float>(MIX_MAX_VOLUME);
|
||||
}
|
||||
/*
|
||||
* Global Functions
|
||||
*/
|
||||
|
|
|
@ -39,6 +39,21 @@ class SoundBase : public Module {
|
|||
void PlayMusic (const std::string &music_name);
|
||||
void HaltMusic ();
|
||||
|
||||
/** \brief Sets the volume of the music channel to the given value
|
||||
*
|
||||
* \param music_value is a value from 0. (no music) to 1. (maximum volume)
|
||||
*/
|
||||
void SetMusicVolume (const float &music_volume);
|
||||
/** \brief Returns the value of the music (0. - 1.) */
|
||||
float GetMusicVolume ();
|
||||
/** \brief Sets the volume of the music channel to the given value
|
||||
*
|
||||
* \param music_value is a value from 0. (no music) to 1. (maximum volume)
|
||||
*/
|
||||
void SetEffectsVolume (const float &effects_volume);
|
||||
/** \brief Returns the value of the effects (0. - 1.) */
|
||||
float GetEffectsVolume ();
|
||||
|
||||
protected:
|
||||
/** \brief Initializes the system */
|
||||
virtual int OnInit (int argc, char* argv[]);
|
||||
|
|
Loading…
Reference in New Issue