[Orxonox-commit 93] r2789 - in branches/miniprojects/src/orxonox/objects: controllers gametypes infos

landauf at orxonox.net landauf at orxonox.net
Mon Mar 16 02:11:14 CET 2009


Author: landauf
Date: 2009-03-16 01:11:14 +0000 (Mon, 16 Mar 2009)
New Revision: 2789

Modified:
   branches/miniprojects/src/orxonox/objects/controllers/Controller.cc
   branches/miniprojects/src/orxonox/objects/controllers/Controller.h
   branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h
   branches/miniprojects/src/orxonox/objects/infos/GametypeInfo.cc
   branches/miniprojects/src/orxonox/objects/infos/GametypeInfo.h
   branches/miniprojects/src/orxonox/objects/infos/HumanPlayer.cc
   branches/miniprojects/src/orxonox/objects/infos/HumanPlayer.h
   branches/miniprojects/src/orxonox/objects/infos/PlayerInfo.cc
   branches/miniprojects/src/orxonox/objects/infos/PlayerInfo.h
Log:
 - Moved default-hud (chat, gamestate info) from Controller to HumanPlayer
 - Added support for a Gametype-HUD to Gametype and PlayerInfo

Modified: branches/miniprojects/src/orxonox/objects/controllers/Controller.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/controllers/Controller.cc	2009-03-15 15:17:20 UTC (rev 2788)
+++ branches/miniprojects/src/orxonox/objects/controllers/Controller.cc	2009-03-16 01:11:14 UTC (rev 2789)
@@ -42,41 +42,9 @@
 
         this->player_ = 0;
         this->controllableEntity_ = 0;
-        this->hud_ = 0;
-        this->bUpdateHUD_ = false;
     }
 
     Controller::~Controller()
     {
-        if (this->isInitialized() && this->hud_)
-            delete this->hud_;
     }
-
-    void Controller::changedControllableEntity()
-    {
-        if (this->bUpdateHUD_)
-        {
-            this->updateHUD();
-            this->bUpdateHUD_ = false;
-        }
-
-        if (this->hud_)
-            this->hud_->setOwner(this->getControllableEntity());
-    }
-
-    void Controller::updateHUD()
-    {
-        if (this->hud_)
-        {
-            delete this->hud_;
-            this->hud_ = 0;
-        }
-
-        if (this->hudtemplate_ != "")
-        {
-            this->hud_ = new OverlayGroup(this);
-            this->hud_->addTemplate(this->hudtemplate_);
-            this->hud_->setOwner(this->getControllableEntity());
-        }
-    }
 }

Modified: branches/miniprojects/src/orxonox/objects/controllers/Controller.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/controllers/Controller.h	2009-03-15 15:17:20 UTC (rev 2788)
+++ branches/miniprojects/src/orxonox/objects/controllers/Controller.h	2009-03-16 01:11:14 UTC (rev 2789)
@@ -56,33 +56,11 @@
             }
             inline ControllableEntity* getControllableEntity() const
                 { return this->controllableEntity_; }
-            virtual void changedControllableEntity();
+            virtual void changedControllableEntity() {}
 
-            inline void setHUDTemplate(const std::string& name)
-            {
-                if (name != this->hudtemplate_)
-                {
-                    this->hudtemplate_ = name;
-                    if (this->controllableEntity_)
-                        this->updateHUD();
-                    else
-                        this->bUpdateHUD_ = true;
-                }
-            }
-            inline const std::string& getHUDTemplate() const
-                { return this->hudtemplate_; }
-
-            inline OverlayGroup* getHUD() const
-                { return this->hud_; }
-
         protected:
-            void updateHUD();
-
             PlayerInfo* player_;
             ControllableEntity* controllableEntity_;
-            std::string hudtemplate_;
-            OverlayGroup* hud_;
-            bool bUpdateHUD_;
     };
 }
 

Modified: branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h	2009-03-15 15:17:20 UTC (rev 2788)
+++ branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h	2009-03-16 01:11:14 UTC (rev 2789)
@@ -111,6 +111,11 @@
             inline float getStartCountdown() const
                 { return this->gtinfo_.startCountdown_; }
 
+            inline void setHUDTemplate(const std::string& name)
+                { this->gtinfo_.hudtemplate_ = name; }
+            inline const std::string& getHUDTemplate() const
+                { return this->gtinfo_.hudtemplate_; }
+
             void addBots(unsigned int amount);
             void killBots(unsigned int amount = 0);
 

