Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 15, 2009, 11:41:25 AM (16 years ago)
Author:
dafrick
Message:

Made QuestManager and NotificationManager to Singletons. Fixed/Changed som other stuff I don't remember…

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

Legend:

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

    r2779 r2785  
    106106    {
    107107        this->sender_ = sender;
    108         bool successful = NotificationManager::registerNotification(this);
     108        bool successful = NotificationManager::getInstance().registerNotification(this);
    109109        if(!successful)
    110110            return false;
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc

    r2783 r2785  
    4848    const std::string NotificationManager::NONE = "none";
    4949
    50     std::multimap<std::time_t,Notification*> NotificationManager::allNotificationsList_s;
    51     std::map<int,std::multimap<std::time_t,Notification*>*> NotificationManager::notificationLists_s;
    52     std::map<NotificationQueue*,int> NotificationManager::queueList_s;
    53    
    54     int NotificationManager::highestIndex_s = 0;
     50    NotificationManager* NotificationManager::singletonRef_s = NULL;
    5551
    5652    /**
     
    5854        Constructor. Registers the Object.
    5955    */
    60     NotificationManager::NotificationManager(BaseObject* creator) : BaseObject(creator)
    61     {
    62         RegisterObject(NotificationManager);
     56    NotificationManager::NotificationManager() : BaseObject(this)
     57    {
     58        RegisterRootObject(NotificationManager);
     59
     60        this->highestIndex_ = 0;
    6361    }
    6462
     
    6967    NotificationManager::~NotificationManager()
    7068    {
     69    }
     70
     71    /**
     72    @brief
     73        Returns the current (and single) instance of the NotificationManager. Creates one, if there isn't one to begin with.
     74    @return
     75        Returns a reference to the single instance of the NotificationManager.
     76    */
     77    /*static*/ NotificationManager & NotificationManager::getInstance()
     78    {
     79        if(singletonRef_s == NULL)
     80        {
     81            singletonRef_s = new NotificationManager();
     82        }
     83        return *singletonRef_s;
    7184    }
    7285   
     
    7992        Returns true if successful.
    8093    */
    81     /*static*/ bool NotificationManager::registerNotification(Notification* notification)
     94    bool NotificationManager::registerNotification(Notification* notification)
    8295    {
    8396   
     
    87100        std::time_t time = std::time(0); //TDO: Doesn't this expire? //!< Get current time.
    88101       
    89         allNotificationsList_s.insert(std::pair<std::time_t,Notification*>(time,notification));
     102        this->allNotificationsList_.insert(std::pair<std::time_t,Notification*>(time,notification));
    90103       
    91104        if(notification->getSender() == NONE) //!< If the sender has no specific name, then the Notification is only added to the list of all Notifications.
     
    97110       
    98111        //!< 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++) //!< Iterate through all queues.
     112        for(std::map<NotificationQueue*,int>::iterator it = this->queueList_.begin(); it != this->queueList_.end(); it++) //!< Iterate through all queues.
    100113        {
    101114            std::set<std::string> set = it->first->getTargetsSet();
    102115            if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TDO: Make sure this works.
    103116            {
    104                 notificationLists_s[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationQueue.
     117                this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationQueue.
    105118                it->first->update(notification, time); //!< Update the queue.
    106119            }
     
    120133        Returns true if successful.
    121134    */
    122     /*static*/ bool NotificationManager::registerQueue(NotificationQueue* queue)
    123     {
    124         NotificationManager::highestIndex_s += 1;
    125         int index = NotificationManager::highestIndex_s;
    126        
    127         queueList_s[queue] = index; //!< Add the NotificationQueue to the list of queues.
     135    bool NotificationManager::registerQueue(NotificationQueue* queue)
     136    {
     137        this->highestIndex_ += 1;
     138        int index = this->highestIndex_;
     139       
     140        this->queueList_[queue] = index; //!< Add the NotificationQueue to the list of queues.
    128141       
    129142        std::set<std::string> set = queue->getTargetsSet(); //TDO: Works this?
     
    132145        if(set.find(ALL) != set.end())
    133146        {
    134             notificationLists_s[index] = &allNotificationsList_s;
     147            this->notificationLists_[index] = &this->allNotificationsList_;
    135148            COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
    136149            return true;
    137150        }
    138151       
    139         notificationLists_s[index] = new std::multimap<std::time_t,Notification*>;
    140         std::multimap<std::time_t,Notification*> map = *notificationLists_s[index];
     152        this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>;
     153        std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index];
    141154       
    142155        //! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationQueue.
    143         for(std::multimap<std::time_t,Notification*>::iterator it = allNotificationsList_s.begin(); it != allNotificationsList_s.end(); it++)
     156        for(std::multimap<std::time_t,Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
    144157        {
    145158            if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target.
     
    170183        Make sure the map is deleted.
    171184    */
    172     /*static*/ std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
    173     {
    174         std::multimap<std::time_t,Notification*>* notifications = NotificationManager::notificationLists_s[NotificationManager::queueList_s[queue]];
     185    std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
     186    {
     187        std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]];
    175188       
    176189        if(notifications == NULL)
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h

    r2779 r2785  
    5050    /**
    5151    @brief
    52         The NotificationManager functions as a gateway between Notifications and NotificationQueues.
     52        The Singleton NotificationManager functions as a gateway between Notifications and NotificationQueues.
    5353        It receives, organizes Notifications and the redistributes them to the specific NotificationQueues.
    5454    @author
     
    5757    class _OrxonoxExport NotificationManager : public BaseObject
    5858    {
     59        protected:
     60            NotificationManager();
     61
    5962        public:
    60             NotificationManager(BaseObject* creator);
    6163            virtual ~NotificationManager();
    6264               
     
    6466            static const std::string NONE;
    6567         
     68            static NotificationManager & getInstance(); //! Returns a reference to the single instance of the NotificationManager.
     69
    6670            //TDO: Visibility?
    67             static bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
    68             static bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager.
     71            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
     72            bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager.
    6973           
    70             static std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.
     74            std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.
    7175           
    7276            /**
     
    7680            @return Returns a time-ordered list of Notifications.
    7781            */
    78             static std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart)
    79                 { return NotificationManager::getNotifications(queue, timeFrameStart, std::time(0)); }
     82            std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart)
     83                { return this->getNotifications(queue, timeFrameStart, std::time(0)); }
    8084            /**
    8185            @brief Fetches the Notifications for a specific NotificationQueue starting at a specified timespan before now.
     
    8488            @return Returns a time-ordered list of Notifications.
    8589            */
    86             static std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, int timeDelay)
    87                 { return NotificationManager::getNotifications(queue, std::time(0)-timeDelay, std::time(0)); }
     90            std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, int timeDelay)
     91                { return this->getNotifications(queue, std::time(0)-timeDelay, std::time(0)); }
    8892     
    89                private:
    90             static int highestIndex_s; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that  no key appears twice.
     93        private:
     94            static NotificationManager* singletonRef_s;
     95
     96            int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that  no key appears twice.
    9197       
    92             static std::multimap<std::time_t,Notification*> allNotificationsList_s; //!< Container where all notifications are stored (together with their respecive timestamps).
    93             static std::map<NotificationQueue*,int> queueList_s; //!< Container where all NotificationQueues are stored with a number as identifier.
    94             static std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_s; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored.
     98            std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored (together with their respecive timestamps).
     99            std::map<NotificationQueue*,int> queueList_; //!< Container where all NotificationQueues are stored with a number as identifier.
     100            std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored.
    95101           
    96102
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc

    r2783 r2785  
    7474        this->setFont(this->queue_->getFont());
    7575        this->setTextSize(this->queue_->getFontSize());
     76
     77        this->setPosition(this->queue_->getPosition());
    7678    }
    7779
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc

    r2783 r2785  
    4646   
    4747    const std::string NotificationQueue::DEFAULT_FONT = "VeraMono";
     48    const Vector2 NotificationQueue::DEFAULT_POSITION = Vector2(0.0,0.0);
    4849
    4950    /**
     
    7879        this->tickTime_ = 0.0;
    7980       
    80         NotificationManager::registerQueue(this);
     81        NotificationManager::getInstance().registerQueue(this);
    8182    }
    8283   
     
    9091        this->setNotificationLength(DEFAULT_LENGTH);
    9192        this->setDisplayTime(DEFAULT_DISPLAY_TIME);
     93        this->setPosition(DEFAULT_POSITION);
    9294       
    9395        this->setTargets(NotificationManager::ALL);
     
    113115        XMLPortParam(NotificationQueue, "font", setFont, getFont, xmlElement, mode);
    114116        XMLPortParam(NotificationQueue, "fontSize", setFontSize, getFontSize, xmlElement, mode);
     117        XMLPortParam(NotificationQueue, "position", setPosition, getPosition, xmlElement, mode);
    115118       
    116119        COUT(3) << "NotificationQueue created." << std::endl;
     
    152155        this->clear();
    153156   
    154         std::multimap<std::time_t,Notification*>* notifications = NotificationManager::getNotifications(this, this->displayTime_);
     157        std::multimap<std::time_t,Notification*>* notifications = NotificationManager::getInstance().getNotifications(this, this->displayTime_);
    155158       
    156159        if(notifications == NULL)
     
    315318            return false;
    316319        this->fontSize_ = size;
    317         for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Set the font size for each overlay.
     320        for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font size for each overlay.
    318321        {
    319322            it->second->overlay->setFontSize(size);
     
    333336    {
    334337        this->font_ = font;
    335         for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Set the font for each overlay.
     338        for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font for each overlay.
    336339        {
    337340            it->second->overlay->setFont(font);
     
    345348        {
    346349            it->second->overlay->scroll(pos);
     350        }
     351    }
     352
     353    void NotificationQueue::positionChanged()
     354    {
     355        int counter = 0;
     356        for (std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin(); it != this->containers_.end(); it++) //!< Set the position for each overlay.
     357        {
     358            (*it)->overlay->setPosition(this->getPosition());
     359            (*it)->overlay->scroll(Vector2(0.0,(1.1*this->getFontSize())*counter));
     360            counter++;
    347361        }
    348362    }
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h

    r2783 r2785  
    4444#include <map>
    4545#include <ctime>
    46 #include "util/Math.h"
    4746
    4847#include "orxonox/overlays/OverlayGroup.h"
     
    114113            inline int getDisplayTime() const
    115114                { return this->displayTime_; }
    116                
    117115            /**
    118             @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.
    119             @return Retuns a set of string holding the different targets.
     116            @brief Returns the position of the NotificationQueue.
     117            @return Returns the position.
    120118            */
    121             inline const std::set<std::string> & getTargetsSet()
    122                 { return this->targets_; }
    123             bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
    124            
     119            inline const Vector2 & getPosition() const
     120                { return this->position_; }
    125121            /**
    126122            @brief Returns the font size used to display the Notifications.
     
    135131            inline const std::string & getFont() const
    136132                { return this->font_; }
     133               
     134            /**
     135            @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.
     136            @return Retuns a set of string holding the different targets.
     137            */
     138            inline const std::set<std::string> & getTargetsSet()
     139                { return this->targets_; }
     140            bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
     141           
     142            inline void setPosition(Vector2 pos)
     143                { this->position_ = pos; this->positionChanged(); }
    137144
    138145            void scroll(const Vector2 pos);
     
    142149            static const int DEFAULT_LENGTH = 64; //!< The default maximum number of Notifications displayed.
    143150            static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
    144             static const float DEFAULT_FONT_SIZE = 0.02; //!< The default font size.
     151            static const float DEFAULT_FONT_SIZE = 0.025; //!< The default font size.
     152
    145153            static const std::string DEFAULT_FONT; //!< The default font.
     154            static const Vector2 DEFAULT_POSITION; //!< the default position.
    146155       
    147156            int maxSize_; //!< The maximal number of Notifications displayed.
     
    149158            int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have.
    150159            int displayTime_; //!< The time a Notification is displayed.
     160            Vector2 position_; //!< The position of the NotificationQueue.
    151161           
    152162            std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
     
    172182            bool setFontSize(float size); //!< Set the font size.
    173183            bool setFont(const std::string & font); //!< Set the font.
     184
     185            void positionChanged();
    174186           
    175187            void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
Note: See TracChangeset for help on using the changeset viewer.