Changeset 6412 for code/branches/pickup2/src/orxonox/sound/AmbientSound.cc
- Timestamp:
- Dec 25, 2009, 1:18:03 PM (15 years ago)
- Location:
- code/branches/pickup2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup2
- Property svn:mergeinfo changed
-
code/branches/pickup2/src/orxonox/sound/AmbientSound.cc
r5929 r6412 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" 34 37 35 38 namespace orxonox … … 39 42 AmbientSound::AmbientSound(BaseObject* creator) 40 43 : BaseObject(creator) 44 , Synchronisable(creator) 45 , bPlayOnLoad_(false) 41 46 { 42 47 RegisterObject(AmbientSound); 48 49 // Ambient sounds always fade in 50 this->setVolume(0); 51 this->registerVariables(); 43 52 } 44 53 45 AmbientSound::~AmbientSound()54 void AmbientSound::preDestroy() 46 55 { 56 if (GameMode::playsSound()) 57 { 58 // Smoothly fade out by keeping a SmartPtr 59 SoundManager::getInstance().unregisterAmbientSound(this); 60 } 61 } 62 63 void AmbientSound::registerVariables() 64 { 65 registerVariable(ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::ambientSourceChanged)); 66 registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::loopingChanged)); 67 registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::pitchChanged)); 68 registerVariable(bPlayOnLoad_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::playOnLoadChanged)); 47 69 } 48 70 … … 50 72 { 51 73 SUPER(AmbientSound, XMLPort, xmlelement, mode); 52 XMLPortParamExtern(AmbientSound, BaseSound, this, "source", setSource, getSource,xmlelement, mode);53 XMLPortParam Extern(AmbientSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode);54 XMLPortParam Extern(AmbientSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);74 BaseSound::XMLPortExtern(xmlelement, mode); 75 XMLPortParam(AmbientSound, "ambientSource", setAmbientSource, getAmbientSource, xmlelement, mode); 76 XMLPortParam(AmbientSound, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode); 55 77 } 56 78 … … 60 82 XMLPortEventState(AmbientSound, BaseObject, "play", play, xmlelement, mode); 61 83 } 84 85 void AmbientSound::play() 86 { 87 if (GameMode::playsSound()) 88 SoundManager::getInstance().registerAmbientSound(this); 89 } 90 91 void AmbientSound::stop() 92 { 93 if (GameMode::playsSound()) 94 SoundManager::getInstance().unregisterAmbientSound(this); 95 } 96 97 void AmbientSound::pause() 98 { 99 if (GameMode::playsSound()) 100 SoundManager::getInstance().pauseAmbientSound(this); 101 } 102 103 float AmbientSound::getRealVolume() 104 { 105 assert(GameMode::playsSound()); 106 return SoundManager::getInstance().getRealVolume(SoundType::Music); 107 } 108 109 void AmbientSound::setAmbientSource(const std::string& source) 110 { 111 this->ambientSource_ = source; 112 this->moodChanged(this->getMood()); 113 } 114 115 void AmbientSound::moodChanged(const std::string& mood) 116 { 117 if (GameMode::playsSound()) 118 { 119 const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + this->ambientSource_; 120 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path); 121 if (fileInfo != NULL) 122 this->setSource(path); 123 else 124 COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl; 125 } 126 } 127 128 void AmbientSound::setPlayOnLoad(bool val) 129 { 130 this->bPlayOnLoad_ = val; 131 if (val) 132 this->play(); 133 } 134 135 void AmbientSound::changedActivity() 136 { 137 SUPER(AmbientSound, changedActivity); 138 if (this->isActive()) 139 this->play(); 140 else 141 this->stop(); 142 } 62 143 }
Note: See TracChangeset
for help on using the changeset viewer.