[Orxonox-commit 894] r5617 - in code/branches/libraries/src/orxonox: objects/quest overlays

landauf at orxonox.net landauf at orxonox.net
Tue Aug 11 00:27:38 CEST 2009


Author: landauf
Date: 2009-08-11 00:27:38 +0200 (Tue, 11 Aug 2009)
New Revision: 5617

Modified:
   code/branches/libraries/src/orxonox/objects/quest/QuestManager.cc
   code/branches/libraries/src/orxonox/objects/quest/QuestManager.h
   code/branches/libraries/src/orxonox/overlays/GUIOverlay.cc
   code/branches/libraries/src/orxonox/overlays/GUIOverlay.h
Log:
Reduced dependencies between orxonox and overlays: GUIOverlays send their owners to a map in the QuestManager instead of the QuestManager asking the GUIOverlays.

Modified: code/branches/libraries/src/orxonox/objects/quest/QuestManager.cc
===================================================================
--- code/branches/libraries/src/orxonox/objects/quest/QuestManager.cc	2009-08-10 19:15:51 UTC (rev 5616)
+++ code/branches/libraries/src/orxonox/objects/quest/QuestManager.cc	2009-08-10 22:27:38 UTC (rev 5617)
@@ -37,8 +37,6 @@
 #include "core/CoreIncludes.h"
 
 #include "objects/infos/PlayerInfo.h"
-#include "objects/infos/PlayerInfo.h"
-#include "overlays/GUIOverlay.h"
 #include "Quest.h"
 #include "QuestHint.h"
 #include "QuestItem.h"
@@ -202,37 +200,25 @@
 
     /**
     @brief
-        
+
     @param name
     @return
     */
     QuestContainer* QuestManager::getQuestTree(std::string & name)
     {
-        GUIOverlay* gui = NULL;
-        for (ObjectList<GUIOverlay>::iterator it = ObjectList<GUIOverlay>::begin(); it != ObjectList<GUIOverlay>::end(); ++it)
-            if (it->getGUIName() == name)
-                gui = *it;
-
-        PlayerInfo* player;
-        if(gui == NULL)
+        PlayerInfo* player = this->players_[name];
+        if(player == NULL)
         {
-            COUT(1) << "Error: No GUIOverlay with the given name '" << name << "' present." << std::endl;
+            COUT(1) << "Error: GUIOverlay with name '" << name << "' has no player." << std::endl;
             return NULL;
         }
-        BaseObject* obj = gui->getOwner();
-        if(obj == NULL)
-        {
-            COUT(1) << "Error: GUIOverlay has no owner. " << std::endl;
-            return NULL;
-        }
-        player = orxonox_cast<PlayerInfo*>(obj);
-    
+
         QuestContainer* root = NULL;
         QuestContainer* current = NULL;
-        
+
         std::list<Quest*>* rootQuests = new std::list<Quest*>();
         getRootQuests(player, *rootQuests);
-        
+
         for(std::list<Quest*>::iterator it = rootQuests->begin(); it != rootQuests->end(); it++)
         {
             QuestContainer* container = addSubQuest(*it, player);
@@ -245,7 +231,7 @@
             {
                 current->next = container;
             }
-            
+
             current = container;
 
         }
@@ -259,7 +245,7 @@
 
     /**
     @brief
-        
+
     @param player
     @param list
     @return
@@ -278,7 +264,7 @@
 
     /**
     @brief
-        
+
     @param quest
     @param player
     @return
@@ -309,7 +295,7 @@
             container->status = "";
             COUT(1) << "An error occurred. A Quest of un-specified status wanted to be displayed." << std::endl;
         }
-        
+
         std::list<Quest*> quests = quest->getSubQuestList();
         QuestContainer* current = NULL;
         QuestContainer* first = NULL;
@@ -328,20 +314,20 @@
                 {
                     current->next = subContainer;
                 }
-                
+
                 current = subContainer;
             }
         }
         if(current != NULL)
             current->next = NULL;
         container->subQuests = first;
-        
+
         return container;
     }
 
     /**
     @brief
-        
+
     @param quest
     @param player
     @return
@@ -367,7 +353,7 @@
                 {
                     current->next = hint;
                 }
-                
+
                 current = hint;
             }
         }

Modified: code/branches/libraries/src/orxonox/objects/quest/QuestManager.h
===================================================================
--- code/branches/libraries/src/orxonox/objects/quest/QuestManager.h	2009-08-10 19:15:51 UTC (rev 5616)
+++ code/branches/libraries/src/orxonox/objects/quest/QuestManager.h	2009-08-10 22:27:38 UTC (rev 5617)
@@ -91,11 +91,17 @@
 
             QuestContainer* getQuestTree(std::string & name); // tolua_export
 
+            inline void setPlayer(const std::string& guiname, PlayerInfo* player)
+                { this->players_[guiname] = player; }
+            inline PlayerInfo* getPlayer(const std::string& guiname) const
+                { std::map<std::string, PlayerInfo*>::const_iterator it = this->players_.find(guiname); return (it != this->players_.end()) ? it->second : 0; }
+
         private:
             static QuestManager* singletonPtr_s;
 
             std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's.
             std::map<std::string, QuestHint*> hintMap_; //!< All QuestHints registered by their id's.
+            std::map<std::string, PlayerInfo*> players_; //!< Stores the player (owner) for each gui
 
             void getRootQuests(const PlayerInfo* player, std::list<Quest*> & list);
             HintContainer* addHints(Quest* quest, const PlayerInfo* player);

Modified: code/branches/libraries/src/orxonox/overlays/GUIOverlay.cc
===================================================================
--- code/branches/libraries/src/orxonox/overlays/GUIOverlay.cc	2009-08-10 19:15:51 UTC (rev 5616)
+++ code/branches/libraries/src/orxonox/overlays/GUIOverlay.cc	2009-08-10 22:27:38 UTC (rev 5617)
@@ -35,6 +35,8 @@
 #include "core/CoreIncludes.h"
 #include "core/GUIManager.h"
 #include "core/XMLPort.h"
+#include "objects/quest/QuestManager.h"
+#include "objects/infos/PlayerInfo.h"
 
 namespace orxonox
 {
@@ -78,4 +80,9 @@
         }
     }
 
+    void GUIOverlay::setGUIName(const std::string& name)
+    {
+        this->guiName_ = name;
+        QuestManager::getInstance().setPlayer(name, orxonox_cast<PlayerInfo*>(this->getOwner()));
+    }
 }

Modified: code/branches/libraries/src/orxonox/overlays/GUIOverlay.h
===================================================================
--- code/branches/libraries/src/orxonox/overlays/GUIOverlay.h	2009-08-10 19:15:51 UTC (rev 5616)
+++ code/branches/libraries/src/orxonox/overlays/GUIOverlay.h	2009-08-10 22:27:38 UTC (rev 5617)
@@ -45,7 +45,7 @@
 
             virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
 
-            inline void setGUIName(const std::string& name) { this->guiName_ = name; }
+            void setGUIName(const std::string& name);
             inline const std::string& getGUIName() const { return this->guiName_; }
 
             virtual void changedVisibility();




More information about the Orxonox-commit mailing list