[Orxonox-commit 4150] r8821 - in code/branches/ai2: data/levels src/modules/notifications

dafrick at orxonox.net dafrick at orxonox.net
Thu Aug 4 00:09:03 CEST 2011


Author: dafrick
Date: 2011-08-04 00:09:03 +0200 (Thu, 04 Aug 2011)
New Revision: 8821

Modified:
   code/branches/ai2/data/levels/missionOne.oxw
   code/branches/ai2/src/modules/notifications/NotificationDispatcher.cc
   code/branches/ai2/src/modules/notifications/NotificationDispatcher.h
Log:
Adding broadcast functionality to NotificationDispatcher.


Modified: code/branches/ai2/data/levels/missionOne.oxw
===================================================================
--- code/branches/ai2/data/levels/missionOne.oxw	2011-08-03 21:28:06 UTC (rev 8820)
+++ code/branches/ai2/data/levels/missionOne.oxw	2011-08-03 22:09:03 UTC (rev 8821)
@@ -104,7 +104,7 @@
         </events>
     </SimpleNotification>
 
-    <SimpleNotification message="Right click on the next target.">
+    <SimpleNotification message="Right click on the next target." meh="true">
         <events>
             <trigger>
                 <EventListener event=PawnDied1 />
@@ -115,7 +115,7 @@
 
 <!-- BRIEFING END--> 
 <!-- TODO: does NOT work. Intended effect: pawn death causes message to appear (and probably the next box) -->
-  <SimpleNotification message="Right click on the next target.">
+  <SimpleNotification message="Right click on the next target." meh="true">
         <events>
             <trigger>
                 <Pawn health=30 position="0,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>

Modified: code/branches/ai2/src/modules/notifications/NotificationDispatcher.cc
===================================================================
--- code/branches/ai2/src/modules/notifications/NotificationDispatcher.cc	2011-08-03 21:28:06 UTC (rev 8820)
+++ code/branches/ai2/src/modules/notifications/NotificationDispatcher.cc	2011-08-03 22:09:03 UTC (rev 8821)
@@ -49,6 +49,7 @@
 
     CreateUnloadableFactory(NotificationDispatcher);
 
