Changeset 8155 in orxonox.OLD for branches/script_engine/src/lib
- Timestamp:
- Jun 5, 2006, 3:47:10 PM (18 years ago)
- Location:
- branches/script_engine/src/lib/script_engine
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/script.h
r8132 r8155 27 27 bool pushParam(float param, std::string& toFunction); 28 28 bool pushParam(double param, std::string& toFunction); 29 // get returned values the last return value in lua is the first in c. 29 // get returned values the last return value in lua is the first in c. TODO: change order of return 30 30 int getReturnedInt(); 31 31 bool getReturnedBool(); 32 32 float getReturnedFloat(); 33 void getReturnedString(std::string& string);33 void getReturnedString(std::string& string); 34 34 35 35 -
branches/script_engine/src/lib/script_engine/script_manager.cc
r8138 r8155 4 4 #include "script.h" 5 5 #include "script_manager.h" 6 #include "lunar.h" 6 7 7 8 8 ScriptManager::ScriptManager( std::string& world)9 ScriptManager::ScriptManager() 9 10 { 10 this->init(world); 11 11 this->init(); 12 12 } 13 13 … … 27 27 } 28 28 29 void ScriptManager::loadParams(const TiXmlElement* root) 30 { 31 //BaseObject::loadParams(root); 29 32 30 //!< Fills the worldObject list 33 const TiXmlElement* scripts = root->FirstChildElement("Scripts"); 31 34 32 void ScriptManager::init(std::string& world) 33 { 35 if( element == NULL) 36 { 37 PRINTF(1)("ScriptManager is missing 'Scripts'\n"); 38 } 39 else 40 { 41 createScriptList(scripts); 42 } 34 43 35 44 36 45 } 37 46 38 39 40 void ScriptManager::loadParams(const TiXmlElement* root)41 {42 //BaseObject::loadParams(root);43 44 45 }46 47 48 47 void ScriptManager::tick(float timestep) 49 {50 }51 52 void ScriptManager::changeWorld(std::string& newWorld)53 48 { 54 49 } … … 57 52 void ScriptManager::initScripts() 58 53 { 54 for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ ) 55 { 56 (*it).script.loadFile((*it).name); 57 } 58 } 59 60 void ScriptManager::init() 61 { 62 currentWorld.assign(""); 63 59 64 } 60 65 61 66 67 void ScriptManager::createScriptList(TiXmlElement* scripts) 68 { 69 const TiXmlElement* script = scripts->FirstChildElement(); 70 const TiXmlElement* object; 71 72 PRINTF(4)("Creating scriptlist\n"); 73 74 while( script != NULL) 75 { 76 LoadParam(script, "file", this, ScriptManager, setCurrentScriptFile) 77 .describe("the fileName of the script, that should be loaded into this world") 78 .defaultValues(""); 79 80 if(!currentScript.name.empty()) // if LoadParam didn't fail... fill the object list with the needed objects 81 { 82 object = script->FirstChildElement("object"); 83 84 while(object != NULL) 85 { 86 addObjectToScript(object->Value(), currentScript); 87 object = object->NextSiblingElement("object"); 88 } 89 90 scriptList.push_back(currentScript); 91 } 92 93 script = script->NextSiblingElement("Script"); 94 95 } 96 97 98 } 99 100 void ScriptManager::setCurrentScriptFile(std::string& file) 101 { 102 if( !fileIsInScriptList(file) ) 103 currentScript.name = file; 104 else 105 currentScript.name.assign(""); 106 } 107 108 void ScriptManager::addObjectToScript(std::string& object, LuaScript& script) 109 { 110 if(!objectIsInObjectList(object,script)) 111 script.objectList.push_back(object); 112 } 113 114 115 bool ScriptManager::fileIsInScriptList(std::string& file) 116 { 117 for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ ) 118 { 119 if( (*it).name.compare(file) == 0) 120 { 121 return true; 122 } 123 } 124 return false; 125 } 126 127 128 bool ScriptManager::objectIsInObjectList(std::string& object, const LuaScript& script) 129 { 130 for(std::list<std::string>::iterator it = script.objectList.begin(); it != script.objectList.end(); it++ ) 131 { 132 if( (*it).compare(object) == 0) 133 { 134 return true; 135 } 136 } 137 return false; 138 } 139 140 -
branches/script_engine/src/lib/script_engine/script_manager.h
r8139 r8155 11 11 12 12 13 //!< Contains the name s of all objects in a world and a list of all script files that need the object.14 struct worldObject13 //!< Contains the name of a lua script file and a list of all objects that the script needs 14 struct LuaScript 15 15 { 16 16 std::string name; 17 std::list<std::string> scriptFiles; 17 std::list<std::string> objectList; 18 Script script; 18 19 }; 19 20 … … 22 23 public: 23 24 ScriptManager(); 24 ScriptManager(std::string& world);25 25 ~ScriptManager(); 26 26 27 27 inline static ScriptManager* getInstance(); 28 28 29 void loadParams(const TiXmlElement* root); 29 virtual void loadParams(const TiXmlElement* root); 30 void setWorld(std::string& world){currentWorld = world;} 30 31 31 32 void tick(float timestep); 32 33 void changeWorld(std::string& newWorld);34 35 33 36 34 void initScripts(); // initializes all scripts … … 38 36 private: 39 37 40 void init(std::string& world); 38 void init(); 39 void createScriptList(TiXmlElement* scripts); 40 void setCurrentScriptFile(std::string& file); 41 void addObjectToScript(std::string& object, LuaScript& script); 41 42 42 static ScriptManager* singletonRef; //!< Reference to this class 43 std::list<worldObject> objectList; //!< The list of all Objects in a world (read from the *.oxw file of the world) 44 std::string currentWorld; 43 bool fileIsInScriptList(std::string& file); 44 bool objectIsInObjectList(std::string& object,const LuaScript& script); 45 46 47 static ScriptManager* singletonRef; //!< Reference to this class 48 std::list<LuaScript> scriptList; //!< The list of all scripts that the current world needs 49 std::string currentWorld; 50 LuaScript currentScript; //!< For temorary use 51 45 52 46 53
Note: See TracChangeset
for help on using the changeset viewer.