X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Faudio%2Fsound_manager.cpp;h=0576fe6ba9cd6d1fbcd9a6cba820250512317fa0;hb=d99e2443318865c0f379170b4ef2aa30f515b235;hp=5b65fe4b5f8437a66fc3904847243d65fafb412b;hpb=db7dbb66619413e3469e75e6db0aad75e5c3301d;p=supertux.git diff --git a/src/audio/sound_manager.cpp b/src/audio/sound_manager.cpp index 5b65fe4b5..0576fe6ba 100644 --- a/src/audio/sound_manager.cpp +++ b/src/audio/sound_manager.cpp @@ -38,7 +38,7 @@ SoundManager::SoundManager() { try { device = alcOpenDevice(0); - if (device == 0) { + if (device == NULL) { throw std::runtime_error("Couldn't open audio device."); } @@ -51,8 +51,12 @@ SoundManager::SoundManager() check_al_error("Audio error after init: "); sound_enabled = true; } catch(std::exception& e) { - device = 0; - context = 0; + if(context != NULL) + alcDestroyContext(context); + context = NULL; + if(device != NULL) + alcCloseDevice(device); + device = NULL; log_warning << "Couldn't initialize audio device: " << e.what() << std::endl; print_openal_version(); } @@ -71,10 +75,10 @@ SoundManager::~SoundManager() alDeleteBuffers(1, &buffer); } - if(context != 0) { + if(context != NULL) { alcDestroyContext(context); } - if(device != 0) { + if(device != NULL) { alcCloseDevice(device); } } @@ -138,7 +142,7 @@ SoundManager::play(const std::string& filename, const Vector& pos) { try { SoundSource* source = create_sound_source(filename); - if(source == 0) + if(source == NULL) return; if(pos == Vector(-1, -1)) { alSourcef(source->source, AL_ROLLOFF_FACTOR, 0); @@ -153,18 +157,35 @@ SoundManager::play(const std::string& filename, const Vector& pos) } void +SoundManager::play_and_delete(SoundSource* source) +{ + if (!source) { + log_debug << "ignoring NULL SoundSource" << std::endl; + return; + } + try { + source->play(); + sources.push_back(source); + } catch(std::exception& e) { + log_warning << "Couldn't play SoundSource: " << e.what() << std::endl; + } +} + +void SoundManager::enable_sound(bool enable) { - if(device == 0) + if(device == NULL) return; + sound_enabled = enable; } void SoundManager::enable_music(bool enable) { - if(device == 0) + if(device == NULL) return; + music_enabled = enable; if(music_enabled) { play_music(current_music); @@ -185,7 +206,7 @@ SoundManager::stop_music(float fadetime) music_source->set_fading(StreamSoundSource::FadingOff, fadetime); } else { delete music_source; - music_source = 0; + music_source = NULL; } current_music = ""; } @@ -201,7 +222,7 @@ SoundManager::play_music(const std::string& filename, bool fade) if(filename == "") { delete music_source; - music_source = 0; + music_source = NULL; return; }