Changeset 6117
- Timestamp:
- Nov 22, 2009, 4:01:16 PM (15 years ago)
- Location:
- code/branches/presentation2
- Files:
-
- 14 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2
- Property svn:mergeinfo changed
/code/branches/sound3 (added) merged: 5941,5943,5946,5954,5956-5957,5962,5982,6031,6046,6069-6072,6074,6088,6093,6097,6100,6102
- Property svn:mergeinfo changed
-
code/branches/presentation2/data/levels/templates/spaceship_assff.oxt
r5781 r6117 76 76 <Light mainstate=visibility position="-8, 0, 8" diffuse="0.3, 0.6, 1.0" specular="0.3, 0.6, 1.0" attenuation="600, 1.0, 0.007, 0.0002" type=point /> 77 77 --> 78 <!--WorldSound mainstate=activity source="sounds/Engine_low.ogg" oop=1 /--> 78 79 </active> 79 80 <forward> 80 81 <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 7.6, 0, 6" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" /> 81 82 <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-7.6, 0, 6" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" /> 83 <WorldSound mainstate=activity source="sounds/Engine_low.ogg" oop=1 /> 82 84 </forward> 83 85 <boost> 84 86 <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 7.6, 0, 6" colour="0.6, 0.75, 0.8, 0.7" width=40 length=1000 lifetime=1 elements=30 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Examples/Flare" /> 85 87 <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-7.6, 0, 6" colour="0.6, 0.75, 0.8, 0.7" width=40 length=1000 lifetime=1 elements=30 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Examples/Flare" /> 88 <!--WorldSound mainstate=activity source="sounds/Engine_high.ogg" oop=1 /--> 86 89 </boost> 87 90 <brake> -
code/branches/presentation2/src/libraries/core/XMLPort.h
r5929 r6117 184 184 ClassIdentifier<classname>::getIdentifier()->addXMLPortParamContainer(paramname, containername); \ 185 185 } \ 186 containername->port( static_cast<BaseObject*>(this), object, xmlelement, mode)186 containername->port(dynamic_cast<BaseObject*>(this), object, xmlelement, mode) 187 187 188 188 // -------------------- -
code/branches/presentation2/src/orxonox/CMakeLists.txt
r5929 r6117 28 28 LevelManager.cc 29 29 Main.cc 30 MoodManager.cc 30 31 PawnManager.cc 31 32 PlayerManager.cc … … 55 56 TOLUA_FILES 56 57 LevelManager.h 58 MoodManager.h 57 59 pickup/BaseItem.h 58 60 pickup/PickupInventory.h -
code/branches/presentation2/src/orxonox/gamestates/GSMainMenu.cc
r6105 r6117 36 36 #include "core/Game.h" 37 37 #include "core/ConsoleCommand.h" 38 #include "core/ConfigValueIncludes.h" 38 39 #include "core/GraphicsManager.h" 39 40 #include "core/GUIManager.h" … … 49 50 , inputState_(0) 50 51 { 52 RegisterRootObject(GSMainMenu); 51 53 inputState_ = InputManager::getInstance().createInputState("mainMenu"); 52 54 inputState_->setMouseMode(MouseMode::Nonexclusive); … … 64 66 // Load sound 65 67 this->ambient_ = new AmbientSound(0); 66 this->ambient_->setSource("ambient/mainmenu.wav");67 68 } 68 69 } … … 91 92 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startDedicated), "startDedicated")); 92 93 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu), "startMainMenu")); 94 95 // create command to change sound path 96 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::setMainMenuSoundPath, this), "setMMSoundPath")); 93 97 94 98 KeyBinderManager::getInstance().setToDefault(); … … 97 101 if (GameMode::playsSound()) 98 102 { 99 this->ambient_->setLoop (true);100 this->ambient_->play(); 103 this->ambient_->setLooping(true); 104 this->ambient_->play(); // works without source 101 105 } 106 107 this->setConfigValues(); 102 108 } 103 109 … … 117 123 void GSMainMenu::update(const Clock& time) 118 124 { 125 } 126 127 void GSMainMenu::setConfigValues() 128 { 129 SetConfigValue(soundPathMain_, "mainmenu.ogg") 130 .description("Contains the path to the main menu sound file.") 131 .callback(this, &GSMainMenu::reloadSound); 132 } 133 134 void GSMainMenu::reloadSound() 135 { 136 if (GameMode::playsSound()) 137 { 138 this->ambient_->setAmbientSource(soundPathMain_); 139 } 140 } 141 142 const std::string& GSMainMenu::getMainMenuSoundPath() 143 { 144 return soundPathMain_; 145 } 146 147 void GSMainMenu::setMainMenuSoundPath(const std::string& path) 148 { 149 ModifyConfigValue(soundPathMain_, set, path); 119 150 } 120 151 -
code/branches/presentation2/src/orxonox/gamestates/GSMainMenu.h
r5929 r6117 34 34 #include "util/OgreForwardRefs.h" 35 35 #include "core/GameState.h" 36 #include "core/OrxonoxClass.h" 36 37 37 38 namespace orxonox 38 39 { 39 class _OrxonoxExport GSMainMenu : public GameState 40 class _OrxonoxExport GSMainMenu : public GameState, public OrxonoxClass 40 41 { 41 42 public: … … 46 47 void deactivate(); 47 48 void update(const Clock& time); 49 50 void setConfigValues(); 51 void reloadSound(); 52 const std::string& getMainMenuSoundPath(); 53 void setMainMenuSoundPath(const std::string& path); 48 54 49 55 static void startStandalone(); … … 61 67 // ambient sound for the main menu 62 68 AmbientSound* ambient_; 69 std::string soundPathMain_; 63 70 }; 64 71 } -
code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
r5929 r6117 31 31 #include "core/CoreIncludes.h" 32 32 #include "core/EventIncludes.h" 33 #include "core/GameMode.h" 34 #include "core/Resource.h" 33 35 #include "core/XMLPort.h" 36 #include "SoundManager.h" 37 #include "MoodManager.h" 34 38 35 39 namespace orxonox … … 41 45 { 42 46 RegisterObject(AmbientSound); 47 48 // Ambient sounds always fade in 49 this->setVolume(0); 43 50 } 44 51 … … 50 57 { 51 58 SUPER(AmbientSound, XMLPort, xmlelement, mode); 52 XMLPortParamExtern(AmbientSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode); 53 XMLPortParamExtern(AmbientSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode); 54 XMLPortParamExtern(AmbientSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode); 59 BaseSound::XMLPortExtern(xmlelement, mode); 60 XMLPortParam(AmbientSound, "ambientsource", setAmbientSource, getAmbientSource, xmlelement, mode); 55 61 } 56 62 … … 60 66 XMLPortEventState(AmbientSound, BaseObject, "play", play, xmlelement, mode); 61 67 } 68 69 void AmbientSound::play() 70 { 71 if (GameMode::playsSound()) 72 { 73 COUT(3) << "Sound: " << this->getSource() << ": Playing" << std::endl; 74 SoundManager::getInstance().registerAmbientSound(this); 75 } 76 } 77 78 void AmbientSound::doPlay() 79 { 80 BaseSound::play(); 81 } 82 83 void AmbientSound::stop() 84 { 85 if (GameMode::playsSound()) 86 { 87 SoundManager::getInstance().unregisterAmbientSound(this); 88 } 89 } 90 91 void AmbientSound::doStop() 92 { 93 BaseSound::stop(); 94 } 95 96 void AmbientSound::pause() 97 { 98 if (GameMode::playsSound()) 99 { 100 SoundManager::getInstance().pauseAmbientSound(this); 101 } 102 } 103 104 void AmbientSound::doPause() 105 { 106 BaseSound::pause(); 107 } 108 109 void AmbientSound::setAmbientSource(const std::string& source) 110 { 111 this->ambientSource_ = source; 112 if (GameMode::playsSound()) 113 { 114 std::string path = "ambient/" + MoodManager::getInstance().getMood() + "/" + source; 115 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path); 116 if (fileInfo != NULL) 117 this->setSource(path); 118 else 119 COUT(3) << "Sound: " << source << ": Not a valid name! Ambient sound will not change." << std::endl; 120 } 121 } 122 123 void AmbientSound::changedActivity() 124 { 125 SUPER(AmbientSound, changedActivity); 126 if (this->isActive()) 127 this->play(); 128 else 129 this->stop(); 130 } 62 131 } -
code/branches/presentation2/src/orxonox/sound/AmbientSound.h
r5929 r6117 22 22 * Author: 23 23 * Reto Grieder 24 * Kevin Young 24 25 * Co-authors: 25 26 * ... 26 27 * 27 28 */ 29 28 30 #ifndef _AmbientSound_H__ 29 31 #define _AmbientSound_H__ … … 43 45 class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject 44 46 { 47 friend class SoundManager; 48 45 49 public: 46 50 AmbientSound(BaseObject* creator); … … 49 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 54 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 55 virtual void changedActivity(); 56 57 virtual void play(); 58 virtual void stop(); 59 virtual void pause(); 60 61 virtual void setAmbientSource(const std::string& source); 62 const std::string& getAmbientSource() const { return this->ambientSource_; } 51 63 52 64 private: 65 void doPlay(); 66 void doStop(); 67 void doPause(); 68 69 std::string ambientSource_; //!< Analogous to source_, but mood independent 53 70 }; 54 71 } -
code/branches/presentation2/src/orxonox/sound/BaseSound.cc
r5929 r6117 29 29 #include "BaseSound.h" 30 30 31 #include <cassert> 31 32 #include <vector> 32 33 #include <AL/alut.h> … … 36 37 #include "core/GameMode.h" 37 38 #include "core/Resource.h" 39 #include "core/XMLPort.h" 38 40 39 41 namespace orxonox … … 42 44 : audioSource_(0) 43 45 , audioBuffer_(0) 44 , bPlayOnLoad_(false)45 46 , bLoop_(false) 47 , state_(Stopped) 46 48 { 47 49 RegisterRootObject(BaseSound); 50 51 if (GameMode::playsSound()) 52 { 53 alGenSources(1, &this->audioSource_); 54 assert(this->audioSource_ != 0); 55 } 48 56 } 49 57 … … 51 59 { 52 60 this->setSource(""); 61 if (GameMode::playsSound()) 62 alDeleteSources(1, &this->audioSource_); 63 } 64 65 void BaseSound::XMLPortExtern(Element& xmlelement, XMLPort::Mode mode) 66 { 67 XMLPortParam(BaseSound, "volume", setVolume, getVolume, xmlelement, mode); 68 XMLPortParam(BaseSound, "loop", setLooping, getLooping, xmlelement, mode); 69 XMLPortParam(BaseSound, "play", play, isPlaying, xmlelement, mode); 70 XMLPortParam(BaseSound, "source", setSource, getSource, xmlelement, mode); 53 71 } 54 72 55 73 void BaseSound::play() 56 74 { 75 if (!this->isPlaying() && GameMode::showsGraphics()) 76 { 77 this->state_ = Playing; 78 alSourcePlay(this->audioSource_); 79 80 if (alGetError() != AL_NO_ERROR) 81 COUT(2) << "Sound: OpenAL: Error playing sound " << this->audioSource_ << std::endl; 82 } 83 } 84 85 void BaseSound::stop() 86 { 87 this->state_ = Stopped; 88 if (GameMode::playsSound()) 89 alSourceStop(this->audioSource_); 90 } 91 92 void BaseSound::pause() 93 { 94 if (this->isStopped()) 95 return; 96 this->state_ = Paused; 97 if (GameMode::playsSound()) 98 alSourcePause(this->audioSource_); 99 } 100 101 void BaseSound::setVolume(float vol) 102 { 103 if (vol > 1 || vol < 0) 104 { 105 COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl; 106 vol = vol > 1 ? 1 : vol; 107 vol = vol < 0 ? 0 : vol; 108 } 109 this->volume_ = vol; 57 110 if (alIsSource(this->audioSource_)) 58 { 59 if (this->bLoop_) 60 alSourcei(this->audioSource_, AL_LOOPING, AL_TRUE); 61 else 62 alSourcei(this->audioSource_, AL_LOOPING, AL_FALSE); 63 alSourcePlay(this->audioSource_); 64 65 if (alGetError() != AL_NO_ERROR) 66 { 67 COUT(2) << "Sound: OpenAL: Error playin sound " << this->audioSource_ << std::endl; 68 } 69 } 70 } 71 72 void BaseSound::stop() 73 { 74 if (alIsSource(this->audioSource_)) 111 alSourcef(this->audioSource_, AL_GAIN, vol); 112 } 113 114 void BaseSound::setLooping(bool val) 115 { 116 this->bLoop_ = val; 117 if (GameMode::playsSound()) 118 alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE)); 119 } 120 121 void BaseSound::setSource(const std::string& source) 122 { 123 if (!GameMode::playsSound() || source == this->source_) 124 { 125 this->source_ = source; 126 return; 127 } 128 129 if (this->audioBuffer_ != 0 && alIsBuffer(this->audioBuffer_)) 130 { 75 131 alSourceStop(this->audioSource_); 76 } 77 78 void BaseSound::pause() 79 { 80 if (alIsSource(this->audioSource_)) 81 alSourcePause(this->audioSource_); 82 } 83 84 bool BaseSound::isPlaying() 85 { 86 if (alIsSource(this->audioSource_)) 87 return getSourceState() == AL_PLAYING; 88 return false; 89 } 90 91 bool BaseSound::isPaused() 92 { 93 if (alIsSource(this->audioSource_)) 94 return getSourceState() == AL_PAUSED; 95 return true; 96 } 97 98 bool BaseSound::isStopped() 99 { 100 if (alIsSource(this->audioSource_)) 101 return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED; 102 return true; 103 } 104 105 void BaseSound::setPlayOnLoad(bool val) 106 { 107 this->bPlayOnLoad_ = true; 108 this->play(); 109 } 110 111 void BaseSound::setSource(const std::string& source) 112 { 132 // Unload old sound first 133 alSourcei(this->audioSource_, AL_BUFFER, 0); 134 alDeleteBuffers(1, &this->audioBuffer_); 135 this->audioBuffer_ = 0; 136 } 137 113 138 this->source_ = source; 114 if (!GameMode::playsSound()) 115 return; 116 117 if (source.empty() && alIsSource(this->audioSource_)) 118 { 119 // Unload sound 120 alSourcei(this->audioSource_, AL_BUFFER, 0); 121 alDeleteSources(1, &this->audioSource_); 122 alDeleteBuffers(1, &this->audioBuffer_); 123 return; 124 } 139 if (source_.empty()) 140 return; 125 141 126 142 COUT(3) << "Sound: OpenAL ALUT: loading file " << source << std::endl; … … 129 145 if (fileInfo == NULL) 130 146 { 131 COUT(2) << " Warning: Sound file '" << source << "' not found" << std::endl;147 COUT(2) << "Sound: Warning: Sound file '" << source << "' not found" << std::endl; 132 148 return; 133 149 } … … 147 163 { 148 164 COUT(2) << "Sound: Trying fallback ogg loader" << std::endl; 149 this->audioBuffer_ = loadOggFile();165 this->audioBuffer_ = this->loadOggFile(); 150 166 } 151 167 … … 157 173 } 158 174 159 alGenSources(1, &this->audioSource_);160 175 alSourcei(this->audioSource_, AL_BUFFER, this->audioBuffer_); 161 176 if (alGetError() != AL_NO_ERROR) … … 166 181 167 182 alSource3f(this->audioSource_, AL_POSITION, 0, 0, 0); 168 169 if (this->bPlayOnLoad_) 170 this->play(); 171 } 172 173 ALint BaseSound::getSourceState() 174 { 175 ALint state; 176 alGetSourcei(this->audioSource_, AL_SOURCE_STATE, &state); 177 return state; 183 alSourcef (this->audioSource_, AL_GAIN, this->volume_); 184 alSourcei (this->audioSource_, AL_LOOPING, (this->bLoop_ ? AL_TRUE : AL_FALSE)); 185 if (this->isPlaying() || this->isPaused()) 186 alSourcePlay(this->audioSource_); 187 if (this->isPaused()) 188 alSourcePause(this->audioSource_); 189 190 if (alGetError() != AL_NO_ERROR) 191 COUT(2) << "Sound: OpenAL: Error playing sound " << this->audioSource_ << std::endl; 178 192 } 179 193 … … 259 273 return buffer; 260 274 } 261 262 } // namespace: orxonox 275 } -
code/branches/presentation2/src/orxonox/sound/BaseSound.h
r5929 r6117 26 26 * 27 27 */ 28 28 29 #ifndef _BaseSound_H__ 29 30 #define _BaseSound_H__ … … 32 33 33 34 #include <string> 34 #include <OgreSharedPtr.h>35 35 #include <OgreDataStream.h> 36 36 #include "core/OrxonoxClass.h" … … 49 49 virtual ~BaseSound(); 50 50 51 void play(); 52 void stop(); 53 void pause(); 51 void XMLPortExtern(Element& xmlelement, XMLPort::Mode mode); 54 52 55 bool isPlaying();56 bool isPaused();57 bool isStopped();53 virtual void play(); 54 virtual void stop(); 55 virtual void pause(); 58 56 59 void setSource(const std::string& source); 60 const std::string& getSource() { return this->source_; } 57 bool isPlaying() { return this->state_ == Playing; } 58 bool isPaused() { return this->state_ == Paused; } 59 bool isStopped() { return this->state_ == Stopped; } 61 60 62 bool getPlayOnLoad() { return this->bPlayOnLoad_; }63 v oid setPlayOnLoad(bool val);61 virtual void setSource(const std::string& source); 62 virtual const std::string& getSource() const { return this->source_; } 64 63 65 bool getLoop() { return this->bLoop_; } 66 void setLoop(bool val) { this->bLoop_ = val; } 64 void setVolume(float vol); 65 float getVolume() const { return this->volume_; } 66 67 bool getLooping() const { return this->bLoop_; } 68 void setLooping(bool val); 69 70 //ALuint getALAudioSource(void); 67 71 68 72 protected: 69 73 ALuint loadOggFile(); 70 ALint getSourceState();71 74 72 75 ALuint audioSource_; … … 74 77 75 78 private: 76 std::string source_; 77 bool bPlayOnLoad_; 78 bool bLoop_; 79 DataStreamPtr dataStream_; 79 enum State 80 { 81 Stopped, 82 Playing, 83 Paused 84 }; 85 86 std::string source_; 87 float volume_; 88 bool bLoop_; 89 State state_; 90 DataStreamPtr dataStream_; 80 91 }; 81 92 } -
code/branches/presentation2/src/orxonox/sound/SoundManager.cc
r5929 r6117 22 22 * Author: 23 23 * Erwin 'vaiursch' Herrsche 24 * Kevin Young 24 25 * Co-authors: 25 26 * ... … … 30 31 31 32 #include <AL/alut.h> 33 #include <utility> 32 34 33 35 #include "util/Exception.h" 34 36 #include "util/Math.h" 35 37 #include "util/ScopeGuard.h" 38 #include "util/StringUtils.h" 39 #include "util/Clock.h" 36 40 #include "core/GameMode.h" 37 41 #include "core/ScopedSingletonManager.h" 42 #include "core/ConfigValueIncludes.h" 43 #include "BaseSound.h" 44 #include "AmbientSound.h" 38 45 39 46 namespace orxonox … … 44 51 SoundManager::SoundManager() 45 52 { 46 if (!alutInitWithoutContext(NULL,NULL)) 47 ThrowException(InitialisationFailed, "OpenAL ALUT error: " << alutGetErrorString(alutGetError())); 53 RegisterRootObject(SoundManager); 54 55 if (!alutInitWithoutContext(NULL, NULL)) 56 ThrowException(InitialisationFailed, "Sound: OpenAL ALUT error: " << alutGetErrorString(alutGetError())); 48 57 Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit); 49 58 50 COUT(3) << " OpenAL: Opening sound device..." << std::endl;59 COUT(3) << "Sound: OpenAL: Opening sound device..." << std::endl; 51 60 this->device_ = alcOpenDevice(NULL); 52 61 if (this->device_ == NULL) 53 62 { 54 COUT(0) << " OpenaAL: Could not open sound device. Have you installed OpenAL?" << std::endl;63 COUT(0) << "Sound: OpenaAL: Could not open sound device. Have you installed OpenAL?" << std::endl; 55 64 #ifdef ORXONOX_PLATFORM_WINDOWS 56 COUT(0) << " Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;65 COUT(0) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl; 57 66 #endif 58 ThrowException(InitialisationFailed, " OpenAL error: Could not open sound device.");67 ThrowException(InitialisationFailed, "Sound: OpenAL error: Could not open sound device."); 59 68 } 60 69 Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_); 61 70 62 COUT(3) << " OpenAL: Sound device opened" << std::endl;71 COUT(3) << "Sound: OpenAL: Sound device opened" << std::endl; 63 72 this->context_ = alcCreateContext(this->device_, NULL); 64 73 if (this->context_ == NULL) 65 ThrowException(InitialisationFailed, " OpenAL error: Could not create sound context");74 ThrowException(InitialisationFailed, "Sound: OpenAL error: Could not create sound context"); 66 75 Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_); 67 76 68 77 if (alcMakeContextCurrent(this->context_) == AL_TRUE) 69 COUT(3) << " OpenAL: Context " << this->context_ << " loaded" << std::endl;78 COUT(3) << "Sound: OpenAL: Context " << this->context_ << " loaded" << std::endl; 70 79 71 80 COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl; … … 73 82 const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER); 74 83 if (str == NULL) 75 COUT(2) << " OpenAL ALUT error: " << alutGetErrorString(alutGetError()) << std::endl;84 COUT(2) << "Sound: OpenAL ALUT error: " << alutGetErrorString(alutGetError()) << std::endl; 76 85 else 77 COUT(4) << " OpenAL ALUT supported MIME types: " << str << std::endl;86 COUT(4) << "Sound: OpenAL ALUT supported MIME types: " << str << std::endl; 78 87 79 88 GameMode::setPlaysSound(true); … … 82 91 closeDeviceGuard.Dismiss(); 83 92 desroyContextGuard.Dismiss(); 93 94 this->setConfigValues(); 84 95 } 85 96 … … 92 103 } 93 104 105 void SoundManager::update(const Clock& time) 106 { 107 this->processCrossFading(time.getDeltaTime()); 108 } 109 110 void SoundManager::setConfigValues() 111 { 112 SetConfigValue(crossFadeStep_, 0.2f) 113 .description("Determines how fast sounds should fade, per second.") 114 .callback(this, &SoundManager::checkFadeStepValidity); 115 } 116 117 void SoundManager::checkFadeStepValidity() 118 { 119 if (crossFadeStep_ <= 0.0 || crossFadeStep_ >= 1.0 ) 120 { 121 COUT(2) << "Sound warning: Sound step out of range, ignoring change." << std::endl; 122 ResetConfigValue(crossFadeStep_); 123 } 124 COUT(3) << "SoundManager: fade step set to " << crossFadeStep_ << std::endl; 125 return; 126 } 127 94 128 void SoundManager::setListenerPosition(const Vector3& position) 95 129 { … … 114 148 COUT(2) << "Sound: OpenAL: Invalid listener orientation" << std::endl; 115 149 } 150 151 void SoundManager::registerAmbientSound(AmbientSound* newAmbient) 152 { 153 if (newAmbient != NULL) 154 { 155 for (AmbientList::const_iterator it = this->ambientSounds_.begin(); it != this->ambientSounds_.end(); ++it) 156 { 157 if (it->first == newAmbient) 158 { 159 COUT(2) << "Sound warning: Will not play an AmbientSound twice." << std::endl; 160 return; 161 } 162 } 163 164 if (!this->ambientSounds_.empty()) 165 { 166 this->fadeOut(ambientSounds_.front().first); 167 } 168 this->ambientSounds_.push_front(std::make_pair(newAmbient, false)); 169 newAmbient->doPlay(); 170 this->fadeIn(newAmbient); 171 } 172 } 173 174 void SoundManager::unregisterAmbientSound(AmbientSound* oldAmbient) 175 { 176 if (oldAmbient == NULL || ambientSounds_.empty()) 177 { 178 return; 179 } 180 if (this->ambientSounds_.front().first == oldAmbient) 181 { 182 this->fadeOut(oldAmbient); 183 this->ambientSounds_.pop_front(); 184 if (!this->ambientSounds_.empty()) 185 { 186 if (!this->ambientSounds_.front().second) // Not paused before 187 { 188 this->ambientSounds_.front().first->doPlay(); 189 } 190 this->fadeIn(this->ambientSounds_.front().first); 191 } 192 } 193 else 194 { 195 for (AmbientList::iterator it = this->ambientSounds_.begin(); it != this->ambientSounds_.end(); ++it) 196 { 197 if (it->first == oldAmbient) 198 { 199 this->fadeOut(oldAmbient); 200 this->ambientSounds_.erase(it); 201 break; 202 } 203 } 204 } 205 } 206 207 void SoundManager::pauseAmbientSound(AmbientSound* ambient) 208 { 209 if (ambient != NULL) 210 { 211 for (AmbientList::iterator it = this->ambientSounds_.begin(); it != this->ambientSounds_.end(); ++it) 212 { 213 if (it->first == ambient) 214 { 215 it->second = true; 216 this->fadeOut(it->first); 217 return; 218 } 219 } 220 } 221 } 222 223 void SoundManager::fadeIn(AmbientSound* sound) 224 { 225 // If we're already fading out --> remove that 226 for (std::list<AmbientSound*>::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); it++) 227 { 228 if (*it == sound) 229 { 230 this->fadeOutList_.erase(it); 231 break; 232 } 233 } 234 // No duplicate entries 235 if (std::find(this->fadeInList_.begin(), this->fadeInList_.end(), sound) == this->fadeInList_.end()) 236 this->fadeInList_.push_back(sound); 237 } 238 239 void SoundManager::fadeOut(AmbientSound* sound) 240 { 241 // If we're already fading in --> remove that 242 for (std::list<AmbientSound*>::iterator it = this->fadeInList_.begin(); it != this->fadeInList_.end(); it++) 243 { 244 if (*it == sound) 245 { 246 this->fadeInList_.erase(it); 247 break; 248 } 249 } 250 // No duplicate entries 251 if (std::find(this->fadeOutList_.begin(), this->fadeOutList_.end(), sound) == this->fadeOutList_.end()) 252 this->fadeOutList_.push_back(sound); 253 } 254 255 void SoundManager::processCrossFading(float dt) 256 { 257 258 // Hacky solution to the fade delay while loading a level. 259 if(dt > 0.2) 260 { 261 return; 262 } 263 264 // FADE IN 265 for (std::list<AmbientSound*>::iterator it= this->fadeInList_.begin(); it != this->fadeInList_.end(); it) 266 { 267 if ((*it)->getVolume() + this->crossFadeStep_*dt > 1.0f) 268 { 269 (*it)->setVolume(1.0f); 270 this->fadeInList_.erase(it++); 271 } 272 else 273 { 274 (*it)->setVolume((*it)->getVolume() + this->crossFadeStep_*dt); 275 ++it; 276 } 277 } 278 279 // FADE OUT 280 for (std::list<AmbientSound*>::iterator it = this->fadeOutList_.begin(); it != this->fadeOutList_.end(); it) 281 { 282 if ((*it)->getVolume() - this->crossFadeStep_*dt < 0.0f) 283 { 284 (*it)->setVolume(0.0f); 285 286 // If sound is in the ambient list --> pause 287 for (AmbientList::const_iterator it2 = this->ambientSounds_.begin(); it2 != this->ambientSounds_.end(); ++it2) 288 { 289 if (it2->first == *it) 290 { 291 (*it)->doPause(); 292 break; 293 } 294 } 295 // If not pause (by loop above for instance) --> stop 296 if (!(*it)->isPaused()) 297 (*it)->doStop(); 298 299 this->fadeOutList_.erase(it++); 300 } 301 else 302 { 303 (*it)->setVolume((*it)->getVolume() - this->crossFadeStep_*dt); 304 ++it; 305 } 306 } 307 } 116 308 } -
code/branches/presentation2/src/orxonox/sound/SoundManager.h
r5929 r6117 22 22 * Author: 23 23 * Erwin 'vaiursch' Herrsche 24 * Kevin Young 24 25 * Co-authors: 25 26 * ... 26 27 */ 28 27 29 #ifndef _SoundManager_H__ 28 30 #define _SoundManager_H__ … … 30 32 #include "OrxonoxPrereqs.h" 31 33 32 #include <cassert>33 34 #include <list> 35 #include <string> 34 36 #include "util/Singleton.h" 35 #include "tools/interfaces/Tickable.h"36 37 37 38 namespace orxonox … … 42 43 * 43 44 */ 44 class _OrxonoxExport SoundManager : public Singleton<SoundManager> 45 class _OrxonoxExport SoundManager : public Singleton<SoundManager>, public OrxonoxClass 45 46 { 46 47 friend class Singleton<SoundManager>; 48 47 49 public: 48 50 SoundManager(); 49 51 ~SoundManager(); 50 52 53 void update(const Clock& time); 54 void setConfigValues(); 55 51 56 void setListenerPosition(const Vector3& position); 52 57 void setListenerOrientation(const Quaternion& orientation); 53 58 59 void registerAmbientSound(AmbientSound* newAmbient); 60 void unregisterAmbientSound(AmbientSound* oldAmbient); 61 void pauseAmbientSound(AmbientSound* ambient); 62 54 63 private: 64 void processCrossFading(float dt); 65 void fadeIn(AmbientSound* sound); 66 void fadeOut(AmbientSound* sound); 67 68 void checkFadeStepValidity(); 69 55 70 ALCdevice* device_; 56 71 ALCcontext* context_; 57 72 73 typedef std::list<std::pair<AmbientSound*, bool> > AmbientList; 74 AmbientList ambientSounds_; 75 76 float crossFadeStep_; //!< Absolute change per second (0.1 means 10% of the nominal volume) for cross fading 77 std::list<AmbientSound*> fadeInList_; 78 std::list<AmbientSound*> fadeOutList_; 79 58 80 static SoundManager* singletonPtr_s; 59 81 }; -
code/branches/presentation2/src/orxonox/sound/WorldSound.cc
r5929 r6117 53 53 { 54 54 SUPER(WorldSound, XMLPort, xmlelement, mode); 55 XMLPortParamExtern(WorldSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode); 56 XMLPortParamExtern(WorldSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode); 57 XMLPortParamExtern(WorldSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode); 55 BaseSound::XMLPortExtern(xmlelement, mode); 58 56 } 59 57 … … 89 87 } 90 88 89 void WorldSound::changedActivity() 90 { 91 SUPER(WorldSound, changedActivity); 92 if (this->isActive()) 93 this->play(); 94 else 95 this->stop(); 96 } 91 97 } -
code/branches/presentation2/src/orxonox/sound/WorldSound.h
r5929 r6117 26 26 * 27 27 */ 28 28 29 #ifndef _WorldSound_H__ 29 30 #define _WorldSound_H__ … … 49 50 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 51 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 52 virtual void changedActivity(); 51 53 52 54 virtual void tick(float dt);
Note: See TracChangeset
for help on using the changeset viewer.