Changeset 8171 in orxonox.OLD for branches/script_engine/src/lib
- Timestamp:
- Jun 6, 2006, 9:18:31 AM (19 years ago)
- Location:
- branches/script_engine/src/lib/script_engine
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/script_manager.cc
r8170 r8171 18 18 } 19 19 20 ScriptManager* ScriptManager::getInstance()21 {22 23 if (!ScriptManager::singletonRef)24 ScriptManager::singletonRef = new ScriptManager();25 return ScriptManager::singletonRef;26 27 }28 20 29 21 void ScriptManager::loadParams(const TiXmlElement* root) … … 84 76 LOAD_PARAM_START_CYCLE(script, object); 85 77 { 86 LoadParam_CYCLE(object, "object", this, ScriptManager, addObjectToScript)87 .describe("The name of an object that is needed by a script");78 // LoadParam_CYCLE(object, "object", this, ScriptManager, addObjectToScript) 79 // .describe("The name of an object that is needed by a script"); 88 80 } 89 81 LOAD_PARAM_END_CYCLE(object); … … 96 88 } 97 89 90 91 } 92 93 94 Script* ScriptManager::getScriptByFile(std::string& file) 95 { 96 97 for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ ) 98 { 99 if( (*it).name.compare(file) == 0) 100 { 101 return &((*it).script); 102 } 103 } 104 return NULL; 98 105 99 106 } -
branches/script_engine/src/lib/script_engine/script_manager.h
r8170 r8171 25 25 ~ScriptManager(); 26 26 27 inline static ScriptManager* getInstance() ;27 inline static ScriptManager* getInstance(){if (!ScriptManager::singletonRef)ScriptManager::singletonRef = new ScriptManager();return ScriptManager::singletonRef;} 28 28 29 29 virtual void loadParams(const TiXmlElement* root); … … 33 33 34 34 void initScripts(); // initializes all scripts 35 Script* getScriptByFile(std::string& file); 35 36 36 37 private: -
branches/script_engine/src/lib/script_engine/script_trigger.cc
r8170 r8171 1 #include "script_trigger.h" 2 3 4 ScriptTrigger::ScriptTrigger() 5 { 6 scriptCalled = false; 7 } 8 9 ScriptTrigger::~ScriptTrigger() 10 { 11 12 } 13 14 void ScriptTrigger::loadParams(const TiXmlElement* root) 15 { 16 /* LoadParam(root, "file", this, ScriptTrigger, setScript) 17 .describe("the fileName of the script, that should be triggered by this script trigger") 18 .defaultValues(""); 19 LoadParam(root, "function", this, ScriptTrigger, setFunction) 20 .describe("the function of the script, that should be triggered by this script trigger") 21 .defaultValues(""); 22 LoadParam(root, "abs-coor", this, ScriptTrigger, setAbsCoord) 23 .describe("the fileName of the script, that should be triggered by this script trigger") 24 .defaultValues(""); 25 LoadParam(root, "radius", this, ScriptTrigger, setRadius) 26 .describe("the fileName of the script, that should be triggered by this script trigger") 27 .defaultValues(""); 28 */ 29 } 30 31 32 33 void ScriptTrigger::tick(float timestep) 34 { 35 36 if((this->getAbsDirV()-target->getAbsDirV()).len() < radius) 37 { 38 if(!callOnce) 39 { 40 executeAction(); 41 } 42 else if(callOnce && !scriptCalled) 43 { 44 executeAction(); 45 scriptCalled = true; 46 } 47 } 48 49 } 50 51 52 53 void ScriptTrigger::executeAction() 54 { 55 ScriptManager* scriptManager = ScriptManager::getInstance(); 56 Script* script = scriptManager->getScriptByFile(this->scriptFile); 57 if(!(script->selectFunction(this->functionName,0)) ) 58 printf("Error: Selection of %s in %s failed.\n",functionName.c_str(), scriptFile.c_str()); 59 if( !(script->executeFunction()) ) 60 printf("Execution of %s in %s failed\n",functionName.c_str(),scriptFile.c_str()); 61 } -
branches/script_engine/src/lib/script_engine/script_trigger.h
r8170 r8171 2 2 #define _SCRIPT_TRIGGER_H 3 3 4 #include <string> 5 4 6 #include "world_entity.h" 5 7 #include "loading/load_param.h" 8 #include "vector.h" 9 #include "script_manager.h" 6 10 7 11 class ScriptTrigger : public WorldEntity … … 12 16 13 17 virtual void loadParams(const TiXmlElement* root); 14 virtual voit tick(float timestep); 18 virtual void tick(float timestep); 19 virtual void executeAction(); 20 21 void setTarget(WorldEntity* target){ if(target!=NULL) this->target=target;} 22 void setCallOnce(bool call){this->callOnce = call;} 23 void setRadius(float radius){if(radius>0) this->radius = radius;} 24 void setScript(std::string& script){this->scriptFile = script;} 25 void setFunction(std::string& function){this->functionName = function;} 15 26 16 27 private:
Note: See TracChangeset
for help on using the changeset viewer.