Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 27, 2008, 4:08:51 AM (16 years ago)
Author:
landauf
Message:

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

File:
1 edited

Legend:

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

    r2006 r2019  
    4343    CreateFactory(ControllableEntity);
    4444
    45     ControllableEntity::ControllableEntity()
     45    ControllableEntity::ControllableEntity(BaseObject* creator) : WorldEntity(creator)
    4646    {
    4747        RegisterObject(ControllableEntity);
     
    7171    ControllableEntity::~ControllableEntity()
    7272    {
    73         if (this->isInitialized() && this->bControlled_)
    74             this->stopLocalControl();
     73        if (this->isInitialized())
     74        {
     75            if (this->bControlled_)
     76                this->stopLocalControl();
     77
     78            if (this->hud_)
     79                delete this->hud_;
     80
     81            if (this->camera_)
     82                delete this->camera_;
     83        }
    7584    }
    7685
     
    92101        this->player_ = player;
    93102        this->playerID_ = player->getObjectID();
    94         this->bControlled_ = player->isLocalPlayer();
     103        this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer());
    95104
    96105        if (this->bControlled_)
    97106        {
    98107            this->startLocalControl();
    99             this->setObjectMode(network::direction::bidirectional);
     108
     109            if (!Core::isMaster())
     110                this->setObjectMode(network::direction::bidirectional);
    100111        }
    101112    }
     
    115126    }
    116127
    117     void ControllableEntity::updatePlayer()
    118     {
     128    void ControllableEntity::networkcallback_changedplayerID()
     129    {
     130        // just do this in case the entity wasn't yet synchronized when the corresponding PlayerInfo got our objectID
    119131        if (this->playerID_ != network::OBJECTID_UNKNOWN)
    120132        {
    121133            this->player_ = dynamic_cast<PlayerInfo*>(network::Synchronisable::getSynchronisable(this->playerID_));
    122             if (this->player_ && (this->player_->getPawn() != this))
     134            if (this->player_ && (this->player_->getControllableEntity() != this))
    123135                this->player_->startControl(this);
    124136        }
     
    128140    {
    129141        std::cout << this->getObjectID() << " ###### start local control" << std::endl;
    130         this->camera_ = new Camera();
     142        this->camera_ = new Camera(this);
    131143        this->camera_->requestFocus();
    132144        this->attach(this->camera_);
     
    134146        if (this->hudtemplate_ != "")
    135147        {
    136             this->hud_ = new OverlayGroup();
     148            this->hud_ = new OverlayGroup(this);
    137149            this->hud_->addTemplate(this->hudtemplate_);
    138150        }
     
    184196        REGISTERDATA(this->client_overwrite_,   network::direction::toserver);
    185197
    186         REGISTERDATA(this->playerID_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::updatePlayer));
     198        REGISTERDATA(this->playerID_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID));
    187199    }
    188200
Note: See TracChangeset for help on using the changeset viewer.