Changeset 6202
- Timestamp:
- Dec 2, 2009, 4:52:42 PM (15 years ago)
- Location:
- code/branches/presentation2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/data/levels/templates/spaceship_assff.oxt
r6187 r6202 64 64 speedupdown = 50 65 65 66 defEngineSndNormal = "sounds/Engine_low.ogg" 67 66 68 accelerationfront = 500 67 69 accelerationbrake = 500 … … 81 83 </EffectContainer> 82 84 <EffectContainer condition="normal or brake"> 83 < WorldSound mainstate="activity" source="sounds/Engine_low.ogg" loop=1 active=false/>85 <!-- WorldSound mainstate="activity" source="sounds/Engine_low.ogg" loop=1 active=false --> 84 86 </EffectContainer> 85 87 <EffectContainer condition="normal or boost"> -
code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc
r6187 r6202 41 41 #include "worldentities/EffectContainer.h" 42 42 #include "worldentities/pawns/SpaceShip.h" 43 #include "sound/WorldSound.h" 43 44 44 45 namespace orxonox 45 46 { 46 47 static const float FORWARD_EFFECT_VELOCITY_THRESHOLD = 20; 48 static const float MAX_VELOCITY_NORMAL = 111; 49 static const float MAX_VELOCITY_BOOST = 221; 47 50 48 51 CreateFactory(MultiStateEngine); … … 51 54 { 52 55 RegisterObject(MultiStateEngine); 56 57 defEngineSndNormal_ = new WorldSound(this); 58 defEngineSndNormal_->setLooping(true); 53 59 54 60 this->lua_ = new LuaState(); … … 66 72 for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsBegin(); ++it2) 67 73 (*it2)->destroy(); 74 delete this->defEngineSndNormal_; 68 75 delete this->lua_; 69 76 } … … 74 81 SUPER(MultiStateEngine, XMLPort, xmlelement, mode); 75 82 XMLPortObject(MultiStateEngine, EffectContainer, "", addEffectContainer, getEffectContainer, xmlelement, mode); 83 XMLPortParam(MultiStateEngine, "defEngineSndNormal", setDefEngSndNormal, getDefEngSndNormal, xmlelement, mode); 76 84 } 77 85 … … 92 100 const Vector3& velocity = this->getShip()->getLocalVelocity(); 93 101 102 float pitch = velocity.length(); 94 103 bool forward = (direction.z < 0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD); 95 104 96 105 int newState = 0; 97 106 if (this->getShip()->getBoost() && forward) 107 { 98 108 newState = Boost; 109 pitch = pitch/MAX_VELOCITY_BOOST + 1; 110 pitch = pitch > 2 ? 2 : pitch; 111 pitch = pitch < 0.5 ? 0.5 : pitch; 112 defEngineSndNormal_->setPitch(pitch); 113 } 99 114 else if (forward && !newState) // newState == Boost 115 { 100 116 newState = Normal; 117 pitch = pitch/MAX_VELOCITY_NORMAL + 1; 118 pitch = pitch > 2 ? 2 : pitch; 119 pitch = pitch < 0.5 ? 0.5 : pitch; 120 defEngineSndNormal_->setPitch(pitch); 121 } 101 122 else if (direction.z > 0 && velocity.z < 0) 102 123 newState = Brake; … … 116 137 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Normal); 117 138 lua_setglobal(this->lua_->getInternalLuaState(), "normal"); 139 if(newState & Normal) 140 { 141 defEngineSndNormal_->play(); 142 } 143 else 144 { 145 defEngineSndNormal_->stop(); 146 } 118 147 } 119 148 if (changes & Brake) … … 150 179 if (!ship) 151 180 return; 181 182 this->getShip()->attach(defEngineSndNormal_); 152 183 153 184 for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it) … … 179 210 return NULL; 180 211 } 212 213 void MultiStateEngine::setDefEngSndNormal(const std::string &engineSound) 214 { 215 defEngineSndNormal_->setSource(engineSound); 216 } 217 218 const std::string& MultiStateEngine::getDefEngSndNormal() 219 { 220 return defEngineSndNormal_->getSource(); 221 } 181 222 } -
code/branches/presentation2/src/orxonox/items/MultiStateEngine.h
r6187 r6202 64 64 void addEffectContainer(EffectContainer* effect); 65 65 EffectContainer* getEffectContainer(unsigned int index) const; 66 void setDefEngSndNormal(const std::string& engineSound); 67 const std::string& getDefEngSndNormal(); 66 68 67 69 private: … … 69 71 LuaState* lua_; 70 72 std::vector<EffectContainer*> effectContainers_; 73 WorldSound* defEngineSndNormal_; 71 74 }; 72 75 } -
code/branches/presentation2/src/orxonox/sound/BaseSound.cc
r6190 r6202 50 50 RegisterRootObject(BaseSound); 51 51 52 this->volume_ = 1; 53 this->pitch_ = 1; 54 52 55 if (GameMode::playsSound()) 53 56 { … … 129 132 if (GameMode::playsSound()) 130 133 alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE)); 134 } 135 136 void BaseSound::setPitch(float pitch) 137 { 138 if (pitch > 2 || pitch < 0.5) 139 { 140 COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl; 141 pitch = pitch > 2 ? 2 : pitch; 142 pitch = pitch < 0.5 ? 0.5 : pitch; 143 } 144 this->pitch_ = pitch; 145 if (GameMode::playsSound()) 146 alSourcei(this->audioSource_, AL_PITCH, pitch); 131 147 } 132 148 … … 194 210 alSource3f(this->audioSource_, AL_POSITION, 0, 0, 0); 195 211 this->updateVolume(); 212 this->setPitch(this->getPitch()); 196 213 alSourcei (this->audioSource_, AL_LOOPING, (this->bLoop_ ? AL_TRUE : AL_FALSE)); 197 214 if (this->isPlaying() || this->isPaused()) -
code/branches/presentation2/src/orxonox/sound/BaseSound.h
r6188 r6202 74 74 void setLooping(bool val); 75 75 76 float getPitch() const { return this->pitch_; } 77 void setPitch(float pitch); 78 76 79 //ALuint getALAudioSource(void); 77 80 … … 92 95 std::string source_; 93 96 float volume_; 97 float pitch_; 94 98 bool bLoop_; 95 99 State state_;
Note: See TracChangeset
for help on using the changeset viewer.