[Orxonox-commit 2783] r7486 - in code/trunk/src/modules: notifications objects

dafrick at orxonox.net dafrick at orxonox.net
Thu Sep 23 23:54:16 CEST 2010


Author: dafrick
Date: 2010-09-23 23:54:16 +0200 (Thu, 23 Sep 2010)
New Revision: 7486

Modified:
   code/trunk/src/modules/notifications/Notification.h
   code/trunk/src/modules/notifications/NotificationManager.cc
   code/trunk/src/modules/notifications/NotificationManager.h
   code/trunk/src/modules/notifications/NotificationQueue.h
   code/trunk/src/modules/objects/Script.cc
   code/trunk/src/modules/objects/Script.h
Log:
Cleanup in Script. Some more documenting in Notifications module.


Modified: code/trunk/src/modules/notifications/Notification.h
===================================================================
--- code/trunk/src/modules/notifications/Notification.h	2010-09-23 21:22:22 UTC (rev 7485)
+++ code/trunk/src/modules/notifications/Notification.h	2010-09-23 21:54:16 UTC (rev 7486)
@@ -39,7 +39,6 @@
 
 #include <string>
 #include "core/BaseObject.h"
-#include "network/synchronisable/Synchronisable.h"
 
 namespace orxonox
 {

Modified: code/trunk/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/trunk/src/modules/notifications/NotificationManager.cc	2010-09-23 21:22:22 UTC (rev 7485)
+++ code/trunk/src/modules/notifications/NotificationManager.cc	2010-09-23 21:54:16 UTC (rev 7486)
@@ -115,11 +115,13 @@
         The id of the client the notification should be sent to.
     @param sender
         The sender that sent the notification.
+    @param isLocal
+        If this is set to true (false is default), then the Notification is sent to the client where this function is executed, meaning the Notification is sent locally.
     */
-    /*static*/ void NotificationManager::sendNotification(const std::string& message, unsigned int clientId, const std::string& sender)
+    /*static*/ void NotificationManager::sendNotification(const std::string& message, unsigned int clientId, const std::string& sender, bool isLocal)
     {
         // If we're in standalone mode or we're already no the right client we create and send the Notification.
-        if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
+        if(GameMode::isStandalone() || isLocal || Host::getPlayerID() == clientId)
         {
             Notification* notification = new Notification(message);
             notification->send(sender);

Modified: code/trunk/src/modules/notifications/NotificationManager.h
===================================================================
--- code/trunk/src/modules/notifications/NotificationManager.h	2010-09-23 21:22:22 UTC (rev 7485)
+++ code/trunk/src/modules/notifications/NotificationManager.h	2010-09-23 21:54:16 UTC (rev 7486)
@@ -75,7 +75,7 @@
             static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener.
 
             //! Sends a Notification with the specified message to the specified client from the specified sender.
-            static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE);
+            static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE, bool isLocal = false);
 
             bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
             void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener.

Modified: code/trunk/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/trunk/src/modules/notifications/NotificationQueue.h	2010-09-23 21:22:22 UTC (rev 7485)
+++ code/trunk/src/modules/notifications/NotificationQueue.h	2010-09-23 21:54:16 UTC (rev 7486)
@@ -57,7 +57,7 @@
         time_t time; // The time the Notification was sent and thus first displayed.
     };
 
