Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 10, 2008, 1:38:17 PM (15 years ago)
Author:
rgrieder
Message:

Trying to synchronise phyiscs over the network.

  • Removed derivation of CollisionShape from WorldEntity (BaseObject instead).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2300 r2374  
    5757        this->bDestroyWhenPlayerLeft_ = false;
    5858
    59         this->acceleration_ = Vector3::ZERO;
    60 
    61         this->server_position_ = Vector3::ZERO;
    62         this->client_position_ = Vector3::ZERO;
    63         this->server_velocity_ = Vector3::ZERO;
    64         this->client_velocity_ = Vector3::ZERO;
    65         this->server_orientation_ = Quaternion::IDENTITY;
    66         this->client_orientation_ = Quaternion::IDENTITY;
     59        this->server_position_        = Vector3::ZERO;
     60        this->client_position_         = Vector3::ZERO;
     61        this->server_linear_velocity_ = Vector3::ZERO;
     62        this->client_linear_velocity_ = Vector3::ZERO;
     63        this->server_orientation_      = Quaternion::IDENTITY;
     64        this->client_orientation_      = Quaternion::IDENTITY;
     65        this->server_angular_velocity_ = Vector3::ZERO;
     66        this->client_angular_velocity_ = Vector3::ZERO;
    6767
    6868        this->registerVariables();
     
    226226    void ControllableEntity::tick(float dt)
    227227    {
     228        MovableEntity::tick(dt);
     229
    228230        if (this->isActive())
    229231        {
    230             if (!this->isDynamic())
    231             {
    232                 this->velocity_ += (dt * this->acceleration_);
    233                 this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
    234             }
    235 
    236             if (Core::isMaster())
    237             {
    238                 this->server_velocity_ = this->velocity_;
    239                 this->server_position_ = this->node_->getPosition();
    240             }
    241             else if (this->bControlled_)
    242             {
    243 //                COUT(2) << "setting client position" << endl;
    244                 this->client_velocity_ = this->velocity_;
    245                 this->client_position_ = this->node_->getPosition();
    246             }
    247232        }
    248233    }
     
    252237        REGISTERSTRING(this->cameraPositionTemplate_, network::direction::toclient);
    253238
    254         REGISTERDATA(this->server_position_,    network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
    255         REGISTERDATA(this->server_velocity_,    network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity));
    256         REGISTERDATA(this->server_orientation_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation));
    257 
    258         REGISTERDATA(this->server_overwrite_,   network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
    259         REGISTERDATA(this->client_overwrite_,   network::direction::toserver);
    260 
    261         REGISTERDATA(this->client_position_,    network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition));
    262         REGISTERDATA(this->client_velocity_,    network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientVelocity));
    263         REGISTERDATA(this->client_orientation_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation));
    264 
     239        REGISTERDATA(this->server_position_,         network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
     240        REGISTERDATA(this->server_linear_velocity_,  network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerLinearVelocity));
     241        REGISTERDATA(this->server_orientation_,      network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation));
     242        REGISTERDATA(this->server_angular_velocity_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerAngularVelocity));
     243
     244        REGISTERDATA(this->server_overwrite_,        network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
     245        REGISTERDATA(this->client_overwrite_,        network::direction::toserver);
     246
     247        REGISTERDATA(this->client_position_,         network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition));
     248        REGISTERDATA(this->client_linear_velocity_,  network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientLinearVelocity));
     249        REGISTERDATA(this->client_orientation_,      network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation));
     250        REGISTERDATA(this->client_angular_velocity_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientAngularVelocity));
    265251
    266252        REGISTERDATA(this->playerID_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID));
     
    270256    {
    271257        if (!this->bControlled_)
    272             this->node_->setPosition(this->server_position_);
    273     }
    274 
    275     void ControllableEntity::processServerVelocity()
    276     {
    277         if (!this->bControlled_)
    278             this->velocity_ = this->server_velocity_;
     258        {
     259            //COUT(0) << "override with server position: " << this << std::endl;
     260            this->setPosition(this->server_position_);
     261        }
     262    }
     263
     264    void ControllableEntity::processServerLinearVelocity()
     265    {
     266        if (!this->bControlled_)
     267            this->setVelocity(this->server_linear_velocity_);
    279268    }
    280269
     
    282271    {
    283272        if (!this->bControlled_)
    284             this->node_->setOrientation(this->server_orientation_);
     273            this->setOrientation(this->server_orientation_);
     274    }
     275
     276    void ControllableEntity::processServerAngularVelocity()
     277    {
     278        if (!this->bControlled_)
     279            this->setAngularVelocity(this->server_angular_velocity_);
    285280    }
    286281
    287282    void ControllableEntity::processOverwrite()
    288283    {
    289         if (this->bControlled_)
    290         {
    291             this->setPosition(this->server_position_);
    292             this->setVelocity(this->server_velocity_);
    293             this->setOrientation(this->server_orientation_);
    294 
    295             this->client_overwrite_ = this->server_overwrite_;
    296         }
     284        //if (this->bControlled_)
     285        //{
     286        //    COUT(0) << "complete override: " << this << std::endl;
     287        //    this->setPosition(this->server_position_);
     288        //    this->setVelocity(this->server_velocity_);
     289        //    this->setOrientation(this->server_orientation_);
     290
     291        //    this->client_overwrite_ = this->server_overwrite_;
     292        //}
    297293    }
    298294
    299295    void ControllableEntity::processClientPosition()
    300296    {
    301         if (this->server_overwrite_ == this->client_overwrite_)
    302         {
     297        //if (this->server_overwrite_ == this->client_overwrite_)
     298        if (!this->bControlled_)
     299        {
     300            //COUT(0) << "override with client position: " << this << std::endl;
    303301//            COUT(2) << "callback: setting client position" << endl;
    304             this->node_->setPosition(this->client_position_);
    305             this->server_position_ = this->client_position_;
    306         }
    307 //        else
    308 //          COUT(2) << "callback: not setting client position" << endl;
    309     }
    310 
    311     void ControllableEntity::processClientVelocity()
    312     {
    313         if (this->server_overwrite_ == this->client_overwrite_)
    314         {
    315             this->velocity_ = this->client_velocity_;
    316             this->server_velocity_ = this->client_velocity_;
     302            this->setPosition(this->client_position_);
     303            //this->server_position_ = this->client_position_;
     304        }
     305        //else
     306        //  COUT(2) << "callback: not setting client position" << endl;
     307    }
     308
     309    void ControllableEntity::processClientLinearVelocity()
     310    {
     311        if (!this->bControlled_)
     312        //if (this->server_overwrite_ == this->client_overwrite_)
     313        {
     314            this->setVelocity(this->client_linear_velocity_);
     315            //this->server_velocity_ = this->client_velocity_;
    317316        }
    318317    }
     
    320319    void ControllableEntity::processClientOrientation()
    321320    {
    322         if (this->server_overwrite_ == this->client_overwrite_)
    323         {
    324             this->node_->setOrientation(this->client_orientation_);
    325             this->server_orientation_ = this->client_orientation_;
    326         }
    327     }
    328 
    329     void ControllableEntity::positionChanged()
     321        if (!this->bControlled_)
     322        //if (this->server_overwrite_ == this->client_overwrite_)
     323        {
     324            this->setOrientation(this->client_orientation_);
     325            //this->server_orientation_ = this->client_orientation_;
     326        }
     327    }
     328
     329    void ControllableEntity::processClientAngularVelocity()
     330    {
     331        if (!this->bControlled_)
     332        //if (this->server_overwrite_ == this->client_overwrite_)
     333        {
     334            this->setAngularVelocity(this->client_angular_velocity_);
     335            //this->server_velocity_ = this->client_velocity_;
     336        }
     337    }
     338
     339    void ControllableEntity::positionChanged(bool bContinuous)
    330340    {
    331341        if (Core::isMaster())
     
    340350    }
    341351
    342     void ControllableEntity::orientationChanged()
     352    void ControllableEntity::orientationChanged(bool bContinuous)
    343353    {
    344354        if (Core::isMaster())
     
    353363    }
    354364
    355     void ControllableEntity::velocityChanged()
     365    void ControllableEntity::linearVelocityChanged(bool bContinuous)
    356366    {
    357367        if (Core::isMaster())
    358368        {
    359             this->server_velocity_ = this->getVelocity();
     369            this->server_linear_velocity_ = this->getVelocity();
    360370            ++this->server_overwrite_;
    361371        }
    362372        else if (this->bControlled_)
    363373        {
    364             this->client_velocity_ = this->getVelocity();
     374            this->client_linear_velocity_ = this->getVelocity();
     375        }
     376    }
     377
     378    void ControllableEntity::angularVelocityChanged(bool bContinuous)
     379    {
     380        if (Core::isMaster())
     381        {
     382            this->server_angular_velocity_ = this->getAngularVelocity();
     383            ++this->server_overwrite_;
     384        }
     385        else if (this->bControlled_)
     386        {
     387            this->client_angular_velocity_ = this->getAngularVelocity();
    365388        }
    366389    }
Note: See TracChangeset for help on using the changeset viewer.