Changeset 7474 for code/trunk/src/modules
- Timestamp:
- Sep 21, 2010, 11:15:44 PM (14 years ago)
- Location:
- code/trunk/src/modules
- Files:
-
- 2 deleted
- 15 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 -
code/trunk/src/modules/objects/Script.cc
r7463 r7474 35 35 #include "core/LuaState.h" 36 36 #include "core/XMLPort.h" 37 #include "network/Host.h" 38 #include "network/NetworkFunction.h" 39 40 #include "PlayerManager.h" 41 #include "infos/PlayerInfo.h" 42 #include "interfaces/PlayerTrigger.h" 43 #include "worldentities/pawns/Pawn.h" 37 44 38 45 namespace orxonox 39 46 { 40 47 CreateFactory(Script); 48 49 registerMemberNetworkFunction(Script, execute); 41 50 42 51 // Initializing constants. … … 51 60 The creator of this object. 52 61 */ 53 Script::Script(BaseObject* creator) : BaseObject(creator) 62 Script::Script(BaseObject* creator) : BaseObject(creator), Synchronisable(creator) 54 63 { 55 64 RegisterObject(Script); … … 63 72 this->needsGraphics_ = false; 64 73 74 this->counter_ = 0.0f; 75 76 this->registerVariables(); 65 77 } 66 78 … … 92 104 XMLPortParam(Script, "times", setTimes, getTimes, xmlelement, mode).defaultValues(Script::INF); 93 105 XMLPortParam(Script, "needsGraphics", setNeedsGraphics, getNeedsGraphics, xmlelement, mode).defaultValues(false); 106 XMLPortParam(Script, "forAll", setForAll, isForAll, xmlelement, mode).defaultValues(false); 94 107 95 108 XMLPortEventSink(Script, BaseObject, "trigger", trigger, xmlelement, mode); 96 109 97 if(this->isOnLoad()) // If the object is onLoad the code is executed at once .98 this->execute( );110 if(this->isOnLoad()) // If the object is onLoad the code is executed at once for all clients. 111 this->execute(0); 99 112 } 100 113 … … 116 129 /** 117 130 @brief 131 Register the variables that need to be synchronized. 132 */ 133 void Script::registerVariables(void) 134 { 135 registerVariable(code_, VariableDirection::ToClient); 136 registerVariable(needsGraphics_, VariableDirection::ToClient); 137 registerVariable(modeStr_, VariableDirection::ToClient, new NetworkCallback<Script>(this, &Script::modeChanged)); 138 } 139 140 void Script::modeChanged(void) 141 { 142 this->setMode(this->modeStr_); 143 } 144 145 void Script::tick(float dt) 146 { 147 SUPER(Script, tick, dt); 148 149 if(!this->clientCallbacks_.empty()) 150 { 151 if(this->counter_ < 2.0f) 152 { 153 this->counter_ += dt; 154 } 155 else 156 { 157 for(std::vector<unsigned int>::iterator it = this->clientCallbacks_.begin(); it != this->clientCallbacks_.end(); it++) 158 { 159 this->execute(*it, true); 160 } 161 this->clientCallbacks_.clear(); 162 this->counter_ = 0.0f; 163 } 164 } 165 } 166 167 /** 168 @brief 118 169 Is called when an event comes in trough the event port. 119 170 @param triggered 120 171 Whether the event is triggering or un-triggering. 121 */ 122 void Script::trigger(bool triggered) 123 { 124 if(triggered) // If the event is triggering (instead of un-triggering) the code of this Script is executed. 125 this->execute(); 126 } 127 128 /** 129 @brief 130 Executes the Scripts code, depending on the mode. 131 */ 132 void Script::execute() 133 { 134 if(this->times_ != Script::INF && this->remainingExecutions_ == 0) 135 return; 136 137 // If the code needs graphics to be executed but the GameMode doesn't show graphics the code isn't executed. 138 if(this->needsGraphics_ && !GameMode::showsGraphics()) 139 return; 140 141 if(this->mode_ == ScriptMode::normal) // If the mode is 'normal'. 142 CommandExecutor::execute(this->code_); 143 else if(this->mode_ == ScriptMode::lua) // If it's 'lua'. 144 { 145 assert(this->luaState_); 146 this->luaState_->doString(this->code_); 147 } 148 149 if(this->times_ != Script::INF) 150 this->remainingExecutions_--; 172 @param trigger 173 The object that caused the event to be fired. 174 @return 175 Returns true if successful. 176 */ 177 bool Script::trigger(bool triggered, BaseObject* trigger) 178 { 179 if(!triggered || !this->isActive()) // If the Script is inactive it cannot be executed. 180 return false; 181 182 COUT(4) << "Script (&" << this << ") triggered." << std::endl; 183 184 PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger); 185 Pawn* pawn = NULL; 186 187 // If the trigger is a PlayerTrigger. 188 if(pTrigger != NULL) 189 { 190 if(!pTrigger->isForPlayer()) // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one. 191 return false; 192 else 193 pawn = pTrigger->getTriggeringPlayer(); 194 } 195 else 196 return false; 197 198 if(pawn == NULL) //TODO: Will this ever happen? If not, change in NotificationDispatcher as well. 199 { 200 COUT(4) << "The Script was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl; 201 return false; 202 } 203 204 // Extract the PlayerInfo from the Pawn. 205 PlayerInfo* player = pawn->getPlayer(); 206 207 if(player == NULL) 208 { 209 COUT(3) << "The PlayerInfo* is NULL." << std::endl; 210 return false; 211 } 212 213 this->execute(player->getClientID()); 214 return true; 215 } 216 217 /** 218 @brief 219 Executes the Scripts code for the input client, depending on the mode. 220 @param clientId 221 The Id of the client the Script should be executed for. 222 @param fromCallback 223 Whether this method is executed in response to the connectedCallback(). 224 */ 225 void Script::execute(unsigned int clientId, bool fromCallback) 226 { 227 if(GameMode::isServer()) 228 { 229 // If the number of executions have been used up. 230 if(this->times_ != Script::INF && this->remainingExecutions_ == 0) 231 return; 232 233 // Decrement the number of remaining executions. 234 if(this->times_ != Script::INF) 235 this->remainingExecutions_--; 236 } 237 238 if(GameMode::isStandalone() || Host::getPlayerID() == clientId) 239 { 240 // If the code needs graphics to be executed but the GameMode doesn't show graphics the code isn't executed. 241 if(this->needsGraphics_ && !GameMode::showsGraphics()) 242 return; 243 244 if(this->mode_ == ScriptMode::normal) // If the mode is 'normal'. 245 CommandExecutor::execute(this->code_); 246 else if(this->mode_ == ScriptMode::lua) // If it's 'lua'. 247 { 248 if(this->luaState_ == NULL) 249 this->luaState_ = new LuaState(); 250 this->luaState_->doString(this->code_); 251 } 252 } 253 if(!GameMode::isStandalone() && GameMode::isServer() && Host::getPlayerID() != clientId) 254 { 255 if(!fromCallback && this->isForAll()) 256 { 257 const std::map<unsigned int, PlayerInfo*> clients = PlayerManager::getInstance().getClients(); 258 for(std::map<unsigned int, PlayerInfo*>::const_iterator it = clients.begin(); it != clients.end(); it++) 259 { 260 callMemberNetworkFunction(Script, execute, this->getObjectID(), it->first, it->first, false); 261 } 262 } 263 else 264 { 265 callMemberNetworkFunction(Script, execute, this->getObjectID(), clientId, clientId, false); 266 } 267 } 268 } 269 270 void Script::clientConnected(unsigned int clientId) 271 { 272 if(!GameMode::isStandalone() && GameMode::isServer() && this->isOnLoad()) 273 { 274 if(clientId != 0) 275 //TODO: Do better. This is only a temporary fix. 276 this->clientCallbacks_.push_back(clientId); 277 } 151 278 } 152 279 … … 160 287 { 161 288 if(mode == Script::NORMAL) 289 { 162 290 this->setMode(ScriptMode::normal); 291 this->modeStr_ = Script::NORMAL; 292 } 163 293 else if(mode == Script::LUA) 164 294 { 165 295 this->setMode(ScriptMode::lua); 296 this->modeStr_ = Script::LUA; 166 297 // Creates a new LuaState. 167 298 if(this->luaState_ == NULL) … … 170 301 else 171 302 { 172 COUT(2) << "Invalid mode '" << mode << "' in Script object. " << std::endl;303 COUT(2) << "Invalid mode '" << mode << "' in Script object. Setting to 'normal'." << std::endl; 173 304 this->setMode(ScriptMode::normal); 305 this->modeStr_ = Script::NORMAL; 174 306 } 175 307 } … … 210 342 else 211 343 { 212 COUT(2) << "Invalid times '" << times << "' in Script. " << std::endl;344 COUT(2) << "Invalid times '" << times << "' in Script. Setting to infinity." << std::endl; 213 345 this->times_ = Script::INF; 346 this->remainingExecutions_ = Script::INF; 214 347 } 215 348 } -
code/trunk/src/modules/objects/Script.h
r7463 r7474 33 33 34 34 #include <string> 35 #include <vector> 36 35 37 #include "core/BaseObject.h" 38 #include "tools/interfaces/Tickable.h" 39 #include "network/synchronisable/Synchronisable.h" 40 #include "network/ClientConnectionListener.h" 36 41 37 42 namespace orxonox … … 54 59 'code': The code that should be executed. 55 60 'mode': The mode, specifying whether the set code should be executed the normal way ('normal') or in lua ('lua'). Default is 'normal'. 56 'onLoad': Whether the code is executed upon loading (creation) of this object. Default is true.61 'onLoad': Whether the code is executed upon loading (creation) of this object. If this is set the code is executed ofr all players, regardless of the value of parameter 'forAll'. Default is true. 57 62 'needsGraphics': Whether the code needs graphics to be executed or not. Default is false. 63 'forAll': Whether the code is executed for all players each time the Script is triggered or jut for the player triggering the Script. If forAll is false, which is default, the event that triggers the Script must come from a PlayerTrigger. 58 64 59 65 Here are two examples illustrating the usage: … … 77 83 Damian 'Mozork' Frick 78 84 */ 79 class _ObjectsExport Script : public BaseObject 85 class _ObjectsExport Script : public BaseObject, public Synchronisable, public ClientConnectionListener, public Tickable 80 86 { 81 87 public: … … 86 92 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a port that can be used to channel events and react to them. 87 93 88 void trigger(bool triggered); //!< Is called when an event comes in trough the event port. 89 void execute(); //!< Executes the Scripts code, depending on the mode. 94 virtual void tick(float dt); 95 96 bool trigger(bool triggered, BaseObject* trigger); //!< Is called when an event comes in trough the event port. 97 void execute(unsigned int clientId, bool fromCallback = false); //!< Executes the Scripts code for the input client, depending on the mode. 90 98 91 99 /** … … 139 147 { return this->needsGraphics_; } 140 148 149 /** 150 @brief Set whether the code is executed for all players or just for the player triggering the Script. 151 @param forAll If true the code is executed for all players. 152 */ 153 void setForAll(bool forAll) 154 { this->forAll_ = forAll; } 155 /** 156 @brief Get whether the Script executes its code for all players or just for the player triggering the Script. 157 @return Returns true if the code is executed for all players, false if not. 158 */ 159 bool isForAll(void) 160 { return this->forAll_; } 161 162 virtual void clientConnected(unsigned int clientId); 163 virtual void clientDisconnected(unsigned int clientid) {} 164 141 165 private: 142 166 //! Static variables to avoid magic strings. … … 150 174 int times_; //!< The number of times the Scripts code is executed at the most. -1 denotes infinity. 151 175 bool needsGraphics_; //!< Whether the code to be executed needs graphics. 176 bool forAll_; //!< Whether the code is executed for all players (in a multiplayer setup) or just for the one triggering the Script. 177 178 std::string modeStr_; 179 180 std::vector<unsigned int> clientCallbacks_; 181 float counter_; 152 182 153 183 LuaState* luaState_; //!< The LuaState to execute the code in lua. 154 184 int remainingExecutions_; //!< The number of remainign executions. -1 denotes infinity. 185 186 void registerVariables(void); 187 void modeChanged(); 155 188 156 189 /** -
code/trunk/src/modules/questsystem/CMakeLists.txt
r7401 r7474 10 10 QuestListener.cc 11 11 QuestManager.cc 12 QuestNotification.cc13 12 ) 14 13 -
code/trunk/src/modules/questsystem/QuestDescription.cc
r7456 r7474 38 38 #include "core/XMLPort.h" 39 39 40 #include "QuestNotification.h" 40 #include "infos/PlayerInfo.h" 41 42 #include "notifications/NotificationManager.h" 41 43 42 44 namespace orxonox 43 45 { 44 46 CreateFactory(QuestDescription); 47 48 /*static*/ const std::string QuestDescription::SENDER = "questsystem"; 45 49 46 50 /** … … 115 119 } 116 120 117 QuestNotification* notification = new QuestNotification(this, message); 118 notification->send(player); 121 NotificationManager::sendNotification(message, player->getClientID(), QuestDescription::SENDER); 119 122 return true; 120 123 } -
code/trunk/src/modules/questsystem/QuestDescription.h
r7456 r7474 128 128 129 129 private: 130 static const std::string SENDER; 131 130 132 std::string title_; //!< The title. 131 133 std::string description_; //!< The description. -
code/trunk/src/modules/questsystem/QuestsystemPrereqs.h
r7164 r7474 81 81 class QuestListener; 82 82 class QuestManager; 83 class QuestNotification;84 83 } 85 84
Note: See TracChangeset
for help on using the changeset viewer.