Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 20, 2010, 9:43:45 PM (14 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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.