summaryrefslogtreecommitdiff
path: root/src/sound_openal.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-04-06 15:30:36 +0300
committerPerttu Ahola <celeron55@gmail.com>2012-04-06 15:30:36 +0300
commit6a57eabb145e5000427e38ab0c8d3bb435b2c596 (patch)
treefb67244b0e56cc4de092f5301da68d9a91ef6792 /src/sound_openal.cpp
parenta67540807a051c39d79203832383e8fc8829b5d6 (diff)
downloadminetest-6a57eabb145e5000427e38ab0c8d3bb435b2c596.tar.gz
minetest-6a57eabb145e5000427e38ab0c8d3bb435b2c596.tar.bz2
minetest-6a57eabb145e5000427e38ab0c8d3bb435b2c596.zip
Handle failing openal init properly, add enable_sound and sound_volume settings
Diffstat (limited to 'src/sound_openal.cpp')
-rw-r--r--src/sound_openal.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/sound_openal.cpp b/src/sound_openal.cpp
index 66faf40c1..c74fa276c 100644
--- a/src/sound_openal.cpp
+++ b/src/sound_openal.cpp
@@ -198,12 +198,14 @@ private:
std::map<int, PlayingSound*> m_sounds_playing;
v3f m_listener_pos;
public:
+ bool m_is_initialized;
OpenALSoundManager(OnDemandSoundFetcher *fetcher):
m_fetcher(fetcher),
m_device(NULL),
m_context(NULL),
m_can_vorbis(false),
- m_next_id(1)
+ m_next_id(1),
+ m_is_initialized(false)
{
ALCenum error = ALC_NO_ERROR;
@@ -252,6 +254,8 @@ public:
infostream<<"Audio: Initialized: OpenAL "<<alGetString(AL_VERSION)
<<", using "<<alcGetString(m_device, ALC_DEVICE_SPECIFIER)
<<std::endl;
+
+ m_is_initialized = true;
}
~OpenALSoundManager()
@@ -465,6 +469,11 @@ public:
alListenerfv(AL_ORIENTATION, f);
warn_if_error(alGetError(), "updateListener");
}
+
+ void setListenerGain(float gain)
+ {
+ alListenerf(AL_GAIN, gain);
+ }
int playSound(const std::string &name, bool loop, float volume)
{
@@ -519,6 +528,10 @@ public:
ISoundManager *createOpenALSoundManager(OnDemandSoundFetcher *fetcher)
{
- return new OpenALSoundManager(fetcher);
+ OpenALSoundManager *m = new OpenALSoundManager(fetcher);
+ if(m->m_is_initialized)
+ return m;
+ delete m;
+ return NULL;
};