Changeset 11003
- Timestamp:
- Dec 30, 2015, 9:24:39 PM (9 years ago)
- Location:
- code/branches/cpp11_v2/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/src/modules/notifications/NotificationDispatcher.cc
r10765 r11003 113 113 // TODO: Needed? 114 114 const std::string message = this->createNotificationMessage(); 115 NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::local);115 NotificationListener::sendNotification(message, this->getSender(), NotificationMessageType::info, NotificationSendMode::local); 116 116 117 117 // Broadcast … … 144 144 const std::string message = this->createNotificationMessage(); 145 145 // TODO: Make the type configurable. 146 NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::network, clientId);146 NotificationListener::sendNotification(message, this->getSender(), NotificationMessageType::info, NotificationSendMode::network, clientId); 147 147 } 148 148 else if(GameMode::isServer()) -
code/branches/cpp11_v2/src/modules/notifications/NotificationManager.cc
r10917 r11003 106 106 Returns true if successful. 107 107 */ 108 bool NotificationManager::registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)108 bool NotificationManager::registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type) 109 109 { 110 110 // TODO: Do something with the type. … … 124 124 Returns true if the command was successfully executed. 125 125 */ 126 bool NotificationManager::executeCommand( notificationCommand::Valuecommand, const std::string& sender)126 bool NotificationManager::executeCommand(NotificationCommand command, const std::string& sender) 127 127 { 128 128 bool commandExecuted = false; 129 if(command == notificationCommand::clear)129 if(command == NotificationCommand::clear) 130 130 { 131 131 if(this->commandClear(sender)) … … 437 437 438 438 */ 439 Notification::Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type)439 Notification::Notification(const std::string& message, const std::string& sender, NotificationMessageType type) 440 440 { 441 441 this->initialize(); -
code/branches/cpp11_v2/src/modules/notifications/NotificationManager.h
r10817 r11003 62 62 { 63 63 public: 64 Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type);64 Notification(const std::string& message, const std::string& sender, NotificationMessageType type); 65 65 virtual ~Notification(); 66 66 … … 89 89 @return Returns an enum with the type of the Notification. 90 90 */ 91 inline notificationMessageType::Value getType(void) const91 inline NotificationMessageType getType(void) const 92 92 { return this->type_; } 93 93 … … 95 95 std::string message_; //!< The Notification message. 96 96 std::string sender_; //!< The sender of the notification. 97 notificationMessageType::Value type_; //!< The type of the notification.97 NotificationMessageType type_; //!< The type of the notification. 98 98 99 99 void initialize(void); //!< Registers the object and sets some default values. … … 128 128 static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export 129 129 130 virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type) override;131 virtual bool executeCommand( notificationCommand::Valuecommand, const std::string& sender) override;130 virtual bool registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type) override; 131 virtual bool executeCommand(NotificationCommand command, const std::string& sender) override; 132 132 133 133 bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager. -
code/branches/cpp11_v2/src/modules/questsystem/QuestDescription.cc
r9667 r11003 119 119 } 120 120 121 NotificationListener::sendNotification(message, QuestDescription::SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());121 NotificationListener::sendNotification(message, QuestDescription::SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID()); 122 122 return true; 123 123 } -
code/branches/cpp11_v2/src/orxonox/infos/GametypeInfo.cc
r10919 r11003 291 291 if(GameMode::isMaster()) 292 292 { 293 NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());293 NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID()); 294 294 // Remove the player from the list of players that have spawned, since it currently is not. 295 295 this->spawnedPlayers_.erase(player); … … 346 346 // Display "Press [Fire] to start the match" if the game has not yet ended. 347 347 if(!this->hasEnded()) 348 NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());348 NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID()); 349 349 // Else display "Game has ended". 350 350 else 351 NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());351 NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID()); 352 352 } 353 353 } -
code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.cc
r10919 r11003 74 74 The type of the notification, can be either 'info' or 'important'. 75 75 */ 76 /*static*/ void NotificationListener::sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand, notificationMessageType::Value messageType)76 /*static*/ void NotificationListener::sendNetworkHelper(const std::string& message, const std::string& sender, NotificationSendMode sendMode, unsigned int clientId, bool isCommand, NotificationMessageType messageType) 77 77 { 78 78 // If we're in standalone mode or we're already no the right client we create and send the notification/command. 79 if(GameMode::isStandalone() || sendMode == notificationSendMode::local || (sendMode == notificationSendMode::network && Host::getPlayerID() == clientId))79 if(GameMode::isStandalone() || sendMode == NotificationSendMode::local || (sendMode == NotificationSendMode::network && Host::getPlayerID() == clientId)) 80 80 { 81 81 sendHelper(message, sender, isCommand, messageType); 82 82 } 83 83 // If we're on the server (and the server is not the intended recipient of the notification/command) we send it over the network. 84 else if(GameMode::isServer() && sendMode == notificationSendMode::network && Host::getPlayerID() != clientId)84 else if(GameMode::isServer() && sendMode == NotificationSendMode::network && Host::getPlayerID() != clientId) 85 85 { 86 callStaticNetworkFunction(&NotificationListener::sendHelper, clientId, message, sender, isCommand, (unsigned int)messageType);86 callStaticNetworkFunction(&NotificationListener::sendHelper, clientId, message, sender, isCommand, messageType); 87 87 } 88 else if(GameMode::isServer() && sendMode == notificationSendMode::broadcast)88 else if(GameMode::isServer() && sendMode == NotificationSendMode::broadcast) 89 89 { 90 90 // TODO: Works as intended? 91 callStaticNetworkFunction(&NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, isCommand, (unsigned int)messageType);91 callStaticNetworkFunction(&NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, isCommand, messageType); 92 92 } 93 93 } … … 105 105 The type of the notification. 106 106 */ 107 /*static*/ void NotificationListener::sendHelper(const std::string& message, const std::string& sender, bool isCommand, unsigned int messageType)107 /*static*/ void NotificationListener::sendHelper(const std::string& message, const std::string& sender, bool isCommand, NotificationMessageType type) 108 108 { 109 109 // Iterate through all NotificationListeners and notify them by calling the method they overloaded. … … 112 112 // If the notification is a message. 113 113 if(!isCommand) 114 listener->registerNotification(message, sender, notificationMessageType::Value(messageType));114 listener->registerNotification(message, sender, type); 115 115 116 116 // If the notification is a command. 117 117 if(isCommand) 118 118 { 119 notificationCommand::Valuecommand = str2Command(message);120 if(command != notificationCommand::none)119 NotificationCommand command = str2Command(message); 120 if(command != NotificationCommand::none) 121 121 listener->executeCommand(command, sender); 122 122 } … … 130 130 The string to be converted. 131 131 @return 132 Returns the corresponding enum, notificationCommand::none if the command doesn't exist.132 Returns the corresponding enum, NotificationCommand::none if the command doesn't exist. 133 133 */ 134 /*static*/ notificationCommand::ValueNotificationListener::str2Command(const std::string& string)134 /*static*/ NotificationCommand NotificationListener::str2Command(const std::string& string) 135 135 { 136 notificationCommand::Value command = notificationCommand::none;136 NotificationCommand command = NotificationCommand::none; 137 137 138 138 if(string == NotificationListener::COMMAND_CLEAR) 139 command = notificationCommand::clear;139 command = NotificationCommand::clear; 140 140 141 141 return command; … … 150 150 Returns the corresponding string. 151 151 */ 152 /*static*/ const std::string& NotificationListener::command2Str( notificationCommand::Valuecommand)152 /*static*/ const std::string& NotificationListener::command2Str(NotificationCommand command) 153 153 { 154 154 switch(command) 155 155 { 156 case notificationCommand::clear:156 case NotificationCommand::clear: 157 157 return NotificationListener::COMMAND_CLEAR; 158 158 default: -
code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.h
r9667 r11003 49 49 { 50 50 // TODO: Document. 51 namespace notificationMessageType 52 { 53 enum Value { 54 info, 55 important 56 }; 57 } 51 enum class NotificationMessageType { 52 info, 53 important 54 }; 58 55 59 namespace notificationSendMode 60 { 61 enum Value { 62 local, 63 network, 64 broadcast 65 }; 66 } 56 enum class NotificationSendMode { 57 local, 58 network, 59 broadcast 60 }; 67 61 68 namespace notificationCommand 69 { 70 enum Value { 71 none, 72 clear 73 }; 74 } 62 enum class NotificationCommand { 63 none, 64 clear 65 }; 75 66 76 67 // TODO: Update doc. … … 101 92 @param sender The sender that sent the notification. Default is 'none'. 102 93 @param messageType The type of the message, can be either 'info' or 'important'. Default is 'info'. 103 @param sendMode The mode in which the notification is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts. Default is notificationSendMode::local.94 @param sendMode The mode in which the notification is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts. Default is NotificationSendMode::local. 104 95 @param clientId The id of the client the notification should be sent to. Default is 0. 105 96 */ 106 static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, notificationMessageType::Value messageType = notificationMessageType::info, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)97 static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, NotificationMessageType messageType = NotificationMessageType::info, NotificationSendMode sendMode = NotificationSendMode::local, unsigned int clientId = 0) 107 98 { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); } 108 99 /** … … 110 101 @param command The command that should be sent (and later executed). 111 102 @param sender The sender that sent the notification. Default is 'none'. 112 @param sendMode The mode in which the command is sent, can be 'local' to send the command to the client where this function is executed, 'network' if the command is to be sent to the client with the specified clientID, or 'broadcast' if the command should be sent to all hosts. Default is notificationSendMode::local.103 @param sendMode The mode in which the command is sent, can be 'local' to send the command to the client where this function is executed, 'network' if the command is to be sent to the client with the specified clientID, or 'broadcast' if the command should be sent to all hosts. Default is NotificationSendMode::local. 113 104 @param clientId The id of the client the command should be sent to. Default is 0. 114 105 */ 115 static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)106 static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, NotificationSendMode sendMode = NotificationSendMode::local, unsigned int clientId = 0) 116 107 { NotificationListener::sendNetworkHelper(command, sender, sendMode, clientId, true); } 117 108 118 static void sendHelper(const std::string& message, const std::string& sender, bool isCommand = false, unsigned int messageMode = 0); // Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network.109 static void sendHelper(const std::string& message, const std::string& sender, bool isCommand, NotificationMessageType type); // Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network. 119 110 120 111 //TODO: Make protected? … … 128 119 @return Returns true if the notification was successfully registered, false if not. 129 120 */ 130 virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)121 virtual bool registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type) 131 122 { return false; } 132 123 /** … … 137 128 @return Returns true if the command was successfully executed, false if not. 138 129 */ 139 virtual bool executeCommand( notificationCommand::Valuecommand, const std::string& sender) { return false; }130 virtual bool executeCommand(NotificationCommand command, const std::string& sender) { return false; } 140 131 141 132 public: … … 149 140 150 141 protected: 151 static void sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand = false, notificationMessageType::Value messageType = notificationMessageType::info); // Helper method to send both notifications and commands over the network.142 static void sendNetworkHelper(const std::string& message, const std::string& sender, NotificationSendMode sendMode, unsigned int clientId, bool isCommand = false, NotificationMessageType messageType = NotificationMessageType::info); // Helper method to send both notifications and commands over the network. 152 143 153 static notificationCommand::Valuestr2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.154 static const std::string& command2Str( notificationCommand::Valuecommand); // Helper method. Converts a command enum into its corresponding string.144 static NotificationCommand str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command. 145 static const std::string& command2Str(NotificationCommand command); // Helper method. Converts a command enum into its corresponding string. 155 146 }; 156 147 }
Note: See TracChangeset
for help on using the changeset viewer.