[Orxonox-commit 462] r3038 - in trunk/src/orxonox/objects: controllers gametypes infos worldentities worldentities/pawns

landauf at orxonox.net landauf at orxonox.net
Sun May 24 17:42:51 CEST 2009


Author: landauf
Date: 2009-05-24 17:42:50 +0200 (Sun, 24 May 2009)
New Revision: 3038

Modified:
   trunk/src/orxonox/objects/controllers/HumanController.cc
   trunk/src/orxonox/objects/gametypes/Gametype.cc
   trunk/src/orxonox/objects/infos/PlayerInfo.cc
   trunk/src/orxonox/objects/infos/PlayerInfo.h
   trunk/src/orxonox/objects/worldentities/ControllableEntity.cc
   trunk/src/orxonox/objects/worldentities/ControllableEntity.h
   trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc
   trunk/src/orxonox/objects/worldentities/pawns/Pawn.h
   trunk/src/orxonox/objects/worldentities/pawns/Spectator.h
Log:
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.


Modified: trunk/src/orxonox/objects/controllers/HumanController.cc
===================================================================
--- trunk/src/orxonox/objects/controllers/HumanController.cc	2009-05-24 01:01:38 UTC (rev 3037)
+++ trunk/src/orxonox/objects/controllers/HumanController.cc	2009-05-24 15:42:50 UTC (rev 3038)
@@ -158,7 +158,7 @@
             if (pawn)
                 pawn->kill();
             else if (HumanController::localController_s->player_)
-                HumanController::localController_s->player_->stopControl(HumanController::localController_s->controllableEntity_);
+                HumanController::localController_s->player_->stopControl();
         }
     }
 

Modified: trunk/src/orxonox/objects/gametypes/Gametype.cc
===================================================================
--- trunk/src/orxonox/objects/gametypes/Gametype.cc	2009-05-24 01:01:38 UTC (rev 3037)
+++ trunk/src/orxonox/objects/gametypes/Gametype.cc	2009-05-24 15:42:50 UTC (rev 3038)
@@ -129,7 +129,7 @@
             if (it->first->getControllableEntity())
             {
                 ControllableEntity* oldentity = it->first->getControllableEntity();
-        
+
                 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(oldentity->getCreator());
                 if (oldentity->getCamera())
                 {
@@ -142,7 +142,6 @@
                     entity->setOrientation(oldentity->getWorldOrientation());
                 }
 
-                it->first->stopControl(oldentity, true);
                 it->first->startControl(entity);
             }
             else
@@ -420,7 +419,7 @@
     }
 
     void Gametype::addTime(float t)
