Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 13, 2009, 3:39:54 PM (16 years ago)
Author:
dafrick
Message:

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.

Location:
code/branches/questsystem5/src/orxonox/overlays/notifications
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc

    r2779 r2783  
    9797       
    9898        //!< Insert the notification in all queues that have its sender as target.
    99         for(std::map<NotificationQueue*,int>::iterator it = queueList_s.begin(); it != queueList_s.end(); it++)
     99        for(std::map<NotificationQueue*,int>::iterator it = queueList_s.begin(); it != queueList_s.end(); it++) //!< Iterate through all queues.
    100100        {
    101101            std::set<std::string> set = it->first->getTargetsSet();
     
    107107        }
    108108       
    109         COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
     109        COUT(3) << "Notification registered with the NotificationManager." << std::endl;
    110110       
    111111        return true;
     
    133133        {
    134134            notificationLists_s[index] = &allNotificationsList_s;
     135            COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
    135136            return true;
    136137        }
     
    148149        }
    149150       
    150         COUT(3) << "Notification registered with the NotificationManager." << std::endl;
    151        
    152151        queue->update(); //!< Update the queue.
     152
     153        COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
    153154       
    154155        return true;
     
    171172    /*static*/ std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
    172173    {
    173         COUT(1) << "Queue: " << queue << ", timeFrameStart: " << timeFrameStart << ", timeFrameEnd: " << timeFrameEnd << std::endl;
    174    
    175174        std::multimap<std::time_t,Notification*>* notifications = NotificationManager::notificationLists_s[NotificationManager::queueList_s[queue]];
    176175       
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc

    r2781 r2783  
    8787    }
    8888
    89     const std::string NotificationOverlay::clipMessage(const std::string & str)
     89    const std::string NotificationOverlay::clipMessage(const std::string & message)
    9090    {
    91         if(str.length() <= (unsigned int)this->queue_->getNotificationLength())
    92             return str;
    93         return str.substr(0, this->queue_->getNotificationLength());
     91        if(message.length() <= (unsigned int)this->queue_->getNotificationLength())
     92            return message;
     93        return message.substr(0, this->queue_->getNotificationLength());
    9494    }
    9595
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc

    r2779 r2783  
    5959    @brief
    6060        Destructor.
    61     @todo
    62         I'm pretty sure that there are some thing that have to be distroyed.
    6361    */
    6462    NotificationQueue::~NotificationQueue()
    6563    {
    66        
     64        this->targets_.clear();
     65        this->clear();
    6766    }
    6867   
     
    7675        RegisterObject(NotificationQueue);
    7776       
    78         this->setDefaults();
    7977        this->size_ = 0;
    8078        this->tickTime_ = 0.0;
     
    107105        SUPER(NotificationQueue, XMLPort, xmlElement, mode);
    108106       
     107        this->setDefaults();
     108
    109109        XMLPortParam(NotificationQueue, "maxSize", setMaxSize, getMaxSize, xmlElement, mode);
    110110        XMLPortParam(NotificationQueue, "notificationLength", setNotificationLength, getNotificationLength, xmlElement, mode);
     
    135135            {
    136136                this->removeContainer(*it);
     137                this->scroll(Vector2(0.0,-(1.1*this->getFontSize())));
    137138                it = this->containers_.begin(); //TDO: Needed?
    138139            }
     
    176177        this->addNotification(notification, time);
    177178       
    178         //TDO: Position!
    179        
    180179        std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it;
    181180        while(this->getSize() > this->getMaxSize())
     
    183182            it = this->containers_.begin();
    184183            this->removeContainer(*it);
     184            this->scroll(Vector2(0.0,-(1.1*this->getFontSize())));
    185185        }
    186186       
     
    241241    /**
    242242    @brief
    243         Returns all targets concatinated as string, with kommas (',') as seperators.
    244     @return
    245         Returns all targets concatinated as string, with kommas (',') as seperators.
    246     @todo
    247         Where is the string deleted?
    248     */
    249     const std::string & NotificationQueue::getTargets() const
    250     {
    251         std::string* pTemp = new std::string("");
     243        Produces all targets concatinated as string, with kommas (',') as seperators.
     244    @param string
     245        Pointer to a string which will be used by the method to fill with the concatination of the targets.
     246    @return
     247        Returns true if successful.
     248    */
     249    bool NotificationQueue::getTargets(std::string* string) const
     250    {
     251        if(string == NULL)
     252        {
     253            COUT(4) << "Input string must have memory allocated." << std::endl;
     254            return false;
     255        }
     256        string->clear();
    252257        bool first = true;
    253258        for(std::set<std::string>::iterator it = this->targets_.begin(); it != this->targets_.end(); it++) //!< Iterate through the set of targets.
     
    255260            if(!first)
    256261            {
    257                 *pTemp += ",";
     262                *string += ",";
    258263            }
    259264            else
     
    261266                first = false;
    262267            }
    263             *pTemp += *it;
    264         }
    265        
    266         return *pTemp;
     268            *string += *it;
     269        }
     270       
     271        return true;
    267272    }
    268273   
     
    278283    bool NotificationQueue::setTargets(const std::string & targets)
    279284    {
     285        this->targets_.clear();
     286
    280287        std::string* pTemp;
    281288        unsigned int index = 0;
     
    283290        {
    284291            pTemp = new std::string("");
    285             while(targets[index] != ',' && targets[index] != ' ' && index < targets.size())
     292            while(index < targets.size() && targets[index] != ',' && targets[index] != ' ')
    286293            {
    287294                *pTemp += targets[index];
    288295                index++;
    289296            }
     297            index++;
    290298            this->targets_.insert(*pTemp);
    291299        }
     
    331339        return true;
    332340    }
    333    
     341
     342    void NotificationQueue::scroll(const Vector2 pos)
     343    {
     344        for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Scroll each overlay.
     345        {
     346            it->second->overlay->scroll(pos);
     347        }
     348    }
     349
    334350    /**
    335351    @brief
     
    358374        this->insertElement(container->overlay, container->name);
    359375        this->size_= this->size_+1;
     376
     377        container->overlay->scroll(Vector2(0.0,(1.1*this->getFontSize())*(this->getSize()-1)));
    360378    }
    361379   
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h

    r2779 r2783  
    4444#include <map>
    4545#include <ctime>
     46#include "util/Math.h"
    4647
    4748#include "orxonox/overlays/OverlayGroup.h"
     
    120121            inline const std::set<std::string> & getTargetsSet()
    121122                { return this->targets_; }
    122             const std::string & getTargets() const; //!< Returns a string consisting of teh concatination of the targets.
     123            bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
    123124           
    124125            /**
     
    134135            inline const std::string & getFont() const
    135136                { return this->font_; }
     137
     138            void scroll(const Vector2 pos);
    136139           
    137140        private:
Note: See TracChangeset for help on using the changeset viewer.