Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7488


Ignore:
Timestamp:
Sep 24, 2010, 12:01:57 PM (14 years ago)
Author:
dafrick
Message:

Some more documentation.
Making NotificationManager Root scope, cleaning up, especially in Notification (now it's just a data structure anymore).

Location:
code/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/doc/api/Groups.dox

    r7487 r7488  
    153153    The Notifications module has three major parts that interact with each other. First there is the @ref orxonox::NotificationQueue "NotificationQueue", this is the entity that (logically, not effectively) displays @ref orxonox::Notification "Notifications" according to some rules, then there is the NotificationLayer, which is the GUI which (actually) displays @ref orxonox::Notification "Notifications" by visualizing the @ref orxonox::NotificationQueue "NotificationQueues" and as a result also the @ref orxonox::Notification "Notifications", that are displayed by the respective @ref orxonox::NotificationQueue "NotificationQueues" and lastly there is the @ref orxonox::NotificationManager "NotificationManager", which connects these two.
    154154
     155    @subsection NotificationQueue NotificationQueue
     156    The @ref orxonox::NotificationQueue "NotificationQueue" is the entity, that (as said earlier) logically displays @ref orxonox::Notification "Notifications". Furthermore a @ref orxonox::NotificationQueue "NotificationQueue" displays only a subset of all the @ref orxonox::Notification "Notifications". The parameters that reduce the range of @ref orxonox::Notification "Notifications" are:
     157    - @b senders The senders, set of targets of a @ref orxonox::NotificationQueue "NotificationQueue" is the set of senders a @ref orxonox::NotificationQueue "NotificationQueue" displays  @ref orxonox::Notification "Notifications" from. E.g. If one would set the senders to "questsystem" then only  @ref orxonox::Notification "Notifications" from the Questsystem wouuld be displayed in that particular queue. If you set senders to "all" then all Notifications will be displayed. Different senders can be concatinated with commas.
     158    - @b size The size specifies how many @ref orxonox::Notification "Notifications" are displayed at the most, if there are more @ref orxonox::Notification "Notifications" that could be displayed but the size is smaller than the number of @ref orxonox::Notification "Notifications", then only the most recent are displayed.
     159    - @b displayTime The display time specifies how long a @ref orxonox::Notification "Notification" is displayed at the most.
     160
    155161    @subsection NotificationLayer NotificationLayer
    156162    The NotificationLayer is a GUI sheet, that displays all the @ref orxonox::NotificationQueue "NotificationQueues" and their @ref orxonox::Notification "Notifications". In its normal mode of operation it is transparent to input, meaning that it only functions as a means of displaying, however if switched to edit mode the NotificationLayer no longer is transparent to input and allows for the adding, removal and modification of @ref orxonox::NotificationQueue "NotificationQueues".
    157163
    158     @subsection NotificationQueue NotificationQueue
    159     ...
    160 
    161164    @subsection NotificationManager NotificationManager
    162     ...
     165    The @ref orxonox::NotificationManager "NotificationManager" is (hence the name) the managing entity in this setting. It is responsible for the registering and unregistering of @ref orxonox::NotificationListener "NotificationListeners" (which the @ref orxonox::NotificationQueue "NotificationQueue" is) and also informs them about changes related to @ref orxonox::Notification "Notifications". It is also responsible for the creation and destruction of @ref orxonox::NotificationQueue "NotificationQueues" through the NotificationLayer and is also the point of approach for the NotificationLayer to get information it needs. Finally the @ref orxonox::NotificationManager "NotificationManager" is responsible for sending (and in the process creating) @ref orxonox::Notification "Notifications" and is a means for the @ref orxonox::NotificationQueue "NotificationQueues" to get the information they need about @ref orxonox::Notification "Notifications".
    163166
    164167    @subsection Notification Notification
     
    172175    @defgroup NotificationDispatchers Dispatchers
    173176    @ingroup Notifications
     177
     178    @ref orxonox::NotificationDispatcher "NotificationDispatchers" are entities that are instantiated in a level file (through XML) and that dispatch (or send) a specific @ref orxonox::Notification "Notification" upon having received a triggering event.
     179
     180    At this point there are two @ref orxonox::NotificationDispatcher "NotificationDispatchers", the @ref orxonox::SimpleNotification "SimpleNotification", which just displays a specified message, and the @ref orxonox::CommandNotification "CommandNotification" which displays a message with a binding for a specified command in it.
    174181*/
    175182
  • code/trunk/src/modules/notifications/Notification.cc

    r7484 r7488  
    6060        The message of the Notification.
    6161    */
    62     Notification::Notification(const std::string & message)
     62    Notification::Notification(const std::string& message, const std::string& sender)
    6363    {
    6464        RegisterRootObject(Notification);
    6565        this->initialize();
    6666        this->message_ = message;
     67        this->sender_ = sender;
    6768    }
    6869
     
    8485        this->message_.clear();
    8586        this->sender_ = NotificationManager::NONE;
    86         this->sent_ = false;
    87     }
    88 
    89     /**
    90     @brief
    91         Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues.
    92     @param sender
    93         The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.
    94     @return
    95         Returns true if successful.
    96     */
    97     bool Notification::send(const std::string & sender)
    98     {
    99         if(this->isSent()) //TODO: Needed?
    100             return false;
    101 
    102         this->sender_ = sender;
    103         bool successful = NotificationManager::getInstance().registerNotification(this);
    104         if(!successful)
    105             return false;
    106         this->sent_ = true;
    107 
    108         COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
    109 
    110         return true;
    111     }
    112 
    113     /**
    114     @brief
    115         Sets the message of the notification.
    116     @param message
    117         The message to be set.
    118     @return
    119         Returns true if successful.
    120     */
    121     bool Notification::setMessage(const std::string & message)
    122     {
    123         if(this->isSent()) // The message cannot be changed if the message has already been sent.
    124             return false;
    125         this->message_ = message;
    126         return true;
    12787    }
    12888
  • code/trunk/src/modules/notifications/Notification.h

    r7486 r7488  
    5454        public:
    5555            Notification();
    56             Notification(const std::string & message);
     56            Notification(const std::string& message, const std::string& sender);
    5757            virtual ~Notification();
    5858
    59             bool send(const std::string & sender); //!< Sends the Notification to the Notificationmanager.
    60 
    61             /**
    62             @brief Checks whether the Notification was sent.
    63             @return Returns true if the Notification was sent already.
    64             */
    65             inline bool isSent(void) const
    66                 { return this->sent_; }
    6759            /**
    6860            @brief Returns the message of the Notification.
     
    7567                { return this->sender_; }
    7668
    77             bool setMessage(const std::string & message); //!< Sets the message of the notification.
    78 
    7969        private:
    8070            std::string message_; //!< The Notification message.
    8171            std::string sender_; //!< The sender of the notification.
    82             bool sent_; //!< Whether Notification has been sent, if so it cannot be changed.
    8372
    8473            void initialize(void); //!< Registers the object and sets some default values.
  • code/trunk/src/modules/notifications/NotificationDispatcher.cc

    r7484 r7488  
    8383        SUPER(NotificationDispatcher, XMLPort, xmlelement, mode);
    8484
     85        XMLPortParam(NotificationDispatcher, "sender", getSender, setSender, xmlelement, mode);
     86       
    8587        XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
    8688    }
  • code/trunk/src/modules/notifications/NotificationDispatcher.h

    r7484 r7488  
    4949        A NotificationDispatcher is an entity that, upon being triggered, dispatches (or sends) a specified @ref orxonox::Notification "Notification".
    5050
     51        There is one parameter to be set, the @b sender . The sender specifies the part of Orxonox the sent @ref orxonox::Notification "Notification" comes from. The default value is set by the classes implementing NotificationDispatcher.
     52
    5153        Its standard usage is:
    5254        @code
    53         <NotificationDispatcher>
     55        <NotificationDispatcher sender="me">
    5456            <events>
    5557                <trigger>
     
    7678            @return Returns the name of the sender.
    7779            */
    78             const std::string& getSender(void)
     80            const std::string& getSender(void) const
    7981                { return this->sender_; }
     82                        /**
     83            @brief Set the sender of the Notification dispatched by this NotificationDispatcher.
     84            @param sender The name of the sender.
     85            */
     86            void setSender(const std::string& sender)
     87                { this->sender_ = sender; }
    8088
    8189            void dispatch(unsigned int clientId); //!< Dispatches a specific Notification.
     
    8694
    8795            void registerVariables(void); //!< Register some variables for synchronisation.
    88 
    89             /**
    90             @brief Set the sender of the Notification dispatched by this NotificationDispatcher.
    91             @param sender The name of the sender.
    92             */
    93             void setSender(const std::string& sender)
    94                 { this->sender_ = sender; }
    9596
    9697            /**
  • code/trunk/src/modules/notifications/NotificationManager.cc

    r7486 r7488  
    5858    DeclareToluaInterface(Notifications);
    5959
    60     ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false);
     60    ManageScopedSingleton(NotificationManager, ScopeID::Root, false);
    6161
    6262    // Setting console command to enter the edit mode.
     
    8888        ModifyConsoleCommand("enterEditMode").setObject(NULL);
    8989
     90        // Destroys all Notifications.
     91        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it!= this->allNotificationsList_.end(); it++)
     92            it->second->destroy();
     93        this->allNotificationsList_.clear();
     94
    9095        COUT(3) << "NotificationManager destroyed." << std::endl;
    9196    }
     
    98103    {
    99104        // Destroys all NotificationQueues that have been registered with the NotificationManager.
    100         for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); )
    101         {
    102             NotificationQueue* queue = (*it).second;
    103             it++;
    104             queue->destroy();
     105        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++)
     106        {
     107            it->second->destroy(true);
    105108        }
    106109        this->queues_.clear();
     
    124127        if(GameMode::isStandalone() || isLocal || Host::getPlayerID() == clientId)
    125128        {
    126             Notification* notification = new Notification(message);
    127             notification->send(sender);
     129            Notification* notification = new Notification(message, sender);
     130            if(NotificationManager::getInstance().registerNotification(notification))
     131                COUT(3) << "Notification \"" << notification->getMessage() << "\" sent." << std::endl;
    128132        }
    129133        // If we're on the server (and the server is not the intended recipient of the Notification) we send it over the network.
  • code/trunk/src/modules/notifications/NotificationQueue.cc

    r7484 r7488  
    3838
    3939#include "core/CoreIncludes.h"
     40#include "core/GameMode.h"
    4041#include "core/GUIManager.h"
    4142#include "core/LuaState.h"
     
    112113        this->targets_.clear();
    113114
    114         if(this->registered_) // If the
    115         {
    116             this->clear();
     115        if(this->registered_) // If the NotificationQueue is registered.
     116        {
     117            this->clear(true);
    117118
    118119            // Unregister with the NotificationManager.
    119120            NotificationManager::getInstance().unregisterListener(this);
    120121            NotificationManager::getInstance().unregisterQueue(this);
    121 
    122             // Remove the NotificationQueue in lua.
     122        }
     123    }
     124
     125    /**
     126    @brief
     127        Destroys the NotificationQueue.
     128        Used in lua and NotificationManager.
     129    @param noGraphics
     130        If this is set to true (false is default), then the queue is not removed in lua. This is used to destroy the queue, after the GUIManager has been destroyed.
     131    */
     132    void NotificationQueue::destroy(bool noGraphics)
     133    {
     134        // Remove the NotificationQueue in lua.
     135        if(GameMode::showsGraphics() && !noGraphics)
    123136            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
    124         }
     137
     138        this->OrxonoxClass::destroy();
    125139    }
    126140
     
    131145    void NotificationQueue::create(void)
    132146    {
    133         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() +  "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
     147        if(GameMode::showsGraphics())
     148            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() +  "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
    134149    }
    135150
     
    226241
    227242        // Push the Notification to the GUI.
    228         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
     243        if(GameMode::showsGraphics())
     244            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
    229245    }
    230246
     
    254270
    255271        // Pops the Notification from the GUI.
    256         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
     272        if(GameMode::showsGraphics())
     273            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
    257274    }
    258275
     
    276293
    277294        // Removes the Notification from the GUI.
    278         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
     295        if(GameMode::showsGraphics())
     296            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
    279297    }
    280298
     
    282300    @brief
    283301        Clears the NotificationQueue by removing all NotificationContainers.
    284     */
    285     void NotificationQueue::clear(void)
     302    @param noGraphics
     303        If this is eset to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.
     304    */
     305    void NotificationQueue::clear(bool noGraphics)
    286306    {
    287307        this->ordering_.clear();
     
    295315
    296316        // Clear the NotificationQueue in the GUI.
    297         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
     317        if(GameMode::showsGraphics() && !noGraphics)
     318            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
    298319    }
    299320
  • code/trunk/src/modules/notifications/NotificationQueue.h

    r7486 r7488  
    6969
    7070        There are quite some parameters that influence the behaviour of the NotificationQueue:
    71         - 'name': The name of the NotificationQueue. It needs to be unique.
    72         - 'senders': The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
    73         - 'size': The size of the NotificationQueue, it specifies how many @ref orxonox::Notification "Notifications" are displayed at once at the most.
    74         - 'displayTime': The time a @ref orxonox::Notification "Notification" is displayed with this NotificationQueue.
     71        - @b name The name of the NotificationQueue. It needs to be unique.
     72        - @b senders The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
     73        - @b size The size of the NotificationQueue, it specifies how many @ref orxonox::Notification "Notifications" are displayed at once at the most.
     74        - @b displayTime The time a @ref orxonox::Notification "Notification" is displayed with this NotificationQueue.
    7575
    7676    @author
     
    8585            virtual ~NotificationQueue();
    8686
    87             /**
    88             @brief Destroys the NotificationQueue.
    89                    Used in lua.
    90             */
    91             void destroy(void) { this->OrxonoxClass::destroy(); } // tolua_export
     87            //! Destroys the NotificationQueue.
     88            void destroy(bool noGraphics = false); // tolua_export
    9289
    9390            virtual void tick(float dt); //!< To update from time to time.
     
    168165            void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); //!< Removes the Notification that is stored in the input NotificationContainer.
    169166
    170             void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers.
     167            void clear(bool noGraphics = false); //!< Clears the NotificationQueue by removing all NotificationContainers.
    171168
    172169    }; // tolua_export
  • code/trunk/src/modules/notifications/dispatchers/CommandNotification.h

    r7484 r7488  
    5050        In use it would like this:
    5151        @code
    52         <CommandNotification preMessage="Please press " command="someCommand" postMessage=" to do something." >
     52        <CommandNotification preMessage="Please press " command="someCommand" postMessage=" to do something." sender="me">
    5353            <events>
    5454                <trigger>
  • code/trunk/src/modules/notifications/dispatchers/SimpleNotification.h

    r7484 r7488  
    4949        In use it would like this:
    5050        @code
    51         <SimpleNotification message="some message..." >
     51        <SimpleNotification message="some message..." sender="me">
    5252            <events>
    5353                <trigger>
Note: See TracChangeset for help on using the changeset viewer.