Changeset 7474 for code/trunk/src/modules/notifications
- Timestamp:
- Sep 21, 2010, 11:15:44 PM (14 years ago)
- Location:
- code/trunk/src/modules/notifications
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/notifications/Notification.cc
r7463 r7474 42 42 { 43 43 44 CreateUnloadableFactory(Notification);45 46 registerMemberNetworkFunction(Notification, send);47 48 44 /** 49 45 @brief 50 46 Default constructor. Initializes the object. 51 @param creator52 The object that created this Notification53 47 */ 54 Notification::Notification( BaseObject* creator) : BaseObject(creator), Synchronisable(creator)48 Notification::Notification() 55 49 { 56 Register Object(Notification);50 RegisterRootObject(Notification); 57 51 this->initialize(); 58 52 this->registerVariables(); … … 67 61 The message of the Notification. 68 62 */ 69 Notification::Notification( BaseObject* creator, const std::string & message) : BaseObject(creator), Synchronisable(creator)63 Notification::Notification(const std::string & message) 70 64 { 71 Register Object(Notification);65 RegisterRootObject(Notification); 72 66 this->initialize(); 73 67 this->message_ = message; 74 this->registerVariables();75 68 } 76 69 … … 95 88 } 96 89 97 void Notification::registerVariables(void)98 {99 registerVariable(this->message_);100 registerVariable(this->sender_);101 registerVariable(this->sent_);102 }103 104 90 /** 105 91 @brief 106 92 Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues. 107 @param clientId108 The id of the client that this Notification is sent to.109 93 @param sender 110 94 The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues. … … 112 96 Returns true if successful. 113 97 */ 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) 130 99 { 131 100 if(this->isSent()) //TODO: Needed? -
code/trunk/src/modules/notifications/Notification.h
r7456 r7474 51 51 Damian 'Mozork' Frick 52 52 */ 53 class _NotificationsExport Notification : public BaseObject, public Synchronisable53 class _NotificationsExport Notification : public OrxonoxClass 54 54 { 55 55 public: 56 Notification( BaseObject* creator);57 Notification( BaseObject* creator,const std::string & message);56 Notification(); 57 Notification(const std::string & message); 58 58 virtual ~Notification(); 59 59 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. 62 61 63 62 /** -
code/trunk/src/modules/notifications/NotificationDispatcher.cc
r7456 r7474 35 35 36 36 #include "core/CoreIncludes.h" 37 #include "core/EventIncludes.h" 37 38 #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 39 46 #include "Notification.h" 40 47 #include "NotificationManager.h" 41 #include "interfaces/PlayerTrigger.h"42 #include "infos/PlayerInfo.h"43 #include "worldentities/pawns/Pawn.h"44 48 45 49 namespace orxonox … … 48 52 CreateUnloadableFactory(NotificationDispatcher); 49 53 54 registerMemberNetworkFunction(NotificationDispatcher, dispatch); 55 50 56 /** 51 57 @brief 52 58 Default constructor. Initializes the object. 53 59 */ 54 NotificationDispatcher::NotificationDispatcher(BaseObject* creator) : BaseObject(creator) 60 NotificationDispatcher::NotificationDispatcher(BaseObject* creator) : BaseObject(creator), Synchronisable(creator) 55 61 { 56 62 RegisterObject(NotificationDispatcher); 57 63 58 64 this->sender_ = NotificationManager::NONE; 65 this->registerVariables(); 59 66 } 60 67 … … 86 93 } 87 94 95 void NotificationDispatcher::registerVariables(void) 96 { 97 registerVariable(this->sender_, VariableDirection::ToClient); 98 } 99 88 100 /** 89 101 @brief … … 94 106 void NotificationDispatcher::dispatch(unsigned int clientId) 95 107 { 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 } 100 117 } 101 118 … … 123 140 if(pTrigger != NULL) 124 141 { 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. 126 143 return false; 127 144 else … … 133 150 if(pawn == NULL) 134 151 { 135 COUT(4) << "The QuestEffectBeaconwas 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; 136 153 return false; 137 154 } 138 155 139 // !Extract the PlayerInfo from the Pawn.156 // Extract the PlayerInfo from the Pawn. 140 157 PlayerInfo* player = pawn->getPlayer(); 141 158 -
code/trunk/src/modules/notifications/NotificationDispatcher.h
r7456 r7474 40 40 #include <string> 41 41 #include "core/BaseObject.h" 42 #include "network/synchronisable/Synchronisable.h" 42 43 43 44 namespace orxonox … … 50 51 Damian 'Mozork' Frick 51 52 */ 52 class _NotificationsExport NotificationDispatcher : public BaseObject 53 class _NotificationsExport NotificationDispatcher : public BaseObject, public Synchronisable 53 54 { 54 55 public: … … 72 73 std::string sender_; //!< The name of the sender of the Notification dispatched by this NotificationDispatcher. 73 74 75 void registerVariables(void); 76 74 77 /** 75 78 @brief Set the sender of the Notification dispatched by this NotificationDispatcher. -
code/trunk/src/modules/notifications/NotificationManager.cc
r7417 r7474 38 38 #include "core/GUIManager.h" 39 39 #include "core/LuaState.h" 40 #include "network/Host.h" 41 #include "network/NetworkFunction.h" 40 42 #include "util/ScopedSingletonManager.h" 41 43 … … 59 61 60 62 SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode); 63 64 registerStaticNetworkFunction(NotificationManager::sendNotification); 61 65 62 66 /** … … 100 104 } 101 105 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 } 102 119 } 103 120 -
code/trunk/src/modules/notifications/NotificationManager.h
r7456 r7474 70 70 static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener. 71 71 72 static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE); 73 72 74 bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. 73 75 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 55 55 56 56 this->setSender("commandNotification"); 57 this->registerVariables(); 57 58 } 58 59 … … 77 78 XMLPortParam(CommandNotification, "preMessage", setPreMessage, getPreMessage, xmlelement, mode); 78 79 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); 79 87 } 80 88 -
code/trunk/src/modules/notifications/dispatchers/CommandNotification.h
r7456 r7474 38 38 #include "notifications/NotificationsPrereqs.h" 39 39 40 #include <string> 40 41 #include "notifications/NotificationDispatcher.h" 41 #include <string>42 42 43 43 namespace orxonox { … … 86 86 std::string postMessage_; //!< The last part of the displayed message. 87 87 88 void registerVariables(void); 89 88 90 /** 89 91 @brief Set the command, whose key is displayed. -
code/trunk/src/modules/notifications/dispatchers/SimpleNotification.cc
r7456 r7474 50 50 51 51 this->setSender("simpleNotification"); 52 53 this->setSyncMode(0x0); 52 54 } 53 55
Note: See TracChangeset
for help on using the changeset viewer.