Changeset 4960 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Jul 27, 2005, 6:27:03 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/sound
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/sound/sound_engine.cc
r4959 r4960 22 22 23 23 //#include <AL/alc.h> // maybe later 24 #include "class_list.h" 24 25 25 26 #include "p_node.h" … … 81 82 SoundBuffer::~SoundBuffer() 82 83 { 83 SoundEngine::getInstance()->removeBuffer(this);84 // SoundEngine::getInstance()->removeBuffer(this); 84 85 alDeleteBuffers(1, &this->bufferID); 85 86 } … … 118 119 SoundSource::~SoundSource() 119 120 { 120 SoundEngine::getInstance()->removeSource(this);121 //SoundEngine::getInstance()->removeSource(this); 121 122 alDeleteSources(1, &this->sourceID); 122 123 } … … 192 193 193 194 this->listener = NULL; 194 this->bufferList = new tList<SoundBuffer>;195 this->sourceList = new tList<SoundSource>;195 this->bufferList = NULL; 196 this->sourceList = NULL; 196 197 } 197 198 … … 210 211 211 212 // deleting all the SoundSources 212 tIterator<SoundSource>* sourceIterator = this->sourceList->getIterator(); 213 SoundSource* enumSource = sourceIterator->nextElement(); 214 while (enumSource) 215 { 216 delete enumSource; 217 enumSource = sourceIterator->nextElement(); 218 } 219 delete sourceIterator; 213 if(this->sourceList != NULL) 214 { 215 tIterator<BaseObject>* sourceIterator = this->sourceList->getIterator(); 216 SoundSource* enumSource = (SoundSource*)sourceIterator->nextElement(); 217 while (enumSource) 218 { 219 delete enumSource; 220 enumSource = (SoundSource*)sourceIterator->nextElement(); 221 } 222 delete sourceIterator; 223 } 220 224 221 225 // deleting all the SoundBuffers 222 tIterator<SoundBuffer>* bufferIterator = this->bufferList->getIterator(); 223 SoundBuffer* enumBuffer = bufferIterator->nextElement(); 224 while (enumBuffer) 226 if (this->bufferList != NULL) 227 { 228 tIterator<BaseObject>* bufferIterator = this->bufferList->getIterator(); 229 SoundBuffer* enumBuffer = (SoundBuffer*)bufferIterator->nextElement(); 230 while (enumBuffer) 225 231 { 226 232 ResourceManager::getInstance()->unload(enumBuffer); 227 enumBuffer = bufferIterator->nextElement();228 } 229 delete bufferIterator;230 233 enumBuffer = (SoundBuffer*)bufferIterator->nextElement(); 234 } 235 delete bufferIterator; 236 } 231 237 // removing openAL from AudioResource 232 238 alutExit(); … … 273 279 void SoundEngine::addBuffer(SoundBuffer* buffer) 274 280 { 275 this->bufferList->add(buffer); 281 if (unlikely(this->bufferList == NULL)) 282 this->bufferList = ClassList::getList(CL_SOUND_BUFFER); 276 283 } 277 284 … … 283 290 { 284 291 // look if there are any sources that have the buffer still loaded 285 tIterator< SoundSource>* sourceIterator = this->sourceList->getIterator();286 SoundSource* enumSource = sourceIterator->nextElement();292 tIterator<BaseObject>* sourceIterator = this->sourceList->getIterator(); 293 SoundSource* enumSource = (SoundSource*)sourceIterator->nextElement(); 287 294 while (enumSource) 288 295 { 289 296 if (buffer == enumSource->getBuffer()) 290 297 delete enumSource; 291 enumSource = sourceIterator->nextElement();298 enumSource = (SoundSource*)sourceIterator->nextElement(); 292 299 } 293 300 delete sourceIterator; 294 295 // remove the Buffer296 this->bufferList->remove(buffer);297 301 } 298 302 … … 303 307 void SoundEngine::addSource(SoundSource* source) 304 308 { 305 this->sourceList->add(source); 306 } 307 308 /** 309 * removes a SoundSource from the sourceList of the SoundEngine 310 * @param source The source to delete from the SoundEngine 311 */ 312 void SoundEngine::removeSource(SoundSource* source) 313 { 314 this->sourceList->remove(source); 315 } 316 309 this->sourceList = ClassList::getList(CL_SOUND_SOURCE); 310 } 317 311 318 312 /** … … 341 335 342 336 // updating all the Sources positions 343 tIterator<SoundSource>* iterator = this->sourceList->getIterator(); 344 SoundSource* enumSource = iterator->nextElement(); 345 while (enumSource) 337 if (likely(this->sourceList != NULL)) 338 { 339 tIterator<BaseObject>* iterator = this->sourceList->getIterator(); 340 SoundSource* enumSource = (SoundSource*)iterator->nextElement(); 341 while (enumSource) 346 342 { 347 343 if (likely(enumSource->getNode()!=NULL)) … … 356 352 enumSource->getNode()->getVelocity().z); 357 353 } 358 enumSource = iterator->nextElement(); 359 } 360 delete iterator; 354 enumSource = (SoundSource*)iterator->nextElement(); 355 } 356 delete iterator; 357 } 361 358 } 362 359 … … 366 363 void SoundEngine::flushUnusedBuffers() 367 364 { 368 tIterator<SoundBuffer>* bufferIterator = this->bufferList->getIterator(); 369 SoundBuffer* enumBuffer = bufferIterator->nextElement(); 370 while (enumBuffer) 371 { 372 tIterator<SoundSource>* sourceIterator = this->sourceList->getIterator(); 373 SoundSource* enumSource = sourceIterator->nextElement(); 365 if(this->sourceList && this->bufferList) 366 { 367 tIterator<BaseObject>* bufferIterator = this->bufferList->getIterator(); 368 SoundBuffer* enumBuffer = (SoundBuffer*)bufferIterator->nextElement(); 369 while (enumBuffer) 370 { 371 tIterator<BaseObject>* sourceIterator = this->sourceList->getIterator(); 372 SoundSource* enumSource = (SoundSource*)sourceIterator->nextElement(); 374 373 while (enumSource) 375 376 377 378 enumSource =sourceIterator->nextElement();379 374 { 375 if (enumBuffer == enumSource->getBuffer()) 376 break; 377 enumSource = (SoundSource*)sourceIterator->nextElement(); 378 } 380 379 delete sourceIterator; 381 380 if (enumSource == NULL) 382 381 ResourceManager::getInstance()->unload(enumBuffer); 383 enumBuffer = bufferIterator->nextElement(); 384 } 385 delete bufferIterator; 382 enumBuffer = (SoundBuffer*)bufferIterator->nextElement(); 383 } 384 delete bufferIterator; 385 } 386 386 } 387 387 … … 391 391 void SoundEngine::flushAllBuffers() 392 392 { 393 tIterator<SoundBuffer>* bufferIterator = this->bufferList->getIterator(); 394 SoundBuffer* enumBuffer = bufferIterator->nextElement(); 395 while (enumBuffer) 393 if (this->bufferList) 394 { 395 tIterator<BaseObject>* bufferIterator = this->bufferList->getIterator(); 396 SoundBuffer* enumBuffer = (SoundBuffer*)bufferIterator->nextElement(); 397 while (enumBuffer) 396 398 { 397 399 ResourceManager::getInstance()->unload(enumBuffer, RP_LEVEL); 398 enumBuffer = bufferIterator->nextElement(); 399 } 400 delete bufferIterator; 400 enumBuffer = (SoundBuffer*)bufferIterator->nextElement(); 401 } 402 delete bufferIterator; 403 } 401 404 } 402 405 … … 406 409 void SoundEngine::flushAllSources() 407 410 { 408 tIterator<SoundSource>* Iterator = this->sourceList->getIterator(); 409 SoundSource* enumSource = Iterator->nextElement(); 410 while (enumSource) 411 if (this->sourceList) 411 412 { 412 delete enumSource; 413 enumSource = Iterator->nextElement(); 413 tIterator<BaseObject>* Iterator = this->sourceList->getIterator(); 414 SoundSource* enumSource = (SoundSource*)Iterator->nextElement(); 415 while (enumSource) 416 { 417 delete enumSource; 418 enumSource = (SoundSource*)Iterator->nextElement(); 419 } 420 delete Iterator; 414 421 } 415 delete Iterator; 416 } 417 422 } 418 423 419 424 /** -
orxonox/trunk/src/lib/sound/sound_engine.h
r4959 r4960 9 9 #include "base_object.h" 10 10 #include "alincl.h" 11 12 11 13 12 #define SOUND_DOPPLER_FACTOR 0.001 //!< A factor for the audible doppler effect … … 85 84 void removeBuffer(SoundBuffer* buffer); 86 85 void addSource(SoundSource* source); 87 void removeSource(SoundSource* source);88 86 89 87 void update(); … … 109 107 110 108 PNode* listener; //!< The listener of the Scene 111 tList< SoundBuffer>*bufferList; //!< A list of buffers112 tList< SoundSource>*sourceList; //!< A list for all the sources in the scene.109 tList<BaseObject>* bufferList; //!< A list of buffers 110 tList<BaseObject>* sourceList; //!< A list for all the sources in the scene. 113 111 114 112 };
Note: See TracChangeset
for help on using the changeset viewer.