Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6944


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.

Location:
code/branches/presentation3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/data/levels/quest_test.oxw

    r6939 r6944  
    1717<?lua
    1818    dofile("includes/CuboidSpaceStation.lua")
    19 ?>
    20 
    21 <NotificationQueue
    22          name     = "notification"
    23          position = "0.40, 0.05"
    24          font     = "VeraMono"
    25          textsize = 0.020
    26          length   = 3
    27          width    = 50
    28 />
    29        
    30        
     19?>     
    3120       
    3221<Level
     
    3423description="Erste Versuche mit den Quests"
    3524>
     25
     26    <NotificationQueue
     27             name     = "notification"
     28             position = "0.40, 0.05"
     29             font     = "VeraMono"
     30             textsize = 0.020
     31             length   = 3
     32             width    = 50
     33    />
    3634
    3735    <Scene
     
    262260                    <events>
    263261                      <trigger>
    264                         <QuestListener questId="dbd02b4c-ab7c-46fd-bdaf-fd4c19ac1551" mode="recieve" />
     262                        <QuestListener questId="dbd02b4c-ab7c-46fd-bdaf-fd4c19ac1551" mode="start" />
    265263                      </trigger>
    266264                    </events>
     
    271269                    <events>
    272270                      <trigger>
    273                              <QuestListener questId="dbd02b4c-ab7c-46fd-bdaf-fd4c19ac1551" mode="recieve" />
     271                             <QuestListener questId="dbd02b4c-ab7c-46fd-bdaf-fd4c19ac1551" mode="start" />
    274272                      </trigger>
    275273                    </events>
  • 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.