[Orxonox-commit 85] r2783 - branches/questsystem5/src/orxonox/overlays/notifications

dafrick at orxonox.net dafrick at orxonox.net
Fri Mar 13 15:39:55 CET 2009


Author: dafrick
Date: 2009-03-13 14:39:54 +0000 (Fri, 13 Mar 2009)
New Revision: 2783

Modified:
   branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc
   branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc
   branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc
   branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h
Log:
Erradicated an infinite loop, and some wannabe-memory leaks. Also started the positioning of the notifications. I'd actually call it usable at this point.

Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc	2009-03-13 10:56:03 UTC (rev 2782)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc	2009-03-13 14:39:54 UTC (rev 2783)
@@ -96,7 +96,7 @@
             all = true;
         
         //!< Insert the notification in all queues that have its sender as target.
-        for(std::map<NotificationQueue*,int>::iterator it = queueList_s.begin(); it != queueList_s.end(); it++)
+        for(std::map<NotificationQueue*,int>::iterator it = queueList_s.begin(); it != queueList_s.end(); it++) //!< Iterate through all queues.
         {
             std::set<std::string> set = it->first->getTargetsSet();
             if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TDO: Make sure this works.
@@ -106,7 +106,7 @@
             }
         }
         
-        COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
+        COUT(3) << "Notification registered with the NotificationManager." << std::endl;
         
         return true;
     }
@@ -132,6 +132,7 @@
         if(set.find(ALL) != set.end())
         {
             notificationLists_s[index] = &allNotificationsList_s;
+            COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
             return true;
         }
         
@@ -147,9 +148,9 @@
             }
         }
         
-        COUT(3) << "Notification registered with the NotificationManager." << std::endl;
-        
         queue->update(); //!< Update the queue.
+
+        COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
         
         return true;
     }
@@ -170,8 +171,6 @@
     */
     /*static*/ std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
     {
-        COUT(1) << "Queue: " << queue << ", timeFrameStart: " << timeFrameStart << ", timeFrameEnd: " << timeFrameEnd << std::endl;
-    
         std::multimap<std::time_t,Notification*>* notifications = NotificationManager::notificationLists_s[NotificationManager::queueList_s[queue]];
         
         if(notifications == NULL)

Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc	2009-03-13 10:56:03 UTC (rev 2782)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc	2009-03-13 14:39:54 UTC (rev 2783)
@@ -86,11 +86,11 @@
         return true;
     }
 
-    const std::string NotificationOverlay::clipMessage(const std::string & str)
+    const std::string NotificationOverlay::clipMessage(const std::string & message)
     {
-        if(str.length() <= (unsigned int)this->queue_->getNotificationLength())
-            return str;
-        return str.substr(0, this->queue_->getNotificationLength());
+        if(message.length() <= (unsigned int)this->queue_->getNotificationLength())
+            return message;
+        return message.substr(0, this->queue_->getNotificationLength());
     }
 
 }

Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc	2009-03-13 10:56:03 UTC (rev 2782)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc	2009-03-13 14:39:54 UTC (rev 2783)
@@ -58,12 +58,11 @@
     /**
     @brief
         Destructor.
-    @todo
-        I'm pretty sure that there are some thing that have to be distroyed.
     */
     NotificationQueue::~NotificationQueue()
     {
-        
+        this->targets_.clear();
+        this->clear();
     }
     
     /**
@@ -75,7 +74,6 @@
     {
         RegisterObject(NotificationQueue);
         
-        this->setDefaults();
         this->size_ = 0;
         this->tickTime_ = 0.0;
         
@@ -106,6 +104,8 @@
     {
         SUPER(NotificationQueue, XMLPort, xmlElement, mode);
         
+        this->setDefaults();
+
         XMLPortParam(NotificationQueue, "maxSize", setMaxSize, getMaxSize, xmlElement, mode);
         XMLPortParam(NotificationQueue, "notificationLength", setNotificationLength, getNotificationLength, xmlElement, mode);
         XMLPortParam(NotificationQueue, "displayTime", setDisplayTime, getDisplayTime, xmlElement, mode);
@@ -134,6 +134,7 @@
             while(it != this->containers_.upper_bound(&this->timeLimit_)) //!< Iterate through all elements whose creation time is smaller than the current time minus the display time.
             {
                 this->removeContainer(*it);
+                this->scroll(Vector2(0.0,-(1.1*this->getFontSize())));
                 it = this->containers_.begin(); //TDO: Needed?
             }
             
@@ -175,13 +176,12 @@
     {
         this->addNotification(notification, time);
         
-        //TDO: Position!
-        
         std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it;
         while(this->getSize() > this->getMaxSize())
         {
             it = this->containers_.begin();
             this->removeContainer(*it);
+            this->scroll(Vector2(0.0,-(1.1*this->getFontSize())));
         }
         
         COUT(3) << "NotificationQueue updated. A new Notifications has been added." << std::endl;
@@ -240,30 +240,35 @@
     
     /**
     @brief
-        Returns all targets concatinated as string, with kommas (',') as seperators.
+        Produces all targets concatinated as string, with kommas (',') as seperators.
+    @param string
+        Pointer to a string which will be used by the method to fill with the concatination of the targets.
     @return
-        Returns all targets concatinated as string, with kommas (',') as seperators.
-    @todo
-        Where is the string deleted?
+        Returns true if successful.
     */
