Changeset 6327
- Timestamp:
- Dec 12, 2009, 5:45:57 PM (15 years ago)
- Location:
- code/branches/presentation2/src/orxonox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc
r6321 r6327 56 56 RegisterObject(MultiStateEngine); 57 57 58 if ( GameMode::isMaster())58 if (GameMode::isMaster()) 59 59 { 60 60 this->defEngineSndNormal_ = new WorldSound(this); 61 this->defEngineSndBoost_ = new WorldSound(this);61 this->defEngineSndBoost_ = new WorldSound(this); 62 62 this->defEngineSndNormal_->setLooping(true); 63 63 this->defEngineSndBoost_->setLooping(true); 64 this->lua_ = new LuaState(); 64 65 } 65 66 else … … 67 68 this->defEngineSndBoost_ = 0; 68 69 this->defEngineSndNormal_ = 0; 69 } 70 71 this->lua_ = new LuaState(); 70 this->lua_ = 0; 71 } 72 72 this->state_ = 0; 73 73 this->steeringDirectionZ_ = 0; 74 75 this->setSyncMode(ObjectDirection::Bidirectional); 74 76 this->registerVariables(); 75 77 } … … 77 79 MultiStateEngine::~MultiStateEngine() 78 80 { 79 if (this->isInitialized() && !this->getShip()) 80 { 81 // We have no ship, so the effects are not attached and won't be destroyed automatically 82 for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it) 83 for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsBegin(); ++it2) 84 (*it2)->destroy(); 85 if( this->defEngineSndNormal_ ) 86 delete this->defEngineSndNormal_; 87 if( this->defEngineSndBoost_ ) 88 delete this->defEngineSndBoost_; 89 delete this->lua_; 81 if (this->isInitialized()) 82 { 83 if (!this->getShip()) 84 { 85 // We have no ship, so the effects are not attached and won't be destroyed automatically 86 for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it) 87 for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsBegin(); ++it2) 88 (*it2)->destroy(); 89 if (this->defEngineSndNormal_) 90 delete this->defEngineSndNormal_; 91 if (this->defEngineSndBoost_) 92 delete this->defEngineSndBoost_; 93 } 94 if (this->lua_) 95 delete this->lua_; 90 96 } 91 97 } … … 101 107 void MultiStateEngine::registerVariables() 102 108 { 103 registerVariable(this->st ate_, VariableDirection::ToServer);109 registerVariable(this->steeringDirectionZ_, VariableDirection::ToServer); 104 110 } 105 111 … … 108 114 if (this->getShip()) 109 115 { 110 // if (this->getShip()->hasLocalController()) 111 if (GameMode::isMaster() && this->getShip()->getController()) 116 if (this->getShip()->hasLocalController()) 117 this->steeringDirectionZ_ = this->getDirection().z; 118 if (GameMode::isMaster()) 112 119 { 113 this->setSyncMode(ObjectDirection::Bidirectional);114 115 const Vector3& direction = this->getDirection();116 120 const Vector3& velocity = this->getShip()->getLocalVelocity(); 117 121 118 122 float pitch = velocity.length(); 119 bool forward = ( direction.z< 0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD);123 bool forward = (this->steeringDirectionZ_ < 0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD); 120 124 121 125 int newState = 0; … … 123 127 { 124 128 newState = Boost; 125 pitch = pitch/MAX_VELOCITY_BOOST + 1; 126 pitch = pitch > 2 ? 2 : pitch; 127 pitch = pitch < 0.5 ? 0.5 : pitch; 128 defEngineSndBoost_->setPitch(pitch); 129 defEngineSndBoost_->setPitch(clamp(pitch/MAX_VELOCITY_BOOST + 1, 0.5f, 2.0f)); 129 130 } 130 131 else if (forward && !newState) // newState == Boost 131 132 { 132 133 newState = Normal; 133 pitch = pitch/MAX_VELOCITY_NORMAL + 1; 134 pitch = pitch > 2 ? 2 : pitch; 135 pitch = pitch < 0.5 ? 0.5 : pitch; 136 defEngineSndNormal_->setPitch(pitch); 137 } 138 else if (direction.z > 0 && velocity.z < 0) 134 defEngineSndNormal_->setPitch(clamp(pitch/MAX_VELOCITY_NORMAL + 1, 0.5f, 2.0f)); 135 } 136 else if (this->steeringDirectionZ_ > 0 && velocity.z < 0) 139 137 newState = Brake; 140 138 else 141 139 newState = Idle; 142 140 143 if (newState != this->state_) 144 { 145 int changes = newState | this->state_; 146 if (changes & Idle) 147 { 148 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Idle); 149 lua_setglobal(this->lua_->getInternalLuaState(), "idle"); 150 } 151 if (changes & Normal) 152 { 153 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Normal); 154 lua_setglobal(this->lua_->getInternalLuaState(), "normal"); 155 if(newState & Normal) 156 { 157 defEngineSndNormal_->play(); 158 } 159 else 160 { 161 defEngineSndNormal_->stop(); 162 } 163 } 164 if (changes & Brake) 165 { 166 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Brake); 167 lua_setglobal(this->lua_->getInternalLuaState(), "brake"); 168 } 169 if (changes & Boost) 170 { 171 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Boost); 172 lua_setglobal(this->lua_->getInternalLuaState(), "boost"); 173 if(newState & Boost) 174 { 175 defEngineSndBoost_->play(); 176 } 177 else 178 { 179 defEngineSndBoost_->stop(); 180 } 181 } 182 183 // Update all effect conditions 184 for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it) 185 (*it)->updateCondition(); 186 187 this->state_ = newState; 188 } 189 } 190 191 if (GameMode::isMaster()) 192 { 141 int changes = newState | this->state_; 142 if (changes & Idle) 143 { 144 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Idle); 145 lua_setglobal(this->lua_->getInternalLuaState(), "idle"); 146 } 147 if (changes & Normal) 148 { 149 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Normal); 150 lua_setglobal(this->lua_->getInternalLuaState(), "normal"); 151 if (newState & Normal) 152 defEngineSndNormal_->play(); 153 else 154 defEngineSndNormal_->stop(); 155 } 156 if (changes & Brake) 157 { 158 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Brake); 159 lua_setglobal(this->lua_->getInternalLuaState(), "brake"); 160 } 161 if (changes & Boost) 162 { 163 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Boost); 164 lua_setglobal(this->lua_->getInternalLuaState(), "boost"); 165 if (newState & Boost) 166 defEngineSndBoost_->play(); 167 else 168 defEngineSndBoost_->stop(); 169 } 170 171 this->state_ = newState; 172 173 // Update all effect conditions 174 for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it) 175 (*it)->updateCondition(); 193 176 } 194 177 } -
code/branches/presentation2/src/orxonox/items/MultiStateEngine.h
r6207 r6327 71 71 72 72 private: 73 int steeringDirectionZ_; 73 74 int state_; 74 75 LuaState* lua_; -
code/branches/presentation2/src/orxonox/sound/BaseSound.cc
r6322 r6327 200 200 void BaseSound::setSource(const std::string& source) 201 201 { 202 if (!GameMode::playsSound() || source == this->source_)202 if (!GameMode::playsSound()) 203 203 { 204 204 this->source_ = source; … … 208 208 if (this->soundBuffer_ != NULL) 209 209 { 210 if (this->soundBuffer_->getFilename() == source) 211 { 212 assert(this->source_ == source_); 213 return; 214 } 210 215 // Stopping is imperative here! 211 216 if (alIsSource(this->audioSource_)) … … 248 253 void BaseSound::stateChanged() 249 254 { 250 CCOUT(0) << "changed state to " << this->state_ << endl; 251 switch( this->state_ ) 255 switch (this->state_) 252 256 { 253 257 case Playing:
Note: See TracChangeset
for help on using the changeset viewer.