Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 21, 2010, 11:15:44 PM (14 years ago)
Author:
dafrick
Message:

Synchronizing Notifications.
In the course of that, notifications are not longer sent by creating a Notification and the calling notification.send() bur by letting the NotificationManager handle all this: NotificationManager::getInstance().sendNotification(message)
This made QuestNotification obsolete, thus it was removde.

Also did some work on synchronizing the Script class. It should work properly most of the time, but the current solution is unreliable and unsatisfactory. So this will change as soon as I know how.

Location:
code/trunk/src/modules/notifications
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/notifications/Notification.cc

    r7463 r7474  
    4242{
    4343
    44     CreateUnloadableFactory(Notification);
    45 
    46     registerMemberNetworkFunction(Notification, send);
    47 
    4844    /**
    4945    @brief
    5046        Default constructor. Initializes the object.
    51     @param creator
    52         The object that created this Notification
    5347    */
    54     Notification::Notification(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
     48    Notification::Notification()
    5549    {
    56         RegisterObject(Notification);
     50        RegisterRootObject(Notification);
    5751        this->initialize();
    5852        this->registerVariables();
     
    6761        The message of the Notification.
    6862    */
    69     Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator), Synchronisable(creator)
     63    Notification::Notification(const std::string & message)
    7064    {
    71         RegisterObject(Notification);
     65        RegisterRootObject(Notification);
    7266        this->initialize();
    7367        this->message_ = message;
    74         this->registerVariables();
    7568    }
    7669
     
    9588    }
    9689
    97     void Notification::registerVariables(void)
    98     {
    99         registerVariable(this->message_);
    100         registerVariable(this->sender_);
    101         registerVariable(this->sent_);
    102     }
    103 
    10490    /**
    10591    @brief
    10692        Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues.
    107     @param clientId
    108         The id of the client that this Notification is sent to.
    10993    @param sender
    11094        The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.
     
    11296        Returns true if successful.
    11397    */
    114     bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE)
    115     {
    116         COUT(0) << "MUP: " << Host::getPlayerID() << "|" << clientId << std::endl;
    117         if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
    118         {
    119             this->sendHelper(sender);
    120         }
    121         else if(GameMode::isServer())
    122         {
    123             callMemberNetworkFunction(Notification, send, this->getObjectID(), clientId, clientId, sender);
    124         }
    125 
    126         return true;
    127     }
    128 
    129     bool Notification::sendHelper(const std::string& sender)
     98    bool Notification::send(const std::string & sender)
    13099    {
    131100        if(this->isSent()) //TODO: Needed?
  • code/trunk/src/modules/notifications/Notification.h

    r7456 r7474  
    5151        Damian 'Mozork' Frick
    5252    */
    53     class _NotificationsExport Notification : public BaseObject, public Synchronisable
     53    class _NotificationsExport Notification : public OrxonoxClass
    5454    {
    5555        public:
    56             Notification(BaseObject* creator);
    57             Notification(BaseObject* creator, const std::string & message);
     56            Notification();
     57            Notification(const std::string & message);
    5858            virtual ~Notification();
    5959
    60             bool send(unsigned int clientId, const std::string & sender); //!< Sends the Notification to the Notificationmanager.
    61             bool sendHelper(const std::string& sender);
     60            bool send(const std::string & sender); //!< Sends the Notification to the Notificationmanager.
    6261
    6362            /**
  • code/trunk/src/modules/notifications/NotificationDispatcher.cc

    r7456 r7474  
    3535
    3636#include "core/CoreIncludes.h"
     37#include "core/EventIncludes.h"
    3738#include "core/XMLPort.h"
    38 #include "core/EventIncludes.h"
     39#include "network/NetworkFunction.h"
     40#include "network/Host.h"
     41
     42#include "infos/PlayerInfo.h"
     43#include "interfaces/PlayerTrigger.h"
     44#include "worldentities/pawns/Pawn.h"
     45
    3946#include "Notification.h"
    4047#include "NotificationManager.h"
    41 #include "interfaces/PlayerTrigger.h"
    42 #include "infos/PlayerInfo.h"
    43 #include "worldentities/pawns/Pawn.h"
    4448
    4549namespace orxonox
     
    4852    CreateUnloadableFactory(NotificationDispatcher);
    4953
     54    registerMemberNetworkFunction(NotificationDispatcher, dispatch);
     55
    5056    /**
    5157    @brief
    5258        Default constructor. Initializes the object.
    5359    */
    54     NotificationDispatcher::NotificationDispatcher(BaseObject* creator) : BaseObject(creator)
     60    NotificationDispatcher::NotificationDispatcher(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
    5561    {
    5662        RegisterObject(NotificationDispatcher);
    5763
    5864        this->sender_ = NotificationManager::NONE;
     65        this->registerVariables();
    5966    }
    6067
     
    8693    }
    8794
     95    void NotificationDispatcher::registerVariables(void)
     96    {
     97        registerVariable(this->sender_, VariableDirection::ToClient);
     98    }
     99
    88100    /**
    89101    @brief
     
    94106    void NotificationDispatcher::dispatch(unsigned int clientId)
    95107    {
    96         const std::string message = this->createNotificationMessage();
    97         Notification* notification = new Notification(this, message);
    98 
    99         notification->send(clientId, this->getSender());
     108        if(GameMode::isStandalone() || Host::getPlayerID() == clientId || this->getSyncMode() == 0x0)
     109        {
     110            const std::string message = this->createNotificationMessage();
     111            NotificationManager::sendNotification(message, clientId, this->getSender());
     112        }
     113        else if(GameMode::isServer())
     114        {
     115            callMemberNetworkFunction(NotificationDispatcher, dispatch, this->getObjectID(), clientId, clientId);
     116        }
    100117    }
    101118
     
    123140        if(pTrigger != NULL)
    124141        {
    125             if(!pTrigger->isForPlayer())  //!< The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
     142            if(!pTrigger->isForPlayer())  // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
    126143                return false;
    127144            else
     
    133150        if(pawn == NULL)
    134151        {
    135             COUT(4) << "The QuestEffectBeacon was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
     152            COUT(4) << "The NotificationDispatcher was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
    136153            return false;
    137154        }
    138155
    139         //! Extract the PlayerInfo from the Pawn.
     156        // Extract the PlayerInfo from the Pawn.
    140157        PlayerInfo* player = pawn->getPlayer();
    141158
  • code/trunk/src/modules/notifications/NotificationDispatcher.h

    r7456 r7474  
    4040#include <string>
    4141#include "core/BaseObject.h"
     42#include "network/synchronisable/Synchronisable.h"
    4243
    4344namespace orxonox
     
    5051        Damian 'Mozork' Frick
    5152    */
    52     class _NotificationsExport NotificationDispatcher : public BaseObject
     53    class _NotificationsExport NotificationDispatcher : public BaseObject, public Synchronisable
    5354    {
    5455        public:
     
    7273            std::string sender_; //!< The name of the sender of the Notification dispatched by this NotificationDispatcher.
    7374
     75           void registerVariables(void);
     76
    7477            /**
    7578            @brief Set the sender of the Notification dispatched by this NotificationDispatcher.
  • code/trunk/src/modules/notifications/NotificationManager.cc

    r7417 r7474  
    3838#include "core/GUIManager.h"
    3939#include "core/LuaState.h"
     40#include "network/Host.h"
     41#include "network/NetworkFunction.h"
    4042#include "util/ScopedSingletonManager.h"
    4143
     
    5961
    6062    SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode);
     63
     64    registerStaticNetworkFunction(NotificationManager::sendNotification);
    6165
    6266    /**
     
    100104        }
    101105        this->queues_.clear();
     106    }
     107
     108    /*static*/ void NotificationManager::sendNotification(const std::string& message, unsigned int clientId, const std::string& sender)
     109    {
     110        if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
     111        {
     112            Notification* notification = new Notification(message);
     113            notification->send(sender);
     114        }
     115        else if(GameMode::isServer())
     116        {
     117            callStaticNetworkFunction(NotificationManager::sendNotification, clientId, message, clientId, sender);
     118        }
    102119    }
    103120
  • code/trunk/src/modules/notifications/NotificationManager.h

    r7456 r7474  
    7070            static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener.
    7171
     72            static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE);
     73
    7274            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
    7375            void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener.
  • code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc

    r7456 r7474  
    5555
    5656        this->setSender("commandNotification");
     57        this->registerVariables();
    5758    }
    5859
     
    7778        XMLPortParam(CommandNotification, "preMessage", setPreMessage, getPreMessage, xmlelement, mode);
    7879        XMLPortParam(CommandNotification, "postMessage", setPostMessage, getPostMessage, xmlelement, mode);
     80    }
     81
     82    void CommandNotification::registerVariables(void)
     83    {
     84        registerVariable(this->command_, VariableDirection::ToClient);
     85        registerVariable(this->preMessage_, VariableDirection::ToClient);
     86        registerVariable(this->postMessage_, VariableDirection::ToClient);
    7987    }
    8088
  • code/trunk/src/modules/notifications/dispatchers/CommandNotification.h

    r7456 r7474  
    3838#include "notifications/NotificationsPrereqs.h"
    3939
     40#include <string>
    4041#include "notifications/NotificationDispatcher.h"
    41 #include <string>
    4242
    4343namespace orxonox {
     
    8686            std::string postMessage_; //!< The last part of the displayed message.
    8787
     88            void registerVariables(void);
     89
    8890            /**
    8991            @brief Set the command, whose key is displayed.
  • code/trunk/src/modules/notifications/dispatchers/SimpleNotification.cc

    r7456 r7474  
    5050
    5151        this->setSender("simpleNotification");
     52
     53        this->setSyncMode(0x0);
    5254    }
    5355
Note: See TracChangeset for help on using the changeset viewer.