Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6396


Ignore:
Timestamp:
Dec 22, 2009, 8:35:05 PM (14 years ago)
Author:
rgrieder
Message:

Fixed space ship boost sound synchronisation.

Location:
code/branches/presentation2/src/orxonox/items
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc

    r6394 r6396  
    7070        }
    7171        this->state_ = 0;
    72         this->steeringDirectionZ_ = 0.0;
     72        this->oldState_ = 0;
    7373
    7474        this->setSyncMode(ObjectDirection::Bidirectional);
     
    106106    void MultiStateEngine::registerVariables()
    107107    {
    108         registerVariable(this->steeringDirectionZ_, VariableDirection::ToServer);
     108        registerVariable(this->state_, VariableDirection::ToServer);
    109109    }
    110110
     
    113113        if (this->getShip())
    114114        {
     115            const Vector3& velocity = this->getShip()->getLocalVelocity();
     116
    115117            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
    117133            if (GameMode::isMaster())
    118134            {
    119                 const Vector3& velocity = this->getShip()->getLocalVelocity();
     135                int changes = this->state_ | this->oldState_;
    120136
    121137                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)
    128141                    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
    141143                if (changes & Idle)
    142144                {
    143                     lua_pushboolean(this->lua_->getInternalLuaState(), newState & Idle);
     145                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Idle);
    144146                    lua_setglobal(this->lua_->getInternalLuaState(), "idle");
    145147                }
    146148                if (changes & Normal)
    147149                {
    148                     lua_pushboolean(this->lua_->getInternalLuaState(), newState & Normal);
     150                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Normal);
    149151                    lua_setglobal(this->lua_->getInternalLuaState(), "normal");
    150                     if (newState & Normal)
     152                    if (this->state_ & Normal)
    151153                        defEngineSndNormal_->play();
    152154                    else
     
    155157                if (changes & Brake)
    156158                {
    157                     lua_pushboolean(this->lua_->getInternalLuaState(), newState & Brake);
     159                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Brake);
    158160                    lua_setglobal(this->lua_->getInternalLuaState(), "brake");
    159161                }
    160162                if (changes & Boost)
    161163                {
    162                     lua_pushboolean(this->lua_->getInternalLuaState(), newState & Boost);
     164                    lua_pushboolean(this->lua_->getInternalLuaState(), this->state_ & Boost);
    163165                    lua_setglobal(this->lua_->getInternalLuaState(), "boost");
    164                     if (newState & Boost)
     166                    if (this->state_ & Boost)
    165167                        defEngineSndBoost_->play();
    166168                    else
     
    168170                }
    169171
    170                 this->state_ = newState;
     172                this->oldState_ = this->state_;
    171173
    172174                // Update all effect conditions
  • code/branches/presentation2/src/orxonox/items/MultiStateEngine.h

    r6391 r6396  
    6868
    6969        private:
    70             float steeringDirectionZ_;
    7170            int state_;
     71            int oldState_;
    7272            LuaState* lua_;
    7373            std::vector<EffectContainer*> effectContainers_;
Note: See TracChangeset for help on using the changeset viewer.