-    //! Struct to allow ordering of NotificationContainers.
+    //! Struct to allow ordering of @ref orxonox::NotificationContainer "NotificationContainers".
     struct NotificationContainerCompare {
         bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
             { return a->time < b->time; } // Ordered by time.
@@ -72,6 +72,7 @@
         - 'senders': The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
         - 'size': The size of the NotificationQueue, it specifies how many @ref orxonox::Notification "Notifications" are displayed at once at the most.
         - 'displayTime': The time a @ref orxonox::Notification "Notification" is displayed with this NotificationQueue.
+
     @author
         Damian 'Mozork' Frick
     */

Modified: code/trunk/src/modules/objects/Script.cc
===================================================================
--- code/trunk/src/modules/objects/Script.cc	2010-09-23 21:22:22 UTC (rev 7485)
+++ code/trunk/src/modules/objects/Script.cc	2010-09-23 21:54:16 UTC (rev 7486)
@@ -60,7 +60,7 @@
     @param creator
         The creator of this object.
     */
-    Script::Script(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
+    Script::Script(BaseObject* creator) : BaseObject(creator)
     {
         RegisterObject(Script);
 
@@ -78,8 +78,7 @@
     */
     Script::~Script()
     {
-        //if(this->isInitialized() && this->luaState_ != NULL)
-        //    delete this->luaState_;
+
     }
 
     /**
@@ -104,7 +103,7 @@
         XMLPortEventSink(Script, BaseObject, "trigger", trigger, xmlelement, mode);
 
         if(this->isOnLoad()) // If the object is onLoad the code is executed at once for the server.
-            this->execute(0);
+            this->execute(0, true);
     }
 
     /**
@@ -177,13 +176,13 @@
         Executes the Scripts code for the input client, depending on the mode.
     @param clientId
         The Id of the client the Script should be executed for.
-    @param fromCallback
-        Whether this method is executed in response to the connectedCallback().
+    @param onLoad
+        Whether this method is executed as a result of the onLoad parameter being set to true. Default is false.
     */
-    void Script::execute(unsigned int clientId, bool fromCallback)
+    void Script::execute(unsigned int clientId, bool onLoad)
     {
         // If this is the server or we're in standalone mode we check whether we still want to execute the code and if so decrease the number of remaining executions.
-        if(GameMode::isServer() || GameMode::isStandalone())
+        if(GameMode::isMaster())
         {
             // If the number of executions have been used up.
             if(this->times_ != Script::INF && this->remainingExecutions_ == 0)
@@ -193,15 +192,16 @@
         // If this is either the standalone mode or we're on the client we want to be.
         if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
         {
-           this->executeHelper(this->getCode(), this->getMode(), this->getNeedsGraphics());
+            this->executeHelper(this->getCode(), this->getMode(), this->getNeedsGraphics());
+            if(GameMode::isMaster() && !onLoad && this->times_ != Script::INF) // Decrement the number of remaining executions.
+                this->remainingExecutions_--;
         }
 
         // If this is the server and we're not on the client we want to be.
-        if(!GameMode::isStandalone() && GameMode::isServer() && Host::getPlayerID() != clientId)
+        if(GameMode::isServer() && Host::getPlayerID() != clientId)
         {
-            // If this is not the result of a clientConnected callback and we want to execute the code for all clients.
-            //TODO: In this case does the server get executed as well?
-            if(!fromCallback && this->isForAll())
+            // If we want to execute the code for all clients and the server.
+            if(this->isForAll())
             {
                 const std::map<unsigned int, PlayerInfo*> clients = PlayerManager::getInstance().getClients();
                 for(std::map<unsigned int, PlayerInfo*>::const_iterator it = clients.begin(); it != clients.end(); it++)
@@ -250,9 +250,9 @@
     void Script::clientConnected(unsigned int clientId)
     {
         // If this is the server and the Script is specified as being 'onLoad'.
-        if(!GameMode::isStandalone() && GameMode::isServer() && this->isOnLoad())
+        if(GameMode::isServer() && this->isOnLoad())
         {
-            this->execute(clientId, true);
+            callStaticNetworkFunction(Script::executeHelper, clientId, this->getCode(), this->getMode(), this->getNeedsGraphics());
         }
     }
 

Modified: code/trunk/src/modules/objects/Script.h
===================================================================
--- code/trunk/src/modules/objects/Script.h	2010-09-23 21:22:22 UTC (rev 7485)
+++ code/trunk/src/modules/objects/Script.h	2010-09-23 21:54:16 UTC (rev 7486)
@@ -36,7 +36,6 @@
 #include <vector>
 
 #include "core/BaseObject.h"
-#include "network/synchronisable/Synchronisable.h"
 #include "network/ClientConnectionListener.h"
 
 namespace orxonox
@@ -83,7 +82,7 @@
     @author
         Damian 'Mozork' Frick
     */
-    class _ObjectsExport Script : public BaseObject, public Synchronisable, public ClientConnectionListener
+    class _ObjectsExport Script : public BaseObject, public ClientConnectionListener
     {
         public:
             Script(BaseObject* creator);
@@ -93,7 +92,7 @@
             virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a port that can be used to channel events and react to them.
 
             bool trigger(bool triggered, BaseObject* trigger); //!< Is called when an event comes in trough the event port.
-            void execute(unsigned int clientId, bool fromCallback = false); //!< Executes the Scripts code for the input client, depending on the mode.
+            void execute(unsigned int clientId, bool onLoad = false); //!< Executes the Scripts code for the input client, depending on the mode.
             static void executeHelper(const std::string& code, const std::string& mode, bool needsGraphics); //!< Helper method that is used to reach this Script object on other clients.
 
             /**




More information about the Orxonox-commit mailing list