Modified: branches/miniprojects/src/orxonox/objects/infos/GametypeInfo.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/infos/GametypeInfo.cc	2009-03-15 15:17:20 UTC (rev 2788)
+++ branches/miniprojects/src/orxonox/objects/infos/GametypeInfo.cc	2009-03-16 01:11:14 UTC (rev 2789)
@@ -57,5 +57,6 @@
         registerVariable(this->bEnded_,                 variableDirection::toclient);
         registerVariable(this->startCountdown_,         variableDirection::toclient);
         registerVariable(this->bStartCountdownRunning_, variableDirection::toclient);
+        registerVariable(this->hudtemplate_,            variableDirection::toclient);
     }
 }

Modified: branches/miniprojects/src/orxonox/objects/infos/GametypeInfo.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/infos/GametypeInfo.h	2009-03-15 15:17:20 UTC (rev 2788)
+++ branches/miniprojects/src/orxonox/objects/infos/GametypeInfo.h	2009-03-16 01:11:14 UTC (rev 2789)
@@ -55,11 +55,15 @@
             inline float getStartCountdown() const
                 { return this->startCountdown_; }
 
+            inline const std::string& getHUDTemplate() const
+                { return this->hudtemplate_; }
+
         private:
             bool bStarted_;
             bool bEnded_;
             bool bStartCountdownRunning_;
             float startCountdown_;
+            std::string hudtemplate_;
     };
 }
 

Modified: branches/miniprojects/src/orxonox/objects/infos/HumanPlayer.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/infos/HumanPlayer.cc	2009-03-15 15:17:20 UTC (rev 2788)
+++ branches/miniprojects/src/orxonox/objects/infos/HumanPlayer.cc	2009-03-16 01:11:14 UTC (rev 2789)
@@ -52,12 +52,16 @@
         this->bHumanPlayer_ = true;
         this->defaultController_ = Class(HumanController);
 
+        this->humanHud_ = 0;
+
         this->setConfigValues();
         this->registerVariables();
     }
 
     HumanPlayer::~HumanPlayer()
     {
+        if (this->isInitialized() && this->humanHud_)
+            delete this->humanHud_;
     }
 
     void HumanPlayer::setConfigValues()
@@ -88,7 +92,7 @@
 
     void HumanPlayer::configvaluecallback_changedHUDTemplate()
     {
-        this->changedController();
+        this->setHumanHUDTemplate(this->hudtemplate_);
     }
 
     void HumanPlayer::networkcallback_changednick()
@@ -145,14 +149,27 @@
         this->networkcallback_clientIDchanged();
     }
 
-    void HumanPlayer::changedController()
+    void HumanPlayer::changedControllableEntity()
     {
-        if (this->getController())
+        PlayerInfo::changedControllableEntity();
+
+        if (this->humanHud_)
+            this->humanHud_->setOwner(this->getControllableEntity());
+    }
+
+    void HumanPlayer::updateHumanHUD()
+    {
+        if (this->humanHud_)
         {
-            this->getController()->setHUDTemplate(this->hudtemplate_);
+            delete this->humanHud_;
+            this->humanHud_ = 0;
+        }
 
-            if (this->getController() && this->getController()->getHUD())
-                this->getController()->getHUD()->setOwner(this->getControllableEntity());
+        if (this->humanHudTemplate_ != "")
+        {
+            this->humanHud_ = new OverlayGroup(this);
+            this->humanHud_->addTemplate(this->humanHudTemplate_);
+            this->humanHud_->setOwner(this->getControllableEntity());
         }
     }
 }

Modified: branches/miniprojects/src/orxonox/objects/infos/HumanPlayer.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/infos/HumanPlayer.h	2009-03-15 15:17:20 UTC (rev 2788)
+++ branches/miniprojects/src/orxonox/objects/infos/HumanPlayer.h	2009-03-16 01:11:14 UTC (rev 2789)
@@ -50,8 +50,22 @@
 
             void setClientID(unsigned int clientID);
 
-            virtual void changedController();
+            virtual void changedControllableEntity();
 
+            inline void setHumanHUDTemplate(const std::string& name)
+            {
+                if (name != this->humanHudTemplate_)
+                {
+                    this->humanHudTemplate_ = name;
+                    this->updateHumanHUD();
+                }
+            }
+            inline const std::string& getHumanHUDTemplate() const
+                { return this->humanHudTemplate_; }
+
+            inline OverlayGroup* getHumanHUD() const
+                { return this->humanHud_; }
+
         protected:
             void configvaluecallback_changednick();
             void configvaluecallback_changedHUDTemplate();
@@ -60,11 +74,16 @@
             void networkcallback_server_initialized();
             void networkcallback_client_initialized();
 
+            void updateHumanHUD();
+
             std::string nick_;
             std::string synchronize_nick_;
             std::string hudtemplate_;
             bool server_initialized_;
             bool client_initialized_;
