Changeset 8821
- Timestamp:
- Aug 4, 2011, 12:09:03 AM (13 years ago)
- Location:
- code/branches/ai2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai2/data/levels/missionOne.oxw
r8800 r8821 105 105 </SimpleNotification> 106 106 107 <SimpleNotification message="Right click on the next target." >107 <SimpleNotification message="Right click on the next target." meh="true"> 108 108 <events> 109 109 <trigger> … … 116 116 <!-- BRIEFING END--> 117 117 <!-- TODO: does NOT work. Intended effect: pawn death causes message to appear (and probably the next box) --> 118 <SimpleNotification message="Right click on the next target." >118 <SimpleNotification message="Right click on the next target." meh="true"> 119 119 <events> 120 120 <trigger> -
code/branches/ai2/src/modules/notifications/NotificationDispatcher.cc
r8706 r8821 50 50 CreateUnloadableFactory(NotificationDispatcher); 51 51 52 registerMemberNetworkFunction(NotificationDispatcher, broadcastHelper); 52 53 registerMemberNetworkFunction(NotificationDispatcher, dispatch); 53 54 … … 61 62 62 63 this->sender_ = NotificationListener::NONE; 64 this->bBroadcast_ = false; 63 65 this->registerVariables(); 64 66 } … … 81 83 SUPER(NotificationDispatcher, XMLPort, xmlelement, mode); 82 84 83 XMLPortParam(NotificationDispatcher, "sender", getSender, setSender, xmlelement, mode); 84 85 XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers. 85 XMLPortParam(NotificationDispatcher, "sender", setSender, getSender, xmlelement, mode); 86 XMLPortParam(NotificationDispatcher, "meh", setBroadcasting, isBroadcasting, xmlelement, mode); 87 88 XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode); 86 89 } 87 90 … … 100 103 { 101 104 registerVariable(this->sender_, VariableDirection::ToClient); 105 } 106 107 /** 108 @brief 109 Broadcasts a specific Notification. 110 */ 111 void NotificationDispatcher::broadcast(void) 112 { 113 COUT(0) << "meh" << endl; 114 // TODO: Needed? 115 const std::string message = this->createNotificationMessage(); 116 NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::local); 117 118 // Broadcast 119 if(!GameMode::isStandalone()) 120 { 121 callMemberNetworkFunction(NotificationDispatcher, broadcastHelper, this->getObjectID(), NETWORK_PEER_ID_BROADCAST); 122 } 123 } 124 125 /** 126 @brief 127 Helper function for broadcast. 128 */ 129 void NotificationDispatcher::broadcastHelper(void) 130 { 131 this->dispatch(Host::getPlayerID()); 102 132 } 103 133 … … 110 140 void NotificationDispatcher::dispatch(unsigned int clientId) 111 141 { 112 if(GameMode::isStandalone() || Host::getPlayerID() == clientId || this->getSyncMode() == 0x0) 142 // 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. 143 if(GameMode::isStandalone() || Host::getPlayerID() == clientId || this->getSyncMode() == ObjectDirection::None) 113 144 { 114 145 const std::string message = this->createNotificationMessage(); … … 139 170 COUT(4) << "NotificationDispatcher (&" << this << ") triggered." << std::endl; 140 171 172 // If the NotificationDispatcher is set to broadcast. 173 if(this->isBroadcasting()) 174 { 175 this->broadcast(); 176 return true; 177 } 178 141 179 PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger); 142 180 PlayerInfo* player = NULL; -
code/branches/ai2/src/modules/notifications/NotificationDispatcher.h
r7552 r8821 50 50 A NotificationDispatcher is an entity that, upon being triggered, dispatches (or sends) a specified @ref orxonox::Notification "Notification". 51 51 52 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 There ate two parameter to be set: 53 - 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. 54 - The @b broadcast . Specifies whether messages are broadcast (i.e. sent to all clients) or just sent to a specific player. 53 55 54 56 Its standard usage is: … … 62 64 </NotificationDispatcher> 63 65 @endcode 64 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". 66 But keep in mind, that NotificationDispatcher is an abstract class. 67 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". 68 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. 65 69 66 70 @author … … 84 88 const std::string& getSender(void) const 85 89 { return this->sender_; } 86 90 /** 87 91 @brief Set the sender of the Notification dispatched by this NotificationDispatcher. 88 92 @param sender The name of the sender. … … 91 95 { this->sender_ = sender; } 92 96 93 void dispatch(unsigned int clientId); //!< Dispatches a specific Notification. 97 /** 98 @brief Check whether the NotificationDispatcher is set to broadcast. 99 @return Returns true if the NotificationDispatcher is set to broadcast. 100 */ 101 bool isBroadcasting(void) const 102 { return this->bBroadcast_; } 103 /** 104 @brief Set the NotificationDispatcher to broadcast. 105 @param broadcast Whether the NotificationDispatcher is set to broadcast or singlecast. 106 */ 107 void setBroadcasting(bool v) 108 { this->bBroadcast_ = v; } 109 110 void broadcast(void); //!< Broadcasts a specific Notification. 111 void broadcastHelper(void); //!< Helper function for broadcast. 112 void dispatch(unsigned int clientId); //!< Dispatches a specific Notification to a given client. 94 113 bool trigger(bool triggered, BaseObject* trigger); //!< Is called when the NotificationDispatcher is triggered. 95 114 96 115 protected: 97 116 std::string sender_; //!< The name of the sender of the Notification dispatched by this NotificationDispatcher. 117 bool bBroadcast_; //!< Whether the NotificationDispatcher is broadcasting. 98 118 99 119 void registerVariables(void); //!< Register some variables for synchronisation. … … 105 125 */ 106 126 virtual const std::string& createNotificationMessage(void) 107 { return *(new std::string("")); }127 { return BLANKSTRING; } 108 128 109 129 };
Note: See TracChangeset
for help on using the changeset viewer.