-    const std::string & NotificationQueue::getTargets() const
+    bool NotificationQueue::getTargets(std::string* string) const
     {
-        std::string* pTemp = new std::string("");
+        if(string == NULL)
+        {
+            COUT(4) << "Input string must have memory allocated." << std::endl;
+            return false;
+        }
+        string->clear();
         bool first = true;
         for(std::set<std::string>::iterator it = this->targets_.begin(); it != this->targets_.end(); it++) //!< Iterate through the set of targets.
         {
             if(!first)
             {
-                *pTemp += ",";
+                *string += ",";
             }
             else
             {
                 first = false;
             }
-            *pTemp += *it;
+            *string += *it;
         }
         
-        return *pTemp;
+        return true;
     }
     
     /**
@@ -277,16 +282,19 @@
     */
     bool NotificationQueue::setTargets(const std::string & targets)
     {
+        this->targets_.clear();
+
         std::string* pTemp;
         unsigned int index = 0;
         while( index < targets.size() ) //!< Go through the string, character by character until the end is reached.
         {
             pTemp = new std::string("");
-            while(targets[index] != ',' && targets[index] != ' ' && index < targets.size())
+            while(index < targets.size() && targets[index] != ',' && targets[index] != ' ')
             {
                 *pTemp += targets[index];
                 index++;
             }
+            index++;
             this->targets_.insert(*pTemp);
         }
         
@@ -330,7 +338,15 @@
         }
         return true;
     }
-    
+
+    void NotificationQueue::scroll(const Vector2 pos)
+    {
+        for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Scroll each overlay.
+        {
+            it->second->overlay->scroll(pos);
+        }
+    }
+
     /**
     @brief
         Adds a Notification, to the queue.
@@ -357,6 +373,8 @@
         this->overlays_[notification] = container;
         this->insertElement(container->overlay, container->name);
         this->size_= this->size_+1;
+
+        container->overlay->scroll(Vector2(0.0,(1.1*this->getFontSize())*(this->getSize()-1)));
     }
     
     /**

Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h	2009-03-13 10:56:03 UTC (rev 2782)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h	2009-03-13 14:39:54 UTC (rev 2783)
@@ -43,6 +43,7 @@
 #include <OgrePanelOverlayElement.h>
 #include <map>
 #include <ctime>
+#include "util/Math.h"
 
 #include "orxonox/overlays/OverlayGroup.h"
 #include "orxonox/objects/Tickable.h"
@@ -119,7 +120,7 @@
             */
             inline const std::set<std::string> & getTargetsSet()
                 { return this->targets_; }
-            const std::string & getTargets() const; //!< Returns a string consisting of teh concatination of the targets.
+            bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
             
             /**
             @brief Returns the font size used to display the Notifications.
@@ -133,6 +134,8 @@
             */
             inline const std::string & getFont() const
                 { return this->font_; }
+
+            void scroll(const Vector2 pos);
             
         private:
             static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.




More information about the Orxonox-commit mailing list