Changeset 6046 for code/branches/sound3/src/orxonox/sound/SoundManager.cc
- Timestamp:
- Nov 11, 2009, 5:55:26 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/sound3/src/orxonox/sound/SoundManager.cc
r6031 r6046 35 35 #include "util/ScopeGuard.h" 36 36 #include "util/StringUtils.h" 37 #include "util/Clock.h" 37 38 #include "core/GameMode.h" 38 39 #include "core/ScopedSingletonManager.h" 39 40 #include "core/Resource.h" 41 #include "core/ConfigValueIncludes.h" 40 42 #include "BaseSound.h" 41 43 #include "MoodManager.h" 44 #include "AmbientSound.h" 42 45 43 46 namespace orxonox … … 48 51 SoundManager::SoundManager() 49 52 { 53 RegisterRootObject(SoundManager); 54 50 55 if (!alutInitWithoutContext(NULL,NULL)) 51 56 ThrowException(InitialisationFailed, "Sound: OpenAL ALUT error: " << alutGetErrorString(alutGetError())); … … 86 91 closeDeviceGuard.Dismiss(); 87 92 desroyContextGuard.Dismiss(); 93 94 this->setConfigValues(); 88 95 } 89 96 … … 96 103 } 97 104 105 void SoundManager::update(const Clock &time) 106 { 107 this->fadeInAmbientSound(time.getDeltaTime()); 108 this->fadeOutAmbientSound(time.getDeltaTime()); 109 } 110 111 void SoundManager::setConfigValues() 112 { 113 SetConfigValue(fadeStep_, 0.2f) 114 .description("Determines how fast sounds should fade, per second.") 115 .callback(this, &SoundManager::checkFadeStepValidity); 116 } 117 98 118 void SoundManager::setListenerPosition(const Vector3& position) 99 119 { … … 119 139 } 120 140 121 void SoundManager::registerAmbientSound(BaseSound* newAmbient) 122 { 123 if (!(this->ambientSounds_.empty())) 124 { 125 this->ambientSounds_.front()->pause(); 126 } 127 this->ambientSounds_.push_front(newAmbient); 128 } 129 130 void SoundManager::unregisterAmbientSound(BaseSound* currentAmbient) 141 void SoundManager::registerAmbientSound(AmbientSound* newAmbient) 142 { 143 if(newAmbient != NULL) 144 { 145 if (!(this->ambientSounds_.empty())) 146 { 147 this->fadeOutList_.push_front(std::make_pair(this->ambientSounds_.front(), 1.0)); 148 } 149 this->fadeInList_.push_front(std::make_pair(newAmbient, 0.0)); 150 this->ambientSounds_.push_front(newAmbient); 151 } 152 } 153 154 void SoundManager::unregisterAmbientSound(AmbientSound* currentAmbient) 131 155 { 132 156 if(currentAmbient == NULL || ambientSounds_.empty()) … … 136 160 if(this->ambientSounds_.front() == currentAmbient) 137 161 { 162 this->fadeOutList_.push_front(std::make_pair(this->ambientSounds_.front(), 1.0)); 138 163 this->ambientSounds_.pop_front(); 139 164 if(!(this->ambientSounds_.empty())) 140 165 { 141 this-> ambientSounds_.front()->replay();166 this->fadeInList_.push_front(std::make_pair(this->ambientSounds_.front(), 0.0)); 142 167 } 143 168 } 144 169 else 145 170 { 146 for(std::list< BaseSound*>::iterator it= this->ambientSounds_.begin(); it != this->ambientSounds_.end(); it++)171 for(std::list<AmbientSound*>::iterator it= this->ambientSounds_.begin(); it != this->ambientSounds_.end(); it++) 147 172 { 148 173 if(*it == currentAmbient) 149 174 { 175 currentAmbient->doStop(); 150 176 this->ambientSounds_.erase(it); 151 177 break; … … 158 184 const std::string& SoundManager::getAmbientPath(const std::string& source) 159 185 { 160 lastReqPath = "ambient/" + MoodManager::getInstance().getMood() + "/" + source;161 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(lastReqPath );186 lastReqPath_ = "ambient/" + MoodManager::getInstance().getMood() + "/" + source; 187 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(lastReqPath_); 162 188 if(fileInfo == NULL) 163 189 { 164 190 return BLANKSTRING; 165 191 } 166 return lastReqPath; 192 return lastReqPath_; 193 } 194 195 void SoundManager::fadeInAmbientSound(float dt) 196 { 197 if(!(this->fadeInList_.empty())) 198 { 199 for(std::list<std::pair<AmbientSound*, float> >::iterator it= this->fadeInList_.begin(); it != this->fadeInList_.end(); it++) 200 { 201 it->second += fadeStep_ * dt; 202 alSourcef(it->first->getALAudioSource(), AL_GAIN, it->second); 203 } 204 if(this->fadeInList_.back().second >= 1) 205 { 206 this->fadeInList_.pop_back(); 207 } 208 } 209 } 210 211 void SoundManager::fadeOutAmbientSound(float dt) 212 { 213 if(!(this->fadeInList_.empty())) 214 { 215 for(std::list<std::pair<AmbientSound*, float> >::iterator it= this->fadeOutList_.begin(); it != this->fadeOutList_.end(); it++) 216 { 217 it->second -= fadeStep_ * dt; 218 alSourcef(it->first->getALAudioSource(), AL_GAIN, it->second); 219 } 220 if(this->fadeOutList_.back().second <= 0) 221 { 222 bool pauseTest = false; 223 224 for(std::list<AmbientSound*>::iterator it= this->ambientSounds_.begin(); it != this->ambientSounds_.end(); it++) 225 { 226 if(*it == this->fadeOutList_.back().first) 227 { 228 pauseTest = true; 229 break; 230 } 231 } 232 if(pauseTest) 233 { 234 this->fadeOutList_.back().first->pause(); 235 } 236 else 237 { 238 this->fadeOutList_.back().first->doStop(); 239 } 240 this->fadeOutList_.pop_back(); 241 } 242 } 243 } 244 245 void SoundManager::checkFadeStepValidity() 246 { 247 if(fadeStep_ <= 0.0 || fadeStep_ >= 1.0 ) 248 { 249 ResetConfigValue(fadeStep_); 250 } 251 COUT(0) << "SoundManager: fade step now set to " << fadeStep_ << std::endl; 252 return; 167 253 } 168 254 }
Note: See TracChangeset
for help on using the changeset viewer.