Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6327


Ignore:
Timestamp:
Dec 12, 2009, 5:45:57 PM (14 years ago)
Author:
rgrieder
Message:

Engine synchronisation seems to work more or less.
Fire sound still doesn't work on client.

Location:
code/branches/presentation2/src/orxonox
Files:
3 edited

Legend:

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

    r6321 r6327  
    5656        RegisterObject(MultiStateEngine);
    5757
    58         if( GameMode::isMaster() )
     58        if (GameMode::isMaster())
    5959        {
    6060            this->defEngineSndNormal_ = new WorldSound(this);
    61             this->defEngineSndBoost_ = new WorldSound(this);
     61            this->defEngineSndBoost_  = new WorldSound(this);
    6262            this->defEngineSndNormal_->setLooping(true);
    6363            this->defEngineSndBoost_->setLooping(true);
     64            this->lua_ = new LuaState();
    6465        }
    6566        else
     
    6768            this->defEngineSndBoost_ = 0;
    6869            this->defEngineSndNormal_ = 0;
    69         }
    70 
    71         this->lua_ = new LuaState();
     70            this->lua_ = 0;
     71        }
    7272        this->state_ = 0;
    73 
     73        this->steeringDirectionZ_ = 0;
     74
     75        this->setSyncMode(ObjectDirection::Bidirectional);
    7476        this->registerVariables();
    7577    }
     
    7779    MultiStateEngine::~MultiStateEngine()
    7880    {
    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_;
    9096        }
    9197    }
     
    101107    void MultiStateEngine::registerVariables()
    102108    {
    103         registerVariable(this->state_, VariableDirection::ToServer);
     109        registerVariable(this->steeringDirectionZ_, VariableDirection::ToServer);
    104110    }
    105111
     
    108114        if (this->getShip())
    109115        {
    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())
    112119            {
    113                 this->setSyncMode(ObjectDirection::Bidirectional);
    114 
    115                 const Vector3& direction = this->getDirection();
    116120                const Vector3& velocity = this->getShip()->getLocalVelocity();
    117121
    118122                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);
    120124
    121125                int newState = 0;
     
    123127                {
    124128                    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));
    129130                }
    130131                else if (forward && !newState) // newState == Boost
    131132                {
    132133                    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)
    139137                    newState = Brake;
    140138                else
    141139                    newState = Idle;
    142140
    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();
    193176            }
    194177        }
  • code/branches/presentation2/src/orxonox/items/MultiStateEngine.h

    r6207 r6327  
    7171
    7272        private:
     73            int steeringDirectionZ_;
    7374            int state_;
    7475            LuaState* lua_;
  • code/branches/presentation2/src/orxonox/sound/BaseSound.cc

    r6322 r6327  
    200200    void BaseSound::setSource(const std::string& source)
    201201    {
    202         if (!GameMode::playsSound() || source == this->source_)
     202        if (!GameMode::playsSound())
    203203        {
    204204            this->source_ = source;
     
    208208        if (this->soundBuffer_ != NULL)
    209209        {
     210            if (this->soundBuffer_->getFilename() == source)
     211            {
     212                assert(this->source_ == source_);
     213                return;
     214            }
    210215            // Stopping is imperative here!
    211216            if (alIsSource(this->audioSource_))
     
    248253    void BaseSound::stateChanged()
    249254    {
    250         CCOUT(0) << "changed state to " << this->state_ << endl;
    251         switch( this->state_ )
     255        switch (this->state_)
    252256        {
    253257            case Playing:
Note: See TracChangeset for help on using the changeset viewer.