Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7486 for code/trunk


Ignore:
Timestamp:
Sep 23, 2010, 11:54:16 PM (14 years ago)
Author:
dafrick
Message:

Cleanup in Script. Some more documenting in Notifications module.

Location:
code/trunk/src/modules
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/notifications/Notification.h

    r7484 r7486  
    4040#include <string>
    4141#include "core/BaseObject.h"
    42 #include "network/synchronisable/Synchronisable.h"
    4342
    4443namespace orxonox
  • code/trunk/src/modules/notifications/NotificationManager.cc

    r7484 r7486  
    116116    @param sender
    117117        The sender that sent the notification.
    118     */
    119     /*static*/ void NotificationManager::sendNotification(const std::string& message, unsigned int clientId, const std::string& sender)
     118    @param isLocal
     119        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.
     120    */
     121    /*static*/ void NotificationManager::sendNotification(const std::string& message, unsigned int clientId, const std::string& sender, bool isLocal)
    120122    {
    121123        // If we're in standalone mode or we're already no the right client we create and send the Notification.
    122         if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
     124        if(GameMode::isStandalone() || isLocal || Host::getPlayerID() == clientId)
    123125        {
    124126            Notification* notification = new Notification(message);
  • code/trunk/src/modules/notifications/NotificationManager.h

    r7484 r7486  
    7676
    7777            //! Sends a Notification with the specified message to the specified client from the specified sender.
    78             static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE);
     78            static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE, bool isLocal = false);
    7979
    8080            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
  • code/trunk/src/modules/notifications/NotificationQueue.h

    r7484 r7486  
    5858    };
    5959
    60     //! Struct to allow ordering of NotificationContainers.
     60    //! Struct to allow ordering of @ref orxonox::NotificationContainer "NotificationContainers".
    6161    struct NotificationContainerCompare {
    6262        bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
     
    7373        - 'size': The size of the NotificationQueue, it specifies how many @ref orxonox::Notification "Notifications" are displayed at once at the most.
    7474        - 'displayTime': The time a @ref orxonox::Notification "Notification" is displayed with this NotificationQueue.
     75
    7576    @author
    7677        Damian 'Mozork' Frick
  • code/trunk/src/modules/objects/Script.cc

    r7483 r7486  
    6161        The creator of this object.
    6262    */
    63     Script::Script(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
     63    Script::Script(BaseObject* creator) : BaseObject(creator)
    6464    {
    6565        RegisterObject(Script);
     
    7979    Script::~Script()
    8080    {
    81         //if(this->isInitialized() && this->luaState_ != NULL)
    82         //    delete this->luaState_;
     81
    8382    }
    8483
     
    105104
    106105        if(this->isOnLoad()) // If the object is onLoad the code is executed at once for the server.
    107             this->execute(0);
     106            this->execute(0, true);
    108107    }
    109108
     
    178177    @param clientId
    179178        The Id of the client the Script should be executed for.
    180     @param fromCallback
    181         Whether this method is executed in response to the connectedCallback().
    182     */
    183     void Script::execute(unsigned int clientId, bool fromCallback)
     179    @param onLoad
     180        Whether this method is executed as a result of the onLoad parameter being set to true. Default is false.
     181    */
     182    void Script::execute(unsigned int clientId, bool onLoad)
    184183    {
    185184        // 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.
    186         if(GameMode::isServer() || GameMode::isStandalone())
     185        if(GameMode::isMaster())
    187186        {
    188187            // If the number of executions have been used up.
     
    194193        if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
    195194        {
    196            this->executeHelper(this->getCode(), this->getMode(), this->getNeedsGraphics());
     195            this->executeHelper(this->getCode(), this->getMode(), this->getNeedsGraphics());
     196            if(GameMode::isMaster() && !onLoad && this->times_ != Script::INF) // Decrement the number of remaining executions.
     197                this->remainingExecutions_--;
    197198        }
    198199
    199200        // If this is the server and we're not on the client we want to be.
    200         if(!GameMode::isStandalone() && GameMode::isServer() && Host::getPlayerID() != clientId)
    201         {
    202             // If this is not the result of a clientConnected callback and we want to execute the code for all clients.
    203             //TODO: In this case does the server get executed as well?
    204             if(!fromCallback && this->isForAll())
     201        if(GameMode::isServer() && Host::getPlayerID() != clientId)
     202        {
     203            // If we want to execute the code for all clients and the server.
     204            if(this->isForAll())
    205205            {
    206206                const std::map<unsigned int, PlayerInfo*> clients = PlayerManager::getInstance().getClients();
     
    251251    {
    252252        // If this is the server and the Script is specified as being 'onLoad'.
    253         if(!GameMode::isStandalone() && GameMode::isServer() && this->isOnLoad())
    254         {
    255             this->execute(clientId, true);
     253        if(GameMode::isServer() && this->isOnLoad())
     254        {
     255            callStaticNetworkFunction(Script::executeHelper, clientId, this->getCode(), this->getMode(), this->getNeedsGraphics());
    256256        }
    257257    }
  • code/trunk/src/modules/objects/Script.h

    r7484 r7486  
    3737
    3838#include "core/BaseObject.h"
    39 #include "network/synchronisable/Synchronisable.h"
    4039#include "network/ClientConnectionListener.h"
    4140
     
    8483        Damian 'Mozork' Frick
    8584    */
    86     class _ObjectsExport Script : public BaseObject, public Synchronisable, public ClientConnectionListener
     85    class _ObjectsExport Script : public BaseObject, public ClientConnectionListener
    8786    {
    8887        public:
     
    9493
    9594            bool trigger(bool triggered, BaseObject* trigger); //!< Is called when an event comes in trough the event port.
    96             void execute(unsigned int clientId, bool fromCallback = false); //!< Executes the Scripts code for the input client, depending on the mode.
     95            void execute(unsigned int clientId, bool onLoad = false); //!< Executes the Scripts code for the input client, depending on the mode.
    9796            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.
    9897
Note: See TracChangeset for help on using the changeset viewer.