Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 9, 2010, 10:59:01 PM (14 years ago)
Author:
dafrick
Message:

Finished EditMode, needs some polish (no not the language…) though.
Took better advantage of lua tables in NotificationLayer.lua
Fixed a lot of bugs, it really is a miracle that the Notifications worked as well as they did.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/notifications/src/modules/notifications/NotificationManager.cc

    r7362 r7395  
    2828
    2929/**
    30     @file
     30    @file NotificationManager.cc
    3131    @brief Implementation of the NotificationManager class.
    3232*/
     
    4343#include "NotificationQueue.h"
    4444
     45#include "ToluaBindNotifications.h"
     46
    4547namespace orxonox
    4648{
     
    4951    const std::string NotificationManager::NONE("none");
    5052
     53    // Register tolua_open function when loading the library.
     54    DeclareToluaInterface(Notifications);
     55
    5156    ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false);
    5257
     
    6570
    6671        ModifyConsoleCommand("enterEditMode").setObject(this);
    67 
    68         if(GameMode::showsGraphics())
    69         {
    70             GUIManager::getInstance().loadGUI("NotificationLayer");
    71 
    72             // Create first queue:
    73             this->queues_.push_back(new NotificationQueue("all"));
    74         }
     72       
     73        COUT(3) << "NotificatioManager created." << std::endl;
    7574    }
    7675
     
    8281    {
    8382        ModifyConsoleCommand("enterEditMode").setObject(NULL);
     83
     84        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
     85            it->second->destroy();
     86       
     87        COUT(3) << "NotificationManager destroyed." << std::endl;
    8488    }
    8589
    8690    void NotificationManager::preDestroy(void)
    8791    {
    88         for(std::vector<NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++)
    89             (*it)->destroy();
     92        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); )
     93        {
     94            NotificationQueue* queue = (*it).second;
     95            it++;
     96            queue->destroy();
     97        }
    9098        this->queues_.clear();
    9199    }
     
    101109    bool NotificationManager::registerNotification(Notification* notification)
    102110    {
    103 
    104         if(notification == NULL) //!< A NULL-Notification cannot be registered.
     111        if(notification == NULL) // A NULL-Notification cannot be registered.
    105112            return false;
    106113
    107114        std::time_t time = std::time(0); //TODO: Doesn't this expire? //!< Get current time.
    108115
    109         this->allNotificationsList_.insert(std::pair<std::time_t,Notification*>(time,notification));
    110 
    111         if(notification->getSender() == NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.
     116        this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification));
     117
     118        if(notification->getSender() == NotificationManager::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.
    112119            return true;
    113120
    114121        bool all = false;
    115         if(notification->getSender() == ALL) // If all are the sender, then the Notifications is added to every NotificationListener.
     122        if(notification->getSender() == NotificationManager::ALL) // If all are the sender, then the Notifications is added to every NotificationListener.
    116123            all = true;
    117124
     
    119126        for(std::map<NotificationListener*,int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all listeners.
    120127        {
    121             std::set<std::string> set = it->first->getTargetsSet();
    122             if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TODO: Make sure this works.
     128            std::set<std::string, NotificationListenerStringCompare> set = it->first->getTargetsSet();
     129            bool bAll = set.find(NotificationManager::ALL) != set.end();
     130            if(all || bAll || set.find(notification->getSender()) != set.end()) //TODO: Make sure this works.
    123131            {
    124                 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); // Insert the Notification in the Notifications list of the current NotificationListener.
     132                if(!bAll)
     133                {
     134                    this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the Notifications list of the current NotificationListener.
     135                }
    125136                it->first->update(notification, time); // Update the listener.
    126137                std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification);
     
    132143        }
    133144
    134         COUT(4) << "Notification registered with the NotificationManager." << std::endl;
     145        COUT(4) << "Notification (&" << notification << ") registered with the NotificationManager." << std::endl;
    135146
    136147        return true;
     
    154165            this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1;
    155166
    156         // If the Notification is no longer present in any of the NotificationListeners it can be removed from the map of all Notifications and be destroyed.
    157         if(this->listenerCounter_[notification] == (unsigned int) 0)
    158         {
    159             this->removeNotification(notification, this->allNotificationsList_);
    160             this->listenerCounter_.erase(notification);
    161             notification->destroy();
    162         }
    163 
    164         COUT(4) << "Notification unregistered with the NotificationManager." << std::endl;
     167        COUT(4) << "Notification (&" << notification << ")unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl;
    165168    }
    166169
     
    175178        Returns true if successful.
    176179    */
    177     //TODO: Needed?
    178180    bool NotificationManager::removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map)
    179181    {
     
    206208        this->listenerList_[listener] = index; // Add the NotificationListener to the list of listeners.
    207209
    208         std::set<std::string> set = listener->getTargetsSet(); //TODO: Does this work?
     210        std::set<std::string, NotificationListenerStringCompare> set = listener->getTargetsSet();
    209211
    210212        // 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.
    211         if(set.find(ALL) != set.end())
    212         {
     213        bool bAll = set.find(NotificationManager::ALL) != set.end();
     214        std::multimap<std::time_t, Notification*> map;
     215        if(bAll)
    213216            this->notificationLists_[index] = &this->allNotificationsList_;
    214             COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
    215             return true;
    216         }
    217 
    218         this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>;
    219         std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index];
     217        else
     218        {
     219            this->notificationLists_[index] = new std::multimap<std::time_t, Notification*>;
     220            map = *this->notificationLists_[index];
     221        }
    220222
    221223        // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener.
    222         for(std::multimap<std::time_t,Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
    223         {
    224             if(set.find(it->second->getSender()) != set.end()) // Checks whether the overlay has the sender of the current notification as target.
     224        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
     225        {
     226            if(bAll || set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current notification as target.
    225227            {
    226                 map.insert(std::pair<std::time_t, Notification*>(it->first, it->second));
     228                if(!bAll)
     229                    map.insert(std::pair<std::time_t, Notification*>(it->first, it->second));
    227230                std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second);
    228231                if(counterIt == this->listenerCounter_.end())
     
    288291            return false;
    289292
    290         std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // The Notifications for the input NotificationListener.
    291 
    292         if(notifications == NULL) // Returns NULL, if there are no Notifications.
    293             return true;
     293        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // The Notifications for the input NotificationListener.
     294
     295        if(notifications == NULL) // Returns false, if there are no Notifications.
     296            return false;
    294297
    295298        std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
    296299        itLowest = notifications->lower_bound(timeFrameStart);
    297         itHighest = notifications->upper_bound(timeFrameStart);
     300        itHighest = notifications->upper_bound(timeFrameEnd);
    298301
    299302        for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time Frame to the end of it.
    300         {
    301             map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); // Add the found Notifications to the map.
    302         }
     303            map->insert(std::pair<std::time_t, Notification*>(it->first,it->second)); // Add the found Notifications to the map.
    303304
    304305        return true;
    305306    }
    306307
    307     void NotificationManager::createQueue(const std::string& name, const std::string& targets, unsigned int size, unsigned int displayTime)
    308     {
    309         this->queues_.push_back(new NotificationQueue(name, targets, size, displayTime));
     308    void NotificationManager::loadQueues(void)
     309    {
     310        new NotificationQueue("all");
     311    }
     312
     313    void NotificationManager::createQueue(const std::string& name)
     314    {
     315        new NotificationQueue(name);
     316    }
     317
     318    NotificationQueue* NotificationManager::getQueue(const std::string & name)
     319    {
     320        std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.find(name);
     321        if(it == this->queues_.end())
     322            return NULL;
     323
     324        return (*it).second;
     325    }
     326
     327    bool NotificationManager::registerQueue(NotificationQueue* queue)
     328    {
     329        return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second;
     330    }
     331   
     332    void NotificationManager::unregisterQueue(NotificationQueue* queue)
     333    {
     334        this->queues_.erase(queue->getName());
    310335    }
    311336
Note: See TracChangeset for help on using the changeset viewer.