Changeset 8206 in orxonox.OLD for branches/script_engine/src/lib
- Timestamp:
- Jun 7, 2006, 5:56:55 PM (19 years ago)
- Location:
- branches/script_engine/src/lib/script_engine
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/script.cc
r8202 r8206 95 95 if (scriptClass != NULL) 96 96 { 97 if( !classIsRegistered(className) ) 97 98 static_cast<ScriptClass*>(scriptClass)->registerClass(this); 98 99 99 100 BaseObject* object = ClassList::getObject(objectName, className); 100 if (object != NULL )101 if (object != NULL && !objectIsAdded(objectName)) 101 102 { 102 103 static_cast<ScriptClass*>(scriptClass)->insertObject(this, object, false); … … 292 293 } 293 294 295 296 bool Script::classIsRegistered(const std::string& type) 297 { 298 for(std::list<worldObject>::const_iterator it = registeredObjects.begin(); it != registeredObjects.end(); it++ ) 299 { 300 if( (*it).type == type) 301 { 302 return true; 303 } 304 } 305 return false; 306 } 307 308 309 310 bool Script::objectIsAdded(const std::string& name) 311 { 312 for(std::list<worldObject>::const_iterator it = registeredObjects.begin(); it != registeredObjects.end(); it++ ) 313 { 314 if( (*it).name == name) 315 { 316 return true; 317 } 318 } 319 return false; 320 321 322 } -
branches/script_engine/src/lib/script_engine/script.h
r8202 r8206 5 5 #include "base_object.h" 6 6 7 7 8 struct lua_State; 9 10 struct worldObject 11 { 12 std::string name; 13 std::string type; 14 }; 8 15 9 16 class Script : public BaseObject … … 18 25 void loadFileNoRet(const std::string& filename) { loadFile(filename); }; 19 26 bool loadFile(const std::string& filename); 27 void addObject(const std::string& className, const std::string& objectName); 28 29 /// QUERRYING 20 30 /** @returns fileName */ 21 31 std::string getFileName() { return currentFile; } 22 23 void addObject(const std::string& className, const std::string& objectName);24 25 26 27 32 lua_State* getLuaState() const { return luaState; } 28 33 … … 51 56 private: 52 57 53 int reportError(int error); //!< Get errormessage from the lua stack and print it. 58 int reportError(int error); //!< Get errormessage from the lua stack and print it. 59 bool classIsRegistered(const std::string& type); 60 bool objectIsAdded(const std::string& name); 54 61 55 lua_State* luaState; //!< The lua_State that the Script works on 56 std::string currentFile; //!< The file that is loaded in the script 57 std::string currentFunction; //!< The name of the current active function (the one that gets the pushed parameter) 58 int argumentCount; //!< Number of arguments for the current function 59 int returnCount; //!< Number of return values of the current function 62 lua_State* luaState; //!< The lua_State that the Script works on 63 std::string currentFile; //!< The file that is loaded in the script 64 std::string currentFunction; //!< The name of the current active function (the one that gets the pushed parameter) 65 int argumentCount; //!< Number of arguments for the current function 66 int returnCount; //!< Number of return values of the current function 67 68 std::list<worldObject> registeredObjects; //!< The list of all the objects and their type that have been registered with this script 60 69 61 70 -
branches/script_engine/src/lib/script_engine/script_manager.cc
r8202 r8206 31 31 { 32 32 //BaseObject::loadParams(root); 33 33 { 34 34 LoadParamXML(root, "ScriptTriggers", this, ScriptManager, createTriggers); 35 35 36 36 LoadParamXML(root, "Scripts", this, ScriptManager, createScripts); 37 } // make shure that the loading process is finished 38 39 // fill the scripts and triggers (doing that on runtime is very slow!) 40 getTriggers(); 41 getScripts(); 42 43 37 44 } 38 45 … … 72 79 Script* ScriptManager::getScriptByFile(std::string& file) 73 80 { 74 75 // for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ ) 76 // { 77 // if( (*it).name.compare(file) == 0) 78 // { 79 // return &((*it).script); 80 // } 81 // } 82 // return NULL; 81 if(getScripts()) 82 for(std::list<BaseObject*>::const_iterator it = scripts->begin(); it != scripts->end(); it++ ) 83 { 84 if( (dynamic_cast<Script*>(*it))->getFileName().compare(file) == 0) 85 { 86 return dynamic_cast<Script*>(*it); 87 } 88 } 89 90 return NULL; 83 91 84 92 } … … 90 98 } 91 99 100 bool ScriptManager::getTriggers() 101 { 102 return (this->triggers != NULL || (this->triggers = ClassList::getList(CL_SCRIPT_TRIGGER)) != NULL); 103 } 92 104 93 105 106 -
branches/script_engine/src/lib/script_engine/script_manager.h
r8202 r8206 20 20 21 21 virtual void loadParams(const TiXmlElement* root); 22 23 22 24 23 Script* getScriptByFile(std::string& file); -
branches/script_engine/src/lib/script_engine/script_trigger.cc
r8205 r8206 102 102 ScriptManager* scriptManager = ScriptManager::getInstance(); 103 103 Script* script = scriptManager->getScriptByFile(this->scriptFile); 104 if(script != NULL) 104 105 if(!(script->selectFunction(this->functionName,0)) ) 105 106 printf("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), scriptFile.c_str());
Note: See TracChangeset
for help on using the changeset viewer.