Changeset 7486 for code/trunk/src/modules/objects
- Timestamp:
- Sep 23, 2010, 11:54:16 PM (14 years ago)
- Location:
- code/trunk/src/modules/objects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/Script.cc
r7483 r7486 61 61 The creator of this object. 62 62 */ 63 Script::Script(BaseObject* creator) : BaseObject(creator) , Synchronisable(creator)63 Script::Script(BaseObject* creator) : BaseObject(creator) 64 64 { 65 65 RegisterObject(Script); … … 79 79 Script::~Script() 80 80 { 81 //if(this->isInitialized() && this->luaState_ != NULL) 82 // delete this->luaState_; 81 83 82 } 84 83 … … 105 104 106 105 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); 108 107 } 109 108 … … 178 177 @param clientId 179 178 The Id of the client the Script should be executed for. 180 @param fromCallback181 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) 184 183 { 185 184 // 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::is Server() || GameMode::isStandalone())185 if(GameMode::isMaster()) 187 186 { 188 187 // If the number of executions have been used up. … … 194 193 if(GameMode::isStandalone() || Host::getPlayerID() == clientId) 195 194 { 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_--; 197 198 } 198 199 199 200 // 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()) 205 205 { 206 206 const std::map<unsigned int, PlayerInfo*> clients = PlayerManager::getInstance().getClients(); … … 251 251 { 252 252 // 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()); 256 256 } 257 257 } -
code/trunk/src/modules/objects/Script.h
r7484 r7486 37 37 38 38 #include "core/BaseObject.h" 39 #include "network/synchronisable/Synchronisable.h"40 39 #include "network/ClientConnectionListener.h" 41 40 … … 84 83 Damian 'Mozork' Frick 85 84 */ 86 class _ObjectsExport Script : public BaseObject, public Synchronisable, publicClientConnectionListener85 class _ObjectsExport Script : public BaseObject, public ClientConnectionListener 87 86 { 88 87 public: … … 94 93 95 94 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. 97 96 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. 98 97
Note: See TracChangeset
for help on using the changeset viewer.