-    { 
+    {
         if (this->timeLimit_ == 0)
           this->time_ -= t;
         else
@@ -428,7 +427,7 @@
     }
 
     void Gametype::removeTime(float t)
-    { 
+    {
         if (this->timeLimit_ == 0)
           this->time_ += t;
         else
@@ -436,12 +435,12 @@
     }
 
     void Gametype::resetTimer()
-    { 
+    {
         this->resetTimer(timeLimit_);
     }
 
     void Gametype::resetTimer(float t)
-    { 
+    {
         this->timeLimit_ = t;
         this->time_ = t;
     }

Modified: trunk/src/orxonox/objects/infos/PlayerInfo.cc
===================================================================
--- trunk/src/orxonox/objects/infos/PlayerInfo.cc	2009-05-24 01:01:38 UTC (rev 3037)
+++ trunk/src/orxonox/objects/infos/PlayerInfo.cc	2009-05-24 15:42:50 UTC (rev 3038)
@@ -61,7 +61,7 @@
     {
         if (this->BaseObject::isInitialized())
         {
-            this->stopControl(this->controllableEntity_);
+            this->stopControl();
 
             if (this->controller_)
             {
@@ -141,48 +141,43 @@
         this->changedController();
     }
 
-    void PlayerInfo::startControl(ControllableEntity* entity, bool callback)
+    void PlayerInfo::startControl(ControllableEntity* entity)
     {
-        if (entity == this->controllableEntity_)
+        if (!entity || entity == this->controllableEntity_)
             return;
 
         if (this->controllableEntity_)
-            this->stopControl(this->controllableEntity_, callback);
+            this->stopControl();
 
         this->controllableEntity_ = entity;
+        this->controllableEntityID_ = entity->getObjectID();
 
-        if (entity)
-        {
-            this->controllableEntityID_ = entity->getObjectID();
-            entity->setPlayer(this);
-            this->bReadyToSpawn_ &= (!this->bSetUnreadyAfterSpawn_);
-        }
-        else
-        {
-            this->controllableEntityID_ = OBJECTID_UNKNOWN;
-        }
+        entity->setPlayer(this);
 
+        this->bReadyToSpawn_ &= (!this->bSetUnreadyAfterSpawn_);
+
         if (this->controller_)
             this->controller_->setControllableEntity(entity);
 
         this->changedControllableEntity();
     }
 
-    void PlayerInfo::stopControl(ControllableEntity* entity, bool callback)
+    void PlayerInfo::stopControl()
     {
-        if (entity && this->controllableEntity_ == entity)
-        {
-            this->controllableEntity_ = 0;
-            this->controllableEntityID_ = OBJECTID_UNKNOWN;
+        ControllableEntity* entity = this->controllableEntity_;
 
-            if (this->controller_)
-                this->controller_->setControllableEntity(0);
+        if (!entity)
+            return;
 
-            if (callback)
-                entity->removePlayer();
+        this->controllableEntity_ = 0;
+        this->controllableEntityID_ = OBJECTID_UNKNOWN;
 
-            this->changedControllableEntity();
-        }
+        if (this->controller_)
+            this->controller_->setControllableEntity(0);
+
+        entity->removePlayer();
+
+        this->changedControllableEntity();
     }
 
     void PlayerInfo::networkcallback_changedcontrollableentityID()
@@ -191,12 +186,11 @@
         {
             Synchronisable* temp = Synchronisable::getSynchronisable(this->controllableEntityID_);
             ControllableEntity* entity = dynamic_cast<ControllableEntity*>(temp);
-
             this->startControl(entity);
         }
         else
         {
-            this->stopControl(this->controllableEntity_);
+            this->stopControl();
         }
     }
 

Modified: trunk/src/orxonox/objects/infos/PlayerInfo.h
===================================================================
--- trunk/src/orxonox/objects/infos/PlayerInfo.h	2009-05-24 01:01:38 UTC (rev 3037)
+++ trunk/src/orxonox/objects/infos/PlayerInfo.h	2009-05-24 15:42:50 UTC (rev 3038)
@@ -67,8 +67,8 @@
             inline bool isReadyToSpawn() const
                 { return this->bReadyToSpawn_; }
 
-            void startControl(ControllableEntity* entity, bool callback = true);
-            void stopControl(ControllableEntity* entity, bool callback = true);
+            void startControl(ControllableEntity* entity);
+            void stopControl();
 
             inline ControllableEntity* getControllableEntity() const
                 { return this->controllableEntity_; }

Modified: trunk/src/orxonox/objects/worldentities/ControllableEntity.cc
===================================================================
--- trunk/src/orxonox/objects/worldentities/ControllableEntity.cc	2009-05-24 01:01:38 UTC (rev 3037)
+++ trunk/src/orxonox/objects/worldentities/ControllableEntity.cc	2009-05-24 15:42:50 UTC (rev 3038)
@@ -90,7 +90,7 @@
                 this->stopLocalHumanControl();
 
             if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
-                this->getPlayer()->stopControl(this, false);
+                this->getPlayer()->stopControl();
 
             if (this->hud_)
                 delete this->hud_;

Modified: trunk/src/orxonox/objects/worldentities/ControllableEntity.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/ControllableEntity.h	2009-05-24 01:01:38 UTC (rev 3037)
+++ trunk/src/orxonox/objects/worldentities/ControllableEntity.h	2009-05-24 15:42:50 UTC (rev 3038)
@@ -38,6 +38,8 @@
 {
     class _OrxonoxExport ControllableEntity : public MobileEntity
     {
+        friend class PlayerInfo; // PlayerInfo uses setPlayer and removePlayer
+
         public:
             ControllableEntity(BaseObject* creator);
             virtual ~ControllableEntity();
@@ -49,8 +51,6 @@
 
             virtual void changedPlayer() {}
 
-            virtual void setPlayer(PlayerInfo* player);
-            virtual void removePlayer();
             inline PlayerInfo* getPlayer() const
                 { return this->player_; }
 
@@ -130,6 +130,9 @@
                 { return this->mouseLookSpeed_; }
 
         protected:
+            virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead
+            virtual void removePlayer();                // don't call this directly, use friend class PlayerInfo instead
+
             virtual void startLocalHumanControl();
             virtual void stopLocalHumanControl();
             virtual void parentChanged();

Modified: trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc
===================================================================
--- trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc	2009-05-24 01:01:38 UTC (rev 3037)
+++ trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc	2009-05-24 15:42:50 UTC (rev 3038)
@@ -208,8 +208,8 @@
             if (this->getGametype())
                 this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
 
-            if (this->getPlayer())
-                this->getPlayer()->stopControl(this);
+            if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
+                this->getPlayer()->stopControl();
 
             if (GameMode::isMaster())
                 this->deatheffect();

Modified: trunk/src/orxonox/objects/worldentities/pawns/Pawn.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/pawns/Pawn.h	2009-05-24 01:01:38 UTC (rev 3037)
+++ trunk/src/orxonox/objects/worldentities/pawns/Pawn.h	2009-05-24 15:42:50 UTC (rev 3038)
@@ -47,9 +47,6 @@
             virtual void tick(float dt);
             void registerVariables();
 
-            virtual void setPlayer(PlayerInfo* player);
-            virtual void removePlayer();
-
             inline bool isAlive() const
                 { return this->bAlive_; }
 
@@ -112,6 +109,9 @@
             virtual void dropItems();
 
         protected:
+            virtual void setPlayer(PlayerInfo* player);
+            virtual void removePlayer();
+
             virtual void death();
             virtual void deatheffect();
             virtual void spawneffect();

Modified: trunk/src/orxonox/objects/worldentities/pawns/Spectator.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/pawns/Spectator.h	2009-05-24 01:01:38 UTC (rev 3037)
+++ trunk/src/orxonox/objects/worldentities/pawns/Spectator.h	2009-05-24 15:42:50 UTC (rev 3038)
@@ -45,9 +45,6 @@
             void registerVariables();
             virtual void tick(float dt);
 
-            virtual void setPlayer(PlayerInfo* player);
-            virtual void startLocalHumanControl();
-
             virtual void moveFrontBack(const Vector2& value);
             virtual void moveRightLeft(const Vector2& value);
             virtual void moveUpDown(const Vector2& value);
@@ -59,6 +56,10 @@
             virtual void fire(WeaponMode::Enum fireMode);
             virtual void greet();
 
+        protected:
+            virtual void setPlayer(PlayerInfo* player);
+            virtual void startLocalHumanControl();
+
         private:
             void changedGreeting();
             void changedFlareVisibility();




More information about the Orxonox-commit mailing list