Changeset 7483
- Timestamp:
- Sep 23, 2010, 11:21:01 AM (14 years ago)
- Location:
- code/trunk/src/modules/objects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/Script.cc
r7482 r7483 55 55 /*static*/ const int Script::INF = -1; 56 56 57 /*static*/ LuaState* Script::LUA_STATE = NULL;58 59 57 /** 60 58 @brief … … 185 183 void Script::execute(unsigned int clientId, bool fromCallback) 186 184 { 187 COUT(0) << "EXECUTE: " << Host::getPlayerID() << " | " << clientId << std::endl; //TODO: Remove.188 185 // 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. 189 186 if(GameMode::isServer() || GameMode::isStandalone()) … … 192 189 if(this->times_ != Script::INF && this->remainingExecutions_ == 0) 193 190 return; 194 195 // Decrement the number of remaining executions.196 //TODO: Mode such that this is consistent in any case.197 if(this->times_ != Script::INF)198 this->remainingExecutions_--;199 191 } 200 192 … … 208 200 if(!GameMode::isStandalone() && GameMode::isServer() && Host::getPlayerID() != clientId) 209 201 { 210 COUT(0) << "1" << std::endl; //TODO: Remove.211 202 // If this is not the result of a clientConnected callback and we want to execute the code for all clients. 212 203 //TODO: In this case does the server get executed as well? … … 217 208 { 218 209 callStaticNetworkFunction(Script::executeHelper, it->first, this->getCode(), this->getMode(), this->getNeedsGraphics()); 210 if(this->times_ != Script::INF) // Decrement the number of remaining executions. 211 this->remainingExecutions_--; 219 212 } 220 213 } … … 222 215 else 223 216 { 224 COUT(0) << "2" << std::endl; //TODO: Remove.225 217 callStaticNetworkFunction(Script::executeHelper, clientId, this->getCode(), this->getMode(), this->getNeedsGraphics()); 218 if(this->times_ != Script::INF) // Decrement the number of remaining executions. 219 this->remainingExecutions_--; 226 220 } 227 221 } … … 234 228 /*static*/ void Script::executeHelper(const std::string& code, const std::string& mode, bool needsGraphics) 235 229 { 236 COUT(0) << "HELPER: " << code << " | " << mode << " | " << needsGraphics << std::endl; //TODO: Remove.237 238 230 // If the code needs graphics to be executed but the GameMode doesn't show graphics the code isn't executed. 239 231 if(needsGraphics && !GameMode::showsGraphics()) … … 244 236 else if(mode == Script::LUA) // If it's 'lua'. 245 237 { 246 if(Script::LUA_STATE == NULL)247 Script::LUA_STATE = new LuaState();248 Script::LUA_STATE->doString(code);238 LuaState* luaState = new LuaState(); 239 luaState->doString(code); 240 delete luaState; 249 241 } 250 242 } … … 261 253 if(!GameMode::isStandalone() && GameMode::isServer() && this->isOnLoad()) 262 254 { 263 if(clientId != 0) //TODO: Remove if not needed. 264 this->execute(clientId, true); 255 this->execute(clientId, true); 265 256 } 266 257 } -
code/trunk/src/modules/objects/Script.h
r7482 r7483 176 176 bool forAll_; //!< Whether the code is executed for all players (in a multiplayer setup) or just for the one triggering the Script. 177 177 178 static LuaState* LUA_STATE; //!< The LuaState to execute the code in lua.179 178 int remainingExecutions_; //!< The number of remainign executions. -1 denotes infinity. 180 179
Note: See TracChangeset
for help on using the changeset viewer.