Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3038


Ignore:
Timestamp:
May 24, 2009, 5:42:50 PM (16 years ago)
Author:
landauf
Message:

Cleaned up setPlayer/removePlayer interface between PlayerInfo and ControllableEntity. The whole control is now up to the PlayerInfo, the respective functions in ControllableEntity are now protected.

Location:
code/trunk/src/orxonox/objects
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/objects/controllers/HumanController.cc

    r2872 r3038  
    159159                pawn->kill();
    160160            else if (HumanController::localController_s->player_)
    161                 HumanController::localController_s->player_->stopControl(HumanController::localController_s->controllableEntity_);
     161                HumanController::localController_s->player_->stopControl();
    162162        }
    163163    }
  • code/trunk/src/orxonox/objects/gametypes/Gametype.cc

    r3033 r3038  
    130130            {
    131131                ControllableEntity* oldentity = it->first->getControllableEntity();
    132        
     132
    133133                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(oldentity->getCreator());
    134134                if (oldentity->getCamera())
     
    143143                }
    144144
    145                 it->first->stopControl(oldentity, true);
    146145                it->first->startControl(entity);
    147146            }
     
    421420
    422421    void Gametype::addTime(float t)
    423     { 
     422    {
    424423        if (this->timeLimit_ == 0)
    425424          this->time_ -= t;
     
    429428
    430429    void Gametype::removeTime(float t)
    431     { 
     430    {
    432431        if (this->timeLimit_ == 0)
    433432          this->time_ += t;
     
    437436
    438437    void Gametype::resetTimer()
    439     { 
     438    {
    440439        this->resetTimer(timeLimit_);
    441440    }
    442441
    443442    void Gametype::resetTimer(float t)
    444     { 
     443    {
    445444        this->timeLimit_ = t;
    446445        this->time_ = t;
  • code/trunk/src/orxonox/objects/infos/PlayerInfo.cc

    r2973 r3038  
    6262        if (this->BaseObject::isInitialized())
    6363        {
    64             this->stopControl(this->controllableEntity_);
     64            this->stopControl();
    6565
    6666            if (this->controller_)
     
    142142    }
    143143
    144     void PlayerInfo::startControl(ControllableEntity* entity, bool callback)
    145     {
    146         if (entity == this->controllableEntity_)
     144    void PlayerInfo::startControl(ControllableEntity* entity)
     145    {
     146        if (!entity || entity == this->controllableEntity_)
    147147            return;
    148148
    149149        if (this->controllableEntity_)
    150             this->stopControl(this->controllableEntity_, callback);
     150            this->stopControl();
    151151
    152152        this->controllableEntity_ = entity;
    153 
    154         if (entity)
    155         {
    156             this->controllableEntityID_ = entity->getObjectID();
    157             entity->setPlayer(this);
    158             this->bReadyToSpawn_ &= (!this->bSetUnreadyAfterSpawn_);
    159         }
    160         else
    161         {
    162             this->controllableEntityID_ = OBJECTID_UNKNOWN;
    163         }
     153        this->controllableEntityID_ = entity->getObjectID();
     154
     155        entity->setPlayer(this);
     156
     157        this->bReadyToSpawn_ &= (!this->bSetUnreadyAfterSpawn_);
    164158
    165159        if (this->controller_)
     
    169163    }
    170164
    171     void PlayerInfo::stopControl(ControllableEntity* entity, bool callback)
    172     {
    173         if (entity && this->controllableEntity_ == entity)
    174         {
    175             this->controllableEntity_ = 0;
    176             this->controllableEntityID_ = OBJECTID_UNKNOWN;
    177 
    178             if (this->controller_)
    179                 this->controller_->setControllableEntity(0);
    180 
    181             if (callback)
    182                 entity->removePlayer();
    183 
    184             this->changedControllableEntity();
    185         }
     165    void PlayerInfo::stopControl()
     166    {
     167        ControllableEntity* entity = this->controllableEntity_;
     168
     169        if (!entity)
     170            return;
     171
     172        this->controllableEntity_ = 0;
     173        this->controllableEntityID_ = OBJECTID_UNKNOWN;
     174
     175        if (this->controller_)
     176            this->controller_->setControllableEntity(0);
     177
     178        entity->removePlayer();
     179
     180        this->changedControllableEntity();
    186181    }
    187182
     
    192187            Synchronisable* temp = Synchronisable::getSynchronisable(this->controllableEntityID_);
    193188            ControllableEntity* entity = dynamic_cast<ControllableEntity*>(temp);
    194 
    195189            this->startControl(entity);
    196190        }
    197191        else
    198192        {
    199             this->stopControl(this->controllableEntity_);
     193            this->stopControl();
    200194        }
    201195    }
  • code/trunk/src/orxonox/objects/infos/PlayerInfo.h

    r2973 r3038  
    6868                { return this->bReadyToSpawn_; }
    6969
    70             void startControl(ControllableEntity* entity, bool callback = true);
    71             void stopControl(ControllableEntity* entity, bool callback = true);
     70            void startControl(ControllableEntity* entity);
     71            void stopControl();
    7272
    7373            inline ControllableEntity* getControllableEntity() const
  • code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2973 r3038  
    9191
    9292            if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
    93                 this->getPlayer()->stopControl(this, false);
     93                this->getPlayer()->stopControl();
    9494
    9595            if (this->hud_)
  • code/trunk/src/orxonox/objects/worldentities/ControllableEntity.h

    r2973 r3038  
    3939    class _OrxonoxExport ControllableEntity : public MobileEntity
    4040    {
     41        friend class PlayerInfo; // PlayerInfo uses setPlayer and removePlayer
     42
    4143        public:
    4244            ControllableEntity(BaseObject* creator);
     
    5052            virtual void changedPlayer() {}
    5153
    52             virtual void setPlayer(PlayerInfo* player);
    53             virtual void removePlayer();
    5454            inline PlayerInfo* getPlayer() const
    5555                { return this->player_; }
     
    131131
    132132        protected:
     133            virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead
     134            virtual void removePlayer();                // don't call this directly, use friend class PlayerInfo instead
     135
    133136            virtual void startLocalHumanControl();
    134137            virtual void stopLocalHumanControl();
  • code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r3033 r3038  
    209209                this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
    210210
    211             if (this->getPlayer())
    212                 this->getPlayer()->stopControl(this);
     211            if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
     212                this->getPlayer()->stopControl();
    213213
    214214            if (GameMode::isMaster())
  • code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.h

    r2826 r3038  
    4747            virtual void tick(float dt);
    4848            void registerVariables();
    49 
    50             virtual void setPlayer(PlayerInfo* player);
    51             virtual void removePlayer();
    5249
    5350            inline bool isAlive() const
     
    113110
    114111        protected:
     112            virtual void setPlayer(PlayerInfo* player);
     113            virtual void removePlayer();
     114
    115115            virtual void death();
    116116            virtual void deatheffect();
  • code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.h

    r2662 r3038  
    4646            virtual void tick(float dt);
    4747
    48             virtual void setPlayer(PlayerInfo* player);
    49             virtual void startLocalHumanControl();
    50 
    5148            virtual void moveFrontBack(const Vector2& value);
    5249            virtual void moveRightLeft(const Vector2& value);
     
    5956            virtual void fire(WeaponMode::Enum fireMode);
    6057            virtual void greet();
     58
     59        protected:
     60            virtual void setPlayer(PlayerInfo* player);
     61            virtual void startLocalHumanControl();
    6162
    6263        private:
Note: See TracChangeset for help on using the changeset viewer.