+
+            std::string humanHudTemplate_;
+            OverlayGroup* humanHud_;
     };
 }
 

Modified: branches/miniprojects/src/orxonox/objects/infos/PlayerInfo.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/infos/PlayerInfo.cc	2009-03-15 15:17:20 UTC (rev 2788)
+++ branches/miniprojects/src/orxonox/objects/infos/PlayerInfo.cc	2009-03-16 01:11:14 UTC (rev 2789)
@@ -34,6 +34,7 @@
 #include "core/CoreIncludes.h"
 #include "network/ClientInformation.h"
 #include "objects/gametypes/Gametype.h"
+#include "overlays/OverlayGroup.h"
 
 namespace orxonox
 {
@@ -49,6 +50,7 @@
         this->controller_ = 0;
         this->controllableEntity_ = 0;
         this->controllableEntityID_ = CLIENTID_UNKNOWN;
+        this->gametypeHud_ = 0;
 
         this->registerVariables();
     }
@@ -67,6 +69,9 @@
 
             if (this->getGametype())
                 this->getGametype()->playerLeft(this);
+
+            if (this->BaseObject::isInitialized() && this->gametypeHud_)
+                delete this->gametypeHud_;
         }
     }
 
@@ -103,6 +108,10 @@
                     this->getGametype()->playerSwitchedBack(this, this->getOldGametype());
                 else
                     this->getGametype()->playerEntered(this);
+
+                if (this->isLocalPlayer() && this->isHumanPlayer())
+                    if (this->getGametype()->getHUDTemplate() != "")
+                        this->setGametypeHUDTemplate(this->getGametype()->getHUDTemplate());
             }
         }
     }
@@ -140,6 +149,8 @@
 
         if (this->controller_)
             this->controller_->setControllableEntity(entity);
+
+        this->changedControllableEntity();
     }
 
     void PlayerInfo::stopControl(ControllableEntity* entity, bool callback)
@@ -154,6 +165,8 @@
 
             if (callback)
                 entity->removePlayer();
+
+            this->changedControllableEntity();
         }
     }
 
@@ -171,4 +184,26 @@
             this->stopControl(this->controllableEntity_);
         }
     }
+
+    void PlayerInfo::changedControllableEntity()
+    {
+        if (this->gametypeHud_)
+            this->gametypeHud_->setOwner(this->getControllableEntity());
+    }
+
+    void PlayerInfo::updateGametypeHUD()
+    {
+        if (this->gametypeHud_)
+        {
+            delete this->gametypeHud_;
+            this->gametypeHud_ = 0;
+        }
+
+        if (this->isLocalPlayer() && this->isHumanPlayer() && this->gametypeHudTemplate_ != "")
+        {
+            this->gametypeHud_ = new OverlayGroup(this);
+            this->gametypeHud_->addTemplate(this->gametypeHudTemplate_);
+            this->gametypeHud_->setOwner(this->getControllableEntity());
+        }
+    }
 }

Modified: branches/miniprojects/src/orxonox/objects/infos/PlayerInfo.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/infos/PlayerInfo.h	2009-03-15 15:17:20 UTC (rev 2788)
+++ branches/miniprojects/src/orxonox/objects/infos/PlayerInfo.h	2009-03-16 01:11:14 UTC (rev 2789)
@@ -48,6 +48,9 @@
             virtual void changedName();
             virtual void changedGametype();
 
+            virtual void changedController() {}
+            virtual void changedControllableEntity();
+
             inline bool isHumanPlayer() const
                 { return this->bHumanPlayer_; }
             inline bool isLocalPlayer() const
@@ -72,8 +75,21 @@
 
             inline Controller* getController() const
                 { return this->controller_; }
-            virtual void changedController() {}
 
+            inline void setGametypeHUDTemplate(const std::string& name)
+            {
+                if (name != this->gametypeHudTemplate_)
+                {
+                    this->gametypeHudTemplate_ = name;
+                    this->updateGametypeHUD();
+                }
+            }
+            inline const std::string& getGametypeHUDTemplate() const
+                { return this->gametypeHudTemplate_; }
+
+            inline OverlayGroup* getGametypeHUD() const
+                { return this->gametypeHud_; }
+
         protected:
             void createController();
 
@@ -85,11 +101,14 @@
 
         private:
             void networkcallback_changedcontrollableentityID();
+            void updateGametypeHUD();
 
             bool bReadyToSpawn_;
             Controller* controller_;
             ControllableEntity* controllableEntity_;
             unsigned int controllableEntityID_;
+            std::string gametypeHudTemplate_;
+            OverlayGroup* gametypeHud_;
     };
 }
 




More information about the Orxonox-commit mailing list