Changeset 8193 in orxonox.OLD for branches/script_engine/src/lib
- Timestamp:
- Jun 7, 2006, 3:04:14 PM (19 years ago)
- Location:
- branches/script_engine/src/lib
- Files:
-
- 8 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/Makefile.am
r8170 r8193 15 15 script.cc\ 16 16 script_manager.cc\ 17 scriptable.cc \ 17 18 script_trigger.cc 18 19 … … 23 24 script.h\ 24 25 script_manager.h\ 26 scriptable.h \ 25 27 script_trigger.h 26 28 -
branches/script_engine/src/lib/script_engine/lunar.h
r8101 r8193 3 3 4 4 #include <string> 5 #include <cassert> 5 6 #include "script.h" 6 7 … … 140 141 static int insertObject(Script* script, T* obj, const std::string& name, bool gc=false) 141 142 { 142 if(script != NULL) 143 return insertObject(script->getLuaState(), obj, name, gc); 144 145 143 assert (script != NULL); 144 return insertObject(script->getLuaState(), obj, name, gc); 146 145 } 147 146 -
branches/script_engine/src/lib/script_engine/script.cc
r8134 r8193 1 1 #include "script.h" 2 3 4 Script::Script() 2 #include "loading/load_param.h" 3 4 5 Script::Script(const TiXmlElement* root) 5 6 { 7 this->setClassID(CL_SCRIPT, "Script"); 8 6 9 returnCount = argumentCount = 0; 7 10 … … 14 17 luaopen_math(luaState); 15 18 luaopen_debug(luaState); 19 20 if (root != NULL) 21 this->loadParams(root); 16 22 17 23 } … … 25 31 26 32 27 bool Script::loadFile(std::string& filename) 33 void Script::loadParams(const TiXmlElement* root) 34 { 35 LOAD_PARAM_START_CYCLE(root, objectElement); 36 { 37 LoadParam_CYCLE(objectElement, "object", this, Script, addObject) 38 .describe("The name of an object that is needed by a script"); 39 } 40 LOAD_PARAM_END_CYCLE(objectElement); 41 42 43 LoadParam(root, "file", this, Script, loadFileNoRet) 44 .describe("the fileName of the script, that should be loaded into this world") 45 .defaultValues(""); 46 } 47 48 49 50 bool Script::loadFile(const std::string& filename) 28 51 { 29 52 … … 59 82 } 60 83 84 85 void Script::addObject(const std::string& className, const std::string& objectName) 86 { 87 88 } 89 90 91 92 61 93 bool Script::executeFile() 62 94 { -
branches/script_engine/src/lib/script_engine/script.h
r8155 r8193 3 3 4 4 5 #include <string>6 5 #include "base_object.h" 7 6 … … 9 8 10 9 11 class Script 10 class Script : public BaseObject 12 11 { 13 12 public: 14 Script( );13 Script(const TiXmlElement* root = NULL); 15 14 ~Script(); 15 16 /// LOADING 17 void loadParams(const TiXmlElement* root); 16 18 17 bool loadFile(std::string& filename); 18 std::string getFileName(){return currentFile;} 19 bool executeFile(); 19 void loadFileNoRet(const std::string& filename) { loadFile(filename); }; 20 bool loadFile(const std::string& filename); 21 /** @returns fileName */ 22 std::string getFileName() { return currentFile; } 20 23 21 lua_State* getLuaState() const{return luaState;} 24 void addObject(const std::string& className, const std::string& objectName); 25 26 22 27 28 lua_State* getLuaState() const { return luaState; } 29 30 31 32 /// EXECUTING 33 // first select function 23 34 bool selectFunction(std::string& functionName, int retCount); 24 bool executeFunction(); 35 25 36 // push parameters for luafunction 26 37 bool pushParam(int param, std::string& toFunction); 27 38 bool pushParam(float param, std::string& toFunction); 28 39 bool pushParam(double param, std::string& toFunction); 29 // get returned values the last return value in lua is the first in c. TODO: change order of return 40 41 // Execute the Function 42 bool executeFunction(); 43 44 // get returned values the last return value in lua is the first in c. TODO: change order of return 30 45 int getReturnedInt(); 31 46 bool getReturnedBool(); … … 33 48 void getReturnedString(std::string& string); 34 49 50 bool executeFile(); 35 51 36 52 private: … … 46 62 47 63 48 49 64 }; 50 65 #endif /* _SCRIPT_H */ -
branches/script_engine/src/lib/script_engine/script_manager.cc
r8178 r8193 31 31 } 32 32 33 const TiXmlElement* scripts = root->FirstChildElement("Scripts"); 34 35 if( scripts == NULL) 36 { 37 PRINTF(1)("ScriptManager is missing 'Scripts'\n"); 38 } 39 else 40 { 41 createScriptList(scripts); 42 } 43 44 33 34 LoadParamXML(root, "Scripts", this, ScriptManager, createScriptList); 45 35 } 46 36 … … 50 40 51 41 52 void ScriptManager::initScripts()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 42 void ScriptManager::init() 61 43 { 62 currentWorld.assign("");63 44 64 45 } … … 67 48 void ScriptManager::createScriptList(const TiXmlElement* scripts) 68 49 { 50 51 LOAD_PARAM_START_CYCLE(scripts, object); 52 { 53 new Script(object); 54 } 55 LOAD_PARAM_END_CYCLE(object); 56 57 58 /* 69 59 const TiXmlElement* script = scripts->FirstChildElement(); 70 60 … … 94 84 script = script->NextSiblingElement("Script"); 95 85 96 } 86 }*/ 97 87 98 88 … … 103 93 { 104 94 105 for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ )106 {107 if( (*it).name.compare(file) == 0)108 {109 return &((*it).script);110 }111 }112 return NULL;95 // for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ ) 96 // { 97 // if( (*it).name.compare(file) == 0) 98 // { 99 // return &((*it).script); 100 // } 101 // } 102 // return NULL; 113 103 114 104 } 115 105 116 void ScriptManager::setCurrentScriptFile(const std::string& file)117 {118 if( !fileIsInScriptList(file) )119 currentScript.name = file;120 else121 currentScript.name.assign("");122 }123 124 void ScriptManager::addObjectToScript(const std::string object)125 {126 if(!objectIsInObjectList(object,currentScript))127 currentScript.objectList.push_back(object);128 }129 130 131 bool ScriptManager::fileIsInScriptList(const std::string& file)132 {133 for(std::list<LuaScript>::const_iterator it = scriptList.begin(); it != scriptList.end(); it++ )134 {135 if( (*it).name.compare(file) == 0)136 {137 return true;138 }139 }140 return false;141 }142 143 144 bool ScriptManager::objectIsInObjectList(const std::string& object, const LuaScript& script)145 {146 for(std::list<std::string>::const_iterator it = script.objectList.begin(); it != script.objectList.end(); it++ )147 {148 if( (*it).compare(object) == 0)149 {150 return true;151 }152 }153 return false;154 }155 156 -
branches/script_engine/src/lib/script_engine/script_manager.h
r8178 r8193 6 6 7 7 #include "script.h" 8 #include "script_trigger.h"9 8 #include "base_object.h" 10 9 #include "luaincl.h" … … 12 11 13 12 14 //!< Contains the name of a lua script file and a list of all objects that the script needs 15 struct LuaScript 16 { 17 std::string name; 18 std::list<std::string> objectList; 19 Script script; 20 }; 21 13 class ScriptTrigger; 14 class Scriptable; 22 15 23 16 class ScriptManager : public BaseObject … … 27 20 ~ScriptManager(); 28 21 29 inline static ScriptManager* getInstance() {if (!ScriptManager::singletonRef)ScriptManager::singletonRef = new ScriptManager();return ScriptManager::singletonRef;}22 inline static ScriptManager* getInstance() { if (!ScriptManager::singletonRef)ScriptManager::singletonRef = new ScriptManager(); return ScriptManager::singletonRef; } 30 23 31 24 virtual void loadParams(const TiXmlElement* root); 32 void setWorld(const std::string& world) {currentWorld = world;}33 25 34 26 void tick(float timestep); 35 27 36 void initScripts(); // initializes all scripts37 28 Script* getScriptByFile(std::string& file); 38 29 30 31 39 32 private: 40 33 41 34 void init(); 42 35 void createScriptList(const TiXmlElement* scripts); 43 void setCurrentScriptFile(const std::string& file);44 36 void addObjectToScript(const std::string object); 45 37 46 bool fileIsInScriptList(const std::string& file);47 bool objectIsInObjectList(const std::string& object, const LuaScript& script);48 38 39 static ScriptManager* singletonRef; //!< Reference to this class 49 40 50 static ScriptManager* singletonRef; //!< Reference to this class 51 std::list<LuaScript> scriptList; //!< The list of all scripts that the current world needs 52 std::string currentWorld; 53 LuaScript currentScript; //!< For temorary use 41 const std::list<BaseObject*>* triggerList; 54 42 55 56 43 const std::list<BaseObject*>* scriptableClasses; 44 const std::list<BaseObject*>* scripts; 57 45 58 46 -
branches/script_engine/src/lib/script_engine/script_trigger.h
r8178 r8193 21 21 void setTarget(WorldEntity* target){ if(target!=NULL) this->target=target;if(worldEntityIsParent)this->setParent(target);} 22 22 void setTargetName(std::string& name){this->targetName = name;} 23 void setCallOnce(bool call) {this->callOnce = call;}24 void setRadius(float radius) {if(radius>0) this->radius = radius;}23 void setCallOnce(bool call) { this->callOnce = call;} 24 void setRadius(float radius) { if(radius>0) this->radius = radius;} 25 25 void setDelay(float time){if(delay>0) this->delay = delay;} 26 26 void setScript(std::string& script){this->scriptFile = script;} … … 31 31 private: 32 32 33 std::string parentName; 33 34 WorldEntity* target; 34 35 std::string targetName; -
branches/script_engine/src/lib/script_engine/scriptable.cc
r8183 r8193 16 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 17 17 18 #include " proto_class.h"18 #include "scriptable.h" 19 19 20 20 using namespace std; … … 25 25 * @todo this constructor is not jet implemented - do it 26 26 */ 27 ProtoClass::ProtoClass () 27 Scriptable::Scriptable(const std::string& name, ClassID classID) 28 : BaseObject(name) 28 29 { 29 this->setClassID(CL_PROTO_ID, "ProtoClass"); 30 this->setClassID(CL_SCRIPTABLE, "Scriptable"); 31 this->classID = classID; 30 32 31 /* If you make a new class, what is most probably the case when you write this file32 don't forget to:33 1. Add the new file new_class.cc to the ./src/Makefile.am34 2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS35 33 36 Advanced Topics:37 - if you want to let your object be managed via the ObjectManager make sure to read38 the object_manager.h header comments. You will use this most certanly only if you39 make many objects of your class, like a weapon bullet.40 */41 34 } 42 35 … … 45 38 * standard deconstructor 46 39 */ 47 ProtoClass::~ProtoClass()40 Scriptable::~Scriptable () 48 41 { 49 42 // delete what has to be deleted here -
branches/script_engine/src/lib/script_engine/scriptable.h
r8183 r8193 1 1 /*! 2 * @file proto_class.h2 * @file scriptable.h 3 3 * @brief Definition of ... 4 4 */ 5 5 6 #ifndef _ PROTO_CLASS_H7 #define _ PROTO_CLASS_H6 #ifndef _SCRIPTABLE_H 7 #define _SCRIPTABLE_H 8 8 9 9 #include "base_object.h" 10 11 #include "script.h" 12 #include "lunar.h" 10 13 11 14 // FORWARD DECLARATION 12 15 13 16 17 /** 18 * Creates a factory to a Loadable Class. 19 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file) 20 */ 21 #define CREATE_SCRIPTABLE_CLASS(CLASS_NAME, CLASS_ID) \ 22 tScriptable<CLASS_NAME> global_##CLASS_NAME##_ScriptableClass(#CLASS_NAME, CLASS_ID) 23 24 14 25 15 26 //! A class for ... 16 class ProtoClass : public BaseObject { 27 class Scriptable : virtual protected BaseObject 28 { 17 29 18 public: 19 ProtoClass(); 20 virtual ~ProtoClass(); 30 public: 31 Scriptable(const std::string& name, ClassID classID); 32 virtual ~Scriptable(); 33 34 bool operator==(const std::string& name) { return (this->getName() == name); } 35 bool operator==(ClassID classID) { return (this->classID == classID); } 36 37 virtual void registerClass(Script* script) = 0; 38 virtual int insertObject(Script* L, BaseObject* obj, const std::string& name, bool gc=false) = 0; 39 40 private: 41 ClassID classID; 42 }; 21 43 22 44 23 private:24 45 25 };26 46 27 #endif /* _PROTO_CLASS_H */ 47 template <class T> 48 class tScriptable : public Scriptable 49 { 50 tScriptable(const std::string& name, ClassID classID) 51 : Scriptable(name, classID) 52 { } 53 54 virtual void registerClass(Script* script) 55 { 56 Lunar<T>::Register(script); 57 } 58 virtual int insertObject(Script* L, BaseObject* obj, const std::string& name, bool gc=false) 59 { 60 Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), name, gc); 61 } 62 63 64 65 } 66 ; 67 68 69 #endif /* _SCRIPTABLE_H */ -
branches/script_engine/src/lib/util/loading/resource.cc
r7195 r8193 26 26 Resource::Resource (const std::string& fileName) 27 27 { 28 this->setClassID(CL_RESOURCE, "Resource");28 // this->setClassID(CL_RESOURCE, "Resource"); 29 29 30 30 }
Note: See TracChangeset
for help on using the changeset viewer.