+    registerMemberNetworkFunction(NotificationDispatcher, broadcastHelper);
     registerMemberNetworkFunction(NotificationDispatcher, dispatch);
 
     /**
@@ -60,6 +61,7 @@
         RegisterObject(NotificationDispatcher);
 
         this->sender_ = NotificationListener::NONE;
+        this->bBroadcast_ = false;
         this->registerVariables();
     }
 
@@ -80,9 +82,10 @@
     {
         SUPER(NotificationDispatcher, XMLPort, xmlelement, mode);
 
-        XMLPortParam(NotificationDispatcher, "sender", getSender, setSender, xmlelement, mode);
-        
-        XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
+        XMLPortParam(NotificationDispatcher, "sender", setSender, getSender, xmlelement, mode);
+        XMLPortParam(NotificationDispatcher, "meh", setBroadcasting, isBroadcasting, xmlelement, mode);
+
+        XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode);
     }
 
     void NotificationDispatcher::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
@@ -103,13 +106,41 @@
 
     /**
     @brief
+        Broadcasts a specific Notification.
+    */
+    void NotificationDispatcher::broadcast(void)
+    {
+        COUT(0) << "meh" << endl;
+        // TODO: Needed?
+        const std::string message = this->createNotificationMessage();
+        NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::local);
+
+        // Broadcast
+        if(!GameMode::isStandalone())
+        {
+            callMemberNetworkFunction(NotificationDispatcher, broadcastHelper, this->getObjectID(), NETWORK_PEER_ID_BROADCAST);
+        }
+    }
+
+    /**
+    @brief
+        Helper function for broadcast.
+    */
+    void NotificationDispatcher::broadcastHelper(void)
+    {
+        this->dispatch(Host::getPlayerID());
+    }
+
+    /**
+    @brief
         Dispatches a Notification with a message supplied by the createNotificationMessage() method, which can be overloaded.
     @param clientId
         The id of the client the notification should be dispatched to.
     */
     void NotificationDispatcher::dispatch(unsigned int clientId)
     {
-        if(GameMode::isStandalone() || Host::getPlayerID() == clientId || this->getSyncMode() == 0x0)
+        // We don't call sendNotification() directly on the server, because if might be necessary that createNotificationMessage() is executed on the client as the message may be client-specific.
+        if(GameMode::isStandalone() || Host::getPlayerID() == clientId || this->getSyncMode() == ObjectDirection::None)
         {
             const std::string message = this->createNotificationMessage();
             // TODO: Make the type configurable.
@@ -138,6 +169,13 @@
 
         COUT(4) << "NotificationDispatcher (&" << this << ") triggered." << std::endl;
 
+        // If the NotificationDispatcher is set to broadcast.
+        if(this->isBroadcasting())
+        {
+            this->broadcast();
+            return true;
+        }
+
         PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
         PlayerInfo* player = NULL;
 

Modified: code/branches/ai2/src/modules/notifications/NotificationDispatcher.h
===================================================================
--- code/branches/ai2/src/modules/notifications/NotificationDispatcher.h	2011-08-03 21:28:06 UTC (rev 8820)
+++ code/branches/ai2/src/modules/notifications/NotificationDispatcher.h	2011-08-03 22:09:03 UTC (rev 8821)
@@ -49,7 +49,9 @@
     @brief
         A NotificationDispatcher is an entity that, upon being triggered, dispatches (or sends) a specified @ref orxonox::Notification "Notification".
 
-        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.
+        There ate two 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.
+        - The @b broadcast . Specifies whether messages are broadcast (i.e. sent to all clients) or just sent to a specific player.
 
         Its standard usage is:
         @code
@@ -61,7 +63,9 @@
             </event>
         </NotificationDispatcher>
         @endcode
-        But keep in mind, that NotificationDispatcher is an abstract class and in this example @ref orxonox::PlayerTrigger "PlayerTrigger" stands for any event that is caused by a @ref orxonox::PlayerTrigger "PlayerTrigger", so instead of @ref orxonox::PlayerTrigger "PlayerTrigger", there could be a @ref orxonox::DistanceTrigger "DistanceTrigger", or a @ref orxonox::DistanceMultiTrigger "DistanceMutliTrigger", or even an @ref orxonox::EventListener "EventListener" that waits for an event coming from any kind of @ref orxonox::PlayerTrigger "PlayerTrigger".
+        But keep in mind, that NotificationDispatcher is an abstract class.
+        Also in this example @ref orxonox::PlayerTrigger "PlayerTrigger" stands for any event that is caused by a @ref orxonox::PlayerTrigger "PlayerTrigger", so instead of @ref orxonox::PlayerTrigger "PlayerTrigger", there could be a @ref orxonox::DistanceTrigger "DistanceTrigger", or a @ref orxonox::DistanceMultiTrigger "DistanceMutliTrigger", or even an @ref orxonox::EventListener "EventListener" that waits for an event coming from any kind of @ref orxonox::PlayerTrigger "PlayerTrigger".
+        If the NotificationDispatcher is not set to broadcast only events caused by @ref orxonox::PlayerTrigger "PlayerTriggers" trigger a message since the information obtained by the @ref orxonox::PlayerTrigger "PlayerTrigger" is used to identify the client to which the message should be sent.
 
     @author
         Damian 'Mozork' Frick
@@ -83,18 +87,34 @@
             */
             const std::string& getSender(void) const
                 { return this->sender_; }
-                        /**
+            /**
             @brief Set the sender of the Notification dispatched by this NotificationDispatcher.
             @param sender The name of the sender.
             */
             void setSender(const std::string& sender)
                 { this->sender_ = sender; }
 
-            void dispatch(unsigned int clientId); //!< Dispatches a specific Notification.
+            /**
+            @brief Check whether the NotificationDispatcher is set to broadcast.
+            @return Returns true if the NotificationDispatcher is set to broadcast.
+            */
+            bool isBroadcasting(void) const
+                { return this->bBroadcast_; }
+            /**
+            @brief Set the NotificationDispatcher to broadcast.
+            @param broadcast Whether the NotificationDispatcher is set to broadcast or singlecast.
+            */
+            void setBroadcasting(bool v)
+                { this->bBroadcast_ = v; }
+
+            void broadcast(void); //!< Broadcasts a specific Notification.
+            void broadcastHelper(void); //!< Helper function for broadcast.
+            void dispatch(unsigned int clientId); //!< Dispatches a specific Notification to a given client.
             bool trigger(bool triggered, BaseObject* trigger); //!< Is called when the NotificationDispatcher is triggered.
 
         protected:
             std::string sender_; //!< The name of the sender of the Notification dispatched by this NotificationDispatcher.
+            bool bBroadcast_; //!< Whether the NotificationDispatcher is broadcasting.
 
             void registerVariables(void); //!< Register some variables for synchronisation.
 
@@ -104,7 +124,7 @@
             @return Returns the notification message.
             */
             virtual const std::string& createNotificationMessage(void)
-                { return *(new std::string("")); }
+                { return BLANKSTRING; }
 
     };
 




More information about the Orxonox-commit mailing list