Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2009, 12:33:16 AM (15 years ago)
Author:
landauf
Message:

Moved Notification and NotificationManger from overlays to the quest objects (NotificationOverlay and NotificationQueue remain with the other overlays).

Added a new interface NotificationListener. The NotificationManager sends notifications to all listeners. NotificationQueue is such a listener (through inheritance). This removes another dependency between orxonox and overlays.

Location:
code/branches/libraries/src/orxonox
Files:
3 added
9 edited
4 moved

Legend:

Unmodified
Added
Removed
  • code/branches/libraries/src/orxonox/OrxonoxPrereqs.h

    r5613 r5619  
    223223    class Pong;
    224224
    225     class Scores;
    226     class CreateLines;
    227     class Scoreboard;
    228     class Stats;
    229 
    230225    // collision
    231226    class CollisionShape;
     
    257252    class InGameConsole;
    258253    class Notification;
     254    class NotificationListener;
    259255    class NotificationManager;
    260256    class NotificationOverlay;
     
    268264    class KillMessage;
    269265    class DeathMessage;
     266    class Map;
     267
    270268    class CreateLines;
    271269    class Scoreboard;
    272     class Map;
     270    class Stats;
    273271
    274272    //sound
  • code/branches/libraries/src/orxonox/gamestates/GSLevel.cc

    r3370 r5619  
    4848#include "objects/Radar.h"
    4949#include "objects/quest/QuestManager.h"
    50 #include "overlays/notifications/NotificationManager.h"
     50#include "objects/quest/notifications/NotificationManager.h"
    5151#include "CameraManager.h"
    5252#include "LevelManager.h"
  • code/branches/libraries/src/orxonox/interfaces/InterfaceCompilation.cc

    r3327 r5619  
    4040#include "Tickable.h"
    4141#include "TimeFactorListener.h"
     42#include "NotificationListener.h"
    4243
    4344#include "core/CoreIncludes.h"
     
    108109        RegisterObject(Rewardable);
    109110    }
     111
     112    //----------------------------
     113    // NotificationListener
     114    //----------------------------
     115    NotificationListener::NotificationListener()
     116    {
     117        RegisterObject(NotificationListener);
     118    }
    110119}
  • code/branches/libraries/src/orxonox/objects/quest/CMakeLists.txt

    r3196 r5619  
    1818  QuestNotification.cc
    1919)
     20
     21ADD_SUBDIRECTORY(notifications)
  • code/branches/libraries/src/orxonox/objects/quest/QuestNotification.h

    r3196 r5619  
    2626 *
    2727 */
    28  
     28
    2929#ifndef _QuestNotification_H__
    3030#define _QuestNotification_H__
     
    3333
    3434#include <string>
    35 #include "overlays/notifications/Notification.h"
     35#include "notifications/Notification.h"
    3636
    3737namespace orxonox {
     
    3939    /**
    4040    @brief
    41        
     41
    4242    @author
    4343        Damian 'Mozork' Frick
     
    4949            QuestNotification(const std::string & message);
    5050            virtual ~QuestNotification();
    51            
     51
    5252            bool send(void);
    53      
     53
    5454        private:
    5555            static const std::string SENDER;
    56            
     56
    5757            void initialize(void);
    58  
     58
    5959    };
    6060
  • code/branches/libraries/src/orxonox/objects/quest/notifications/NotificationManager.cc

    r5616 r5619  
    3838#include "core/CoreIncludes.h"
    3939#include "Notification.h"
    40 #include "NotificationQueue.h"
     40#include "interfaces/NotificationListener.h"
    4141
    4242namespace orxonox
     
    6969    /**
    7070    @brief
    71         Registers a Notification within the NotificationManager and makes sure that the Notification is displayed in all the NotificationQueues associated with its sender.
     71        Registers a Notification within the NotificationManager and makes sure that the Notification is sent to all the NotificationListeners associated with its sender.
    7272    @param notification
    7373        The Notification to be registered.
     
    7777    bool NotificationManager::registerNotification(Notification* notification)
    7878    {
    79    
     79
    8080        if(notification == NULL) //!< A NULL-Notification cannot be registered.
    8181            return false;
    82        
     82
    8383        std::time_t time = std::time(0); //TDO: Doesn't this expire? //!< Get current time.
    84        
     84
    8585        this->allNotificationsList_.insert(std::pair<std::time_t,Notification*>(time,notification));
    86        
     86
    8787        if(notification->getSender() == NONE) //!< If the sender has no specific name, then the Notification is only added to the list of all Notifications.
    8888            return true;
    89        
     89
    9090        bool all = false;
    91         if(notification->getSender() == ALL) //!< If all are the sender, then the Notifications is added to every NotificationQueue.
     91        if(notification->getSender() == ALL) //!< If all are the sender, then the Notifications is added to every NotificationListener.
    9292            all = true;
    93        
    94         //!< Insert the notification in all queues that have its sender as target.
    95         for(std::map<NotificationQueue*,int>::iterator it = this->queueList_.begin(); it != this->queueList_.end(); it++) //!< Iterate through all queues.
     93
     94        //!< Insert the notification in all listeners that have its sender as target.
     95        for(std::map<NotificationListener*,int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) //!< Iterate through all listeners.
    9696        {
    9797            std::set<std::string> set = it->first->getTargetsSet();
    9898            if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TDO: Make sure this works.
    9999            {
    100                 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationQueue.
    101                 it->first->update(notification, time); //!< Update the queue.
     100                this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationListener.
     101                it->first->update(notification, time); //!< Update the listener.
    102102            }
    103103        }
    104        
     104
    105105        COUT(3) << "Notification registered with the NotificationManager." << std::endl;
    106        
     106
    107107        return true;
    108108    }
    109    
     109
    110110    /**
    111111    @brief
    112         Registers a NotificationQueue within the NotificationManager.
    113     @param queue
    114         The NotificationQueue to be registered.
     112        Registers a NotificationListener within the NotificationManager.
     113    @param listener
     114        The NotificationListener to be registered.
    115115    @return
    116116        Returns true if successful.
    117117    */
    118     bool NotificationManager::registerQueue(NotificationQueue* queue)
     118    bool NotificationManager::registerListener(NotificationListener* listener)
    119119    {
    120120        this->highestIndex_ += 1;
    121121        int index = this->highestIndex_;
    122        
    123         this->queueList_[queue] = index; //!< Add the NotificationQueue to the list of queues.
    124        
    125         std::set<std::string> set = queue->getTargetsSet(); //TDO: Works this?
    126        
    127         //! If all senders are the target of the queue, then the list of notification for that specific queue is te same as the list of all Notifications.
     122
     123        this->listenerList_[listener] = index; //!< Add the NotificationListener to the list of listeners.
     124
     125        std::set<std::string> set = listener->getTargetsSet(); //TDO: Works this?
     126
     127        //! If all senders are the target of the listener, then the list of notification for that specific listener is te same as the list of all Notifications.
    128128        if(set.find(ALL) != set.end())
    129129        {
    130130            this->notificationLists_[index] = &this->allNotificationsList_;
    131             COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
     131            COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl;
    132132            return true;
    133133        }
    134        
     134
    135135        this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>;
    136136        std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index];
    137        
    138         //! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationQueue.
     137
     138        //! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener.
    139139        for(std::multimap<std::time_t,Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
    140140        {
     
    144144            }
    145145        }
    146        
    147         queue->update(); //!< Update the queue.
    148146
    149         COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
    150        
     147        listener->update(); //!< Update the listener.
     148
     149        COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl;
     150
    151151        return true;
    152152    }
    153    
     153
    154154    /**
    155155    @brief
    156         Fetches the Notifications for a specific NotificationQueue in a specified timeframe.
    157     @param queue
    158         The NotificationQueue the Notifications are fetched for.
     156        Fetches the Notifications for a specific NotificationListener in a specified timeframe.
     157    @param listener
     158        The NotificationListener the Notifications are fetched for.
    159159    @param map
    160160        A multimap, in which the notifications are stored.
     
    166166        Returns true if successful.
    167167    */
    168     bool NotificationManager::getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
     168    bool NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
    169169    {
    170         if(queue == NULL || map == NULL)
     170        if(listener == NULL || map == NULL)
    171171            return false;
    172172
    173         std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]]; //!< The Notifications for the input NotificationQueue.
    174        
     173        std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; //!< The Notifications for the input NotificationListener.
     174
    175175        if(notifications == NULL) //!< Returns NULL, if there are no Notifications.
    176176            return true;
    177    
     177
    178178        std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
    179179        itLowest = notifications->lower_bound(timeFrameStart);
    180180        itHighest = notifications->upper_bound(timeFrameStart);
    181        
     181
    182182        for(it = itLowest; it != itHighest; it++) //!< Iterate through the Notifications from the start of the time Frame to the end of it.
    183183        {
    184184            map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); //!< Add the found Notifications to the map.
    185185        }
    186        
     186
    187187        return true;
    188188    }
  • code/branches/libraries/src/orxonox/objects/quest/notifications/NotificationManager.h

    r5616 r5619  
    4949    /**
    5050    @brief
    51         The Singleton NotificationManager functions as a gateway between Notifications and NotificationQueues.
    52         It receives, organizes Notifications and the redistributes them to the specific NotificationQueues.
     51        The Singleton NotificationManager functions as a gateway between Notifications and NotificationListeners.
     52        It receives, organizes Notifications and the redistributes them to the specific NotificationListeners.
    5353    @author
    5454        Damian 'Mozork' Frick
     
    6565
    6666            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
    67             bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager.
     67            bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
    6868
    69             bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.
     69            bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe.
    7070
    7171            /**
    72             @brief Fetches the Notifications for a specific NotificationQueue starting at a specified time.
    73             @param queue The NotificationQueue the Notifications are fetched for.
     72            @brief Fetches the Notifications for a specific NotificationListener starting at a specified time.
     73            @param listener The NotificationListener the Notifications are fetched for.
    7474            @param map A multimap, in which the notifications are stored.
    7575            @param timeFrameStart The start time the Notifications are fetched from.
    7676            @return Returns true if successful.
    7777            */
    78             bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart)
    79                 { return this->getNotifications(queue, map, timeFrameStart, std::time(0)); }
     78            bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart)
     79                { return this->getNotifications(listener, map, timeFrameStart, std::time(0)); }
    8080            /**
    81             @brief Fetches the Notifications for a specific NotificationQueue starting at a specified timespan before now.
    82             @param queue The NotificationQueue the Notifications are fetched for.
     81            @brief Fetches the Notifications for a specific NotificationListener starting at a specified timespan before now.
     82            @param listener The NotificationListener the Notifications are fetched for.
    8383            @param map A multimap, in which the notifications are stored.
    8484            @param timeDelay The timespan.
    8585            @return Returns true if successful.
    8686            */
    87             bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, int timeDelay)
    88                 { return this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
     87            bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, int timeDelay)
     88                { return this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
    8989
    9090        private:
     
    9494
    9595            std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored (together with their respecive timestamps).
    96             std::map<NotificationQueue*,int> queueList_; //!< Container where all NotificationQueues are stored with a number as identifier.
    97             std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored.
     96            std::map<NotificationListener*,int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
     97            std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
    9898
    9999
  • code/branches/libraries/src/orxonox/overlays/notifications/CMakeLists.txt

    r2911 r5619  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
    2   Notification.cc
    3   NotificationManager.cc
    42  NotificationOverlay.cc
    53  NotificationQueue.cc
  • code/branches/libraries/src/orxonox/overlays/notifications/NotificationOverlay.cc

    r3301 r5619  
    3636#include "util/Exception.h"
    3737#include "core/CoreIncludes.h"
    38 #include "Notification.h"
     38#include "objects/quest/notifications/Notification.h"
    3939#include "NotificationQueue.h"
    4040
     
    6565    {
    6666        this->initialize();
    67        
     67
    6868        if(notification == NULL || queue == NULL) //!> If either notification or queue are not given an Exception is thrown.
    6969        {
     
    7373        this->queue_ = queue;
    7474        this->defineOverlay();
    75        
     75
    7676        this->processNotification(notification);
    7777    }
    78    
     78
    7979    /**
    8080    @brief
     
    8585        this->queue_ = NULL;
    8686    }
    87    
     87
    8888    /**
    8989    @brief
  • code/branches/libraries/src/orxonox/overlays/notifications/NotificationQueue.cc

    r3301 r5619  
    3939#include "core/XMLPort.h"
    4040#include "NotificationOverlay.h"
    41 #include "NotificationManager.h"
     41#include "objects/quest/notifications/NotificationManager.h"
    4242
    4343namespace orxonox
     
    8080        this->tickTime_ = 0.0;
    8181
    82         NotificationManager::getInstance().registerQueue(this);
     82        NotificationManager::getInstance().registerListener(this);
    8383    }
    8484
  • code/branches/libraries/src/orxonox/overlays/notifications/NotificationQueue.h

    r3196 r5619  
    4545#include "interfaces/Tickable.h"
    4646#include "overlays/OverlayGroup.h"
     47#include "interfaces/NotificationListener.h"
    4748
    4849namespace orxonox
     
    5758        std::string name; //!< The name of the overlay.
    5859    };
    59    
     60
    6061    //! Struct to allow ordering of NotificationOverlayContainers.
    6162    struct NotificationOverlayContainerCompare {
     
    8485    */
    8586
    86     class _OrxonoxExport NotificationQueue : public OverlayGroup, public Tickable
     87    class _OrxonoxExport NotificationQueue : public OverlayGroup, public Tickable, public NotificationListener
    8788    {
    88    
     89
    8990        public:
    9091            NotificationQueue(BaseObject* creator);
    9192            virtual ~NotificationQueue();
    92            
     93
    9394            virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); //!< Method for creating a NotificationQueue object through XML.
    94            
     95
    9596            virtual void tick(float dt); //!< To update from time to time.
    96            
     97
    9798            void update(void); //!< Updates the queue.
    9899            void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.
    99            
     100
    100101            /**
    101102            @brief Returns the maximum number of Notifications displayed.
     
    140141            inline const std::string & getFont() const
    141142                { return this->font_; }
    142                
     143
    143144            /**
    144145            @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.
     
    148149                { return this->targets_; }
    149150            bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
    150            
     151
    151152            /**
    152153            @brief Sets the position of the NotificationQueue.
    153154            @param pos The position.
    154155            */
    155             inline void setPosition(Vector2 pos) 
     156            inline void setPosition(Vector2 pos)
    156157                { this->position_ = pos; this->positionChanged(); }
    157158
    158159            void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.
    159            
     160
    160161        private:
    161162            static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
     
    166167            static const std::string DEFAULT_FONT; //!< The default font.
    167168            static const Vector2 DEFAULT_POSITION; //!< the default position.
    168        
     169
    169170            int maxSize_; //!< The maximal number of Notifications displayed.
    170171            int size_; //!< The number of Notifications displayed.
     
    172173            int displayTime_; //!< The time a Notification is displayed.
    173174            Vector2 position_; //!< The position of the NotificationQueue.
    174            
     175
    175176            std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
    176            
     177
    177178            float fontSize_; //!< The font size.
    178179            std::string font_; //!< The font.
    179            
     180
    180181            std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare> containers_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps.
    181182            std::map<Notification*, NotificationOverlayContainer*> overlays_; //!< Mapping notifications to their corresponding overlay containers, for easier association and finding.
    182            
     183
    183184            float tickTime_; //!< Helper variable, to not have to check for overlays that have been displayed too long, every tick.
    184185            NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
    185            
     186
    186187            void initialize(void); //!< Initializes the object.
    187188            void setDefaults(void); //!< Helper method to set the default values.
    188            
     189
    189190            bool setMaxSize(int size); //!< Sets the maximum number of displayed Notifications.
    190191            bool setNotificationLength(int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.
    191192            bool setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed.
    192            
     193
    193194            bool setTargets(const std::string & targets); //!< Set the targets of this queue.
    194            
     195
    195196            bool setFontSize(float size); //!< Set the font size.
    196197            bool setFont(const std::string & font); //!< Set the font.
    197198
    198199            void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
    199            
     200
    200201            void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
    201202            bool removeContainer(NotificationOverlayContainer* container); //!< Remove a container from the queue.
    202            
     203
    203204            void clear(void); //!< Clear the queue.
    204    
     205
    205206    };
    206207
Note: See TracChangeset for help on using the changeset viewer.