SoundCentral.cpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #include "SoundCentral.hpp"
00023 #include "SoundListener.hpp"
00024 #include "Ambience.hpp"
00025 #include "../thing/Actor.hpp"
00026 #include "../../util/error/Log.hpp"
00027 
00028 
00029 namespace se_core {
00030 
00031     SoundCentral
00032     ::SoundCentral() : listenerCount_(0), isAmbiencePlaying_(false), ambienceHandler_(0) {
00033     }
00034 
00035     SoundCentral
00036     ::~SoundCentral() {
00037     }
00038 
00039 
00040     void SoundCentral
00041     ::addListener(SoundListener &l) {
00042         AssertFatal(listenerCount_ < MAX_LISTENERS, "Added one listener too many");
00043         listeners[ listenerCount_++ ] = &l;
00044     }
00045 
00046 
00047     void SoundCentral
00048     ::removeListener(SoundListener &l) {
00049         for(int i = 0; i < listenerCount_; ++i) {
00050             if(listeners[ i ] == &l) {
00051                 listeners[ i ] = listeners[ --listenerCount_ ];
00052             }
00053         }
00054     }
00055 
00056 
00057     void SoundCentral
00058     ::ambience(const char* snd) {
00059         for(int i = 0; i < listenerCount_; ++i) {
00060             listeners[ i ]->ambienceEvent(snd);
00061         }
00062     }
00063 
00064 
00065     void SoundCentral
00066     ::setAmbienceHandler(const char* name) {
00067         setAmbienceHandler(*Ambience::lookup(name));
00068     }
00069 
00070 
00071     void SoundCentral
00072     ::sound(Actor& speaker, const char* snd) {
00073         for(int i = 0; i < listenerCount_; ++i) {
00074             listeners[ i ]->soundEvent(speaker, snd);
00075         }
00076     }
00077 
00078     void SoundCentral
00079     ::castMusicStopped() {
00080         if(ambienceHandler_) {
00081             ambienceHandler_->musicStoppedEvent(*this);
00082         }
00083     }
00084 
00085 
00086     void SoundCentral
00087     ::castMusicEnded() {
00088         if(ambienceHandler_) {
00089             ambienceHandler_->musicEndedEvent(*this);
00090         }
00091     }
00092 
00093 }

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:11 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo