Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 20, 2010, 9:43:45 PM (15 years ago)
Author:
dafrick
Message:

No more seg-faults when restarting a game, quests still not working properly the second thime, though.
Also replaced QuestListener mode 'receive' with 'start' in quest_test, which appears to be the correct term.

Location:
code/branches/presentation3/src/modules/questsystem/notifications
Files:
4 edited

Legend:

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

    r6417 r6944  
    6666    NotificationManager::~NotificationManager()
    6767    {
     68       
    6869    }
    6970
     
    101102                this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationListener.
    102103                it->first->update(notification, time); //!< Update the listener.
     104                std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification);
     105                if(counterIt == this->listenerCounter_.end())
     106                    this->listenerCounter_[notification] = 1;
     107                else
     108                    this->listenerCounter_[notification] = counterIt->second + 1;
    103109            }
    104110        }
    105111
    106         COUT(3) << "Notification registered with the NotificationManager." << std::endl;
     112        COUT(4) << "Notification registered with the NotificationManager." << std::endl;
    107113
    108114        return true;
     115    }
     116
     117    /**
     118    @brief
     119        Unregisters a Notification within the NotificationManager.
     120    */
     121    void NotificationManager::unregisterNotification(Notification* notification, NotificationListener* listener)
     122    {
     123        assert(notification);
     124        assert(listener);
     125
     126        if(this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second)))
     127            this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1;
     128        if(this->listenerCounter_[notification] == (unsigned int) 0)
     129        {
     130            this->removeNotification(notification, this->allNotificationsList_);
     131            notification->destroy();
     132        }
     133
     134        COUT(4) << "Notification unregistered with the NotificationManager." << std::endl;
     135    }
     136
     137    /**
     138    @brief
     139        Helper method that removes an input notification form an input map.
     140    */
     141    bool NotificationManager::removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map)
     142    {
     143        for(std::multimap<std::time_t, Notification*>::iterator it = map.begin(); it != map.end(); it++)
     144        {
     145            if(it->second == notification)
     146            {
     147                map.erase(it);
     148                return true;
     149            }
     150        }
     151        return false;
    109152    }
    110153
     
    130173        {
    131174            this->notificationLists_[index] = &this->allNotificationsList_;
    132             COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl;
     175            COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
    133176            return true;
    134177        }
     
    142185            if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target.
    143186            {
    144                 map.insert(std::pair<std::time_t,Notification*>(it->first, it->second));
     187                map.insert(std::pair<std::time_t, Notification*>(it->first, it->second));
     188                std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second);
     189                if(counterIt == this->listenerCounter_.end())
     190                    this->listenerCounter_[it->second] = 1;
     191                else
     192                    this->listenerCounter_[it->second] = counterIt->second + 1;
    145193            }
    146194        }
     
    148196        listener->update(); //!< Update the listener.
    149197
    150         COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl;
     198        COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
    151199
    152200        return true;
     201    }
     202
     203    /**
     204    @brief
     205        Unregisters a NotificationListener withing the NotificationManager.
     206    */
     207    void NotificationManager::unregisterListener(NotificationListener* listener)
     208    {
     209        assert(listener);
     210
     211        int identifier = this->listenerList_.find(listener)->second;
     212        std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second;
     213       
     214        // Make sure all Notifications are removed.
     215        std::multimap<std::time_t, Notification*>::iterator it = map->begin();
     216        while(it != map->end())
     217        {
     218            this->unregisterNotification(it->second, listener);
     219            it = map->begin();
     220        }
     221
     222        this->listenerList_.erase(listener);
     223        this->notificationLists_.erase(identifier);
     224        delete map;
     225
     226        COUT(4) << "NotificationListener unregistered with the NotificationManager." << std::endl;
    153227    }
    154228
  • code/branches/presentation3/src/modules/questsystem/notifications/NotificationManager.h

    r5929 r6944  
    6464
    6565            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
     66            void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager.
    6667            bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
     68            void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager.
    6769
    6870            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.
     
    9092            static NotificationManager* singletonPtr_s;
    9193
    92             int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that  no key appears twice.
     94            int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
    9395
    94             std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored (together with their respecive timestamps).
     96            std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored.
    9597            std::map<NotificationListener*,int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
    9698            std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
     99            std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with.
     100
     101            bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map);
    97102
    98103
  • code/branches/presentation3/src/modules/questsystem/notifications/NotificationQueue.cc

    r6502 r6944  
    5656    NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayGroup(creator)
    5757    {
     58        this->registered_ = false;
     59       
    5860        RegisterObject(NotificationQueue);
    5961        this->initialize();
     
    6870        this->targets_.clear();
    6971        this->clear();
     72
     73        if(this->registered_)
     74            NotificationManager::getInstance().unregisterListener(this);
    7075    }
    7176
     
    8186
    8287        NotificationManager::getInstance().registerListener(this);
     88        this->registered_ = true;
    8389    }
    8490
     
    423429            return false;
    424430
     431        NotificationManager::getInstance().unregisterNotification(container->notification, this);
     432       
    425433        this->removeElement(container->overlay);
    426434        this->containers_.erase(container);
     
    443451        {
    444452            this->removeContainer(*it);
    445             it = this->containers_.begin(); //TODO: Needed?
     453            it = this->containers_.begin();
    446454        }
    447455    }
  • code/branches/presentation3/src/modules/questsystem/notifications/NotificationQueue.h

    r5781 r6944  
    185185            NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
    186186
     187            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
     188
    187189            void initialize(void); //!< Initializes the object.
    188190            void setDefaults(void); //!< Helper method to set the default values.
Note: See TracChangeset for help on using the changeset viewer.