Changeset 6396
- Timestamp:
- Dec 22, 2009, 8:35:05 PM (15 years ago)
- Location:
- code/branches/presentation2/src/orxonox/items
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc
r6394 r6396 70 70 } 71 71 this->state_ = 0; 72 this-> steeringDirectionZ_ = 0.0;72 this->oldState_ = 0; 73 73 74 74 this->setSyncMode(ObjectDirection::Bidirectional); … … 106 106 void MultiStateEngine::registerVariables() 107 107 { 108 registerVariable(this->st eeringDirectionZ_, VariableDirection::ToServer);108 registerVariable(this->state_, VariableDirection::ToServer); 109 109 } 110 110 … … 113 113 if (this->getShip()) 114 114 { 115 const Vector3& velocity = this->getShip()->getLocalVelocity(); 116 115 117 if (this->getShip()->hasLocalController()) 116 this->steeringDirectionZ_ = this->getDirection().z; 118 { 119 const Vector3& direction = this->getDirection(); 120 bool forward = (direction.z < 0.0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD); 121 122 this->state_ = 0; 123 if (this->getShip()->getBoost() && forward) 124 this->state_ = Boost; 125 else if (forward && !this->state_) // this->state_ == Boost 126 this->state_ = Normal; 127 else if (direction.z > 0.0 && velocity.z < 0.0) 128 this->state_ = Brake; 129 else 130 this->state_ = Idle; 131 } 132 117 133 if (GameMode::isMaster()) 118 134 { 119 const Vector3& velocity = this->getShip()->getLocalVelocity();135 int changes = this->state_ | this->oldState_; 120 136 121 137 float pitch = velocity.length(); 122 bool forward = (this->steeringDirectionZ_ < 0.0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD); 123 124 int newState = 0; 125 if (this->getShip()->getBoost() && forward) 126 { 127 newState = Boost; 138 if (this->state_ & Normal) 139 defEngineSndNormal_->setPitch(clamp(pitch/MAX_VELOCITY_NORMAL + 1, 0.5f, 2.0f)); 140 if (this->state_ & Boost) 128 141 defEngineSndBoost_->setPitch(clamp(pitch/MAX_VELOCITY_BOOST + 1, 0.5f, 2.0f)); 129 } 130 else if (forward && !newState) // newState == Boost 131 { 132 newState = Normal; 133 defEngineSndNormal_->setPitch(clamp(pitch/MAX_VELOCITY_NORMAL + 1, 0.5f, 2.0f)); 134 } 135 else if (this->steeringDirectionZ_ > 0.0 && velocity.z < 0.0) 136 newState = Brake; 137 else 138 newState = Idle; 139 140 int changes = newState | this->state_; 142 141 143 if (changes & Idle) 142 144 { 143 lua_pushboolean(this->lua_->getInternalLuaState(), newState& Idle);145 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Idle); 144 146 lua_setglobal(this->lua_->getInternalLuaState(), "idle"); 145 147 } 146 148 if (changes & Normal) 147 149 { 148 lua_pushboolean(this->lua_->getInternalLuaState(), newState& Normal);150 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Normal); 149 151 lua_setglobal(this->lua_->getInternalLuaState(), "normal"); 150 if ( newState& Normal)152 if (this->state_ & Normal) 151 153 defEngineSndNormal_->play(); 152 154 else … … 155 157 if (changes & Brake) 156 158 { 157 lua_pushboolean(this->lua_->getInternalLuaState(), newState& Brake);159 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Brake); 158 160 lua_setglobal(this->lua_->getInternalLuaState(), "brake"); 159 161 } 160 162 if (changes & Boost) 161 163 { 162 lua_pushboolean(this->lua_->getInternalLuaState(), newState& Boost);164 lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Boost); 163 165 lua_setglobal(this->lua_->getInternalLuaState(), "boost"); 164 if ( newState& Boost)166 if (this->state_ & Boost) 165 167 defEngineSndBoost_->play(); 166 168 else … … 168 170 } 169 171 170 this-> state_ = newState;172 this->oldState_ = this->state_; 171 173 172 174 // Update all effect conditions -
code/branches/presentation2/src/orxonox/items/MultiStateEngine.h
r6391 r6396 68 68 69 69 private: 70 float steeringDirectionZ_;71 70 int state_; 71 int oldState_; 72 72 LuaState* lua_; 73 73 std::vector<EffectContainer*> effectContainers_;
Note: See TracChangeset
for help on using the changeset viewer.