/** Positional sound is cool, but creating a new object just to play a simple * menu sound is not. This function allows for 'quick sounds' in a single call. * \param sound_type Internal name of the sfx to play. * \return a pointer to the sound, for instance to check when the sound finished. * don't delete the returned pointer. */ SFXBase* SFXManager::quickSound(const std::string &sound_type) { if (!sfxAllowed()) return NULL; m_quick_sounds.lock(); std::map<std::string, SFXBase*>::iterator sound = m_quick_sounds.getData().find(sound_type); if (sound == m_quick_sounds.getData().end()) { // sound not yet in our local list of quick sounds SFXBase* new_sound = createSoundSource(sound_type, false); if (new_sound == NULL) return NULL; new_sound->play(); m_quick_sounds.getData()[sound_type] = new_sound; m_quick_sounds.unlock(); return new_sound; } else { SFXBase *base_sound = sound->second; base_sound->play(); m_quick_sounds.unlock(); return base_sound; } } // quickSound
/** Sets the position and orientation of the listener. * \param position Position of the listener. * \param front Which way the listener is facing. */ void SFXManager::reallyPositionListenerNow() { #if HAVE_OGGVORBIS if (!sfxAllowed()) return; m_listener_position.lock(); { //forward vector float orientation[6]; orientation[0] = m_listener_front.getX(); orientation[1] = m_listener_front.getY(); orientation[2] = -m_listener_front.getZ(); //up vector orientation[3] = m_listener_up.getX(); orientation[4] = m_listener_up.getY(); orientation[5] = -m_listener_up.getZ(); const Vec3 &pos = m_listener_position.getData(); alListener3f(AL_POSITION, pos.getX(), pos.getY(), -pos.getZ()); alListenerfv(AL_ORIENTATION, orientation); } m_listener_position.unlock(); #endif } // reallyPositionListenerNow
/** Positional sound is cool, but creating a new object just to play a simple * menu sound is not. This function allows for 'quick sounds' in a single call. * \param sound_type Internal name of the sfx to play. * \return a pointer to the sound, for instance to check when the sound finished. * don't delete the returned pointer. */ SFXBase* SFXManager::quickSound(const std::string &sound_type) { if (!sfxAllowed()) return NULL; std::map<std::string, SFXBase*>::iterator sound = m_quick_sounds.find(sound_type); if (sound == m_quick_sounds.end()) { // sound not yet in our local list of quick sounds SFXBase* newSound = SFXManager::get()->createSoundSource(sound_type, false); if (newSound == NULL) return NULL; newSound->play(); m_quick_sounds[sound_type] = newSound; return newSound; } else { (*sound).second->play(); return (*sound).second; } } // quickSound
/** Resumes all paused SFXs. If sound is disabled, does nothing. */ void SFXManager::resumeAll() { // ignore unpausing if sound is disabled if (!sfxAllowed()) return; queue(SFX_RESUME_ALL); } // resumeAll
/** Pauses all looping SFXs. Non-looping SFX will be finished, since it's * otherwise not possible to determine which SFX must be resumed (i.e. were * actually playing at the time pause was called). */ void SFXManager::pauseAll() { if (!sfxAllowed()) return; queue(SFX_PAUSE_ALL); } // pauseAll