Changeset 6412 for code/branches/pickup2/src/orxonox/sound/WorldSound.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/WorldSound.cc
r5929 r6412 35 35 #include "core/EventIncludes.h" 36 36 #include "core/XMLPort.h" 37 #include "Scene.h" 38 #include "SoundManager.h" 39 #include <core/ConsoleCommandCompilation.h> 37 40 38 41 namespace orxonox … … 44 47 { 45 48 RegisterObject(WorldSound); 49 // WorldSound buffers should be pooled when they're not used anymore 50 this->bPooling_ = true; 51 this->registerVariables(); 46 52 } 47 53 48 WorldSound::~WorldSound()54 void WorldSound::registerVariables() 49 55 { 56 registerVariable(volume_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::volumeChanged)); 57 registerVariable(source_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::sourceChanged)); 58 registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::loopingChanged)); 59 registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged)); 60 registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged)); 50 61 } 51 62 … … 53 64 { 54 65 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); 66 BaseSound::XMLPortExtern(xmlelement, mode); 58 67 } 59 68 … … 62 71 SUPER(WorldSound, XMLEventPort, xmlelement, mode); 63 72 XMLPortEventState(WorldSound, BaseObject, "play", play, xmlelement, mode); 73 } 74 75 void WorldSound::initialiseSource() 76 { 77 BaseSound::initialiseSource(); 78 if (this->getScene()) 79 { 80 float refDist = this->getScene()->getSoundReferenceDistance(); 81 alSourcef(this->audioSource_, AL_REFERENCE_DISTANCE, refDist); 82 // TODO: 500 is very magical here. Derive something better 83 alSourcef(this->audioSource_, AL_MAX_DISTANCE, refDist * 500); 84 } 85 this->tick(0); // update position, orientation and velocity 64 86 } 65 87 … … 80 102 COUT(2) << "Sound: OpenAL: Invalid sound velocity" << std::endl; 81 103 82 const Quaternion& orient = this->getWorldOrientation(); 83 Vector3 at = orient.zAxis(); 84 alSource3f(this->audioSource_, AL_DIRECTION, at.x, at.y, at.z); 104 const Vector3& direction = -this->getWorldOrientation().zAxis(); 105 alSource3f(this->audioSource_, AL_DIRECTION, direction.x, direction.y, direction.z); 85 106 error = alGetError(); 86 107 if (error == AL_INVALID_VALUE) … … 89 110 } 90 111 112 void WorldSound::changedActivity() 113 { 114 SUPER(WorldSound, changedActivity); 115 if (this->isActive()) 116 this->play(); 117 else 118 this->stop(); 119 } 120 121 float WorldSound::getRealVolume() 122 { 123 assert(GameMode::playsSound()); 124 return SoundManager::getInstance().getRealVolume(SoundType::Effects); 125 } 91 126 }
Note: See TracChangeset
for help on using the changeset viewer.