Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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.