Changeset 8408 in orxonox.OLD for trunk/src/world_entities
- Timestamp:
- Jun 14, 2006, 5:50:18 PM (19 years ago)
- Location:
- trunk/src/world_entities
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/script_trigger.cc
r8271 r8408 1 1 //for testing 2 2 #include "luaincl.h" 3 3 4 #include "script_trigger.h" 4 5 #include "class_list.h" … … 6 7 7 8 #include "state.h" 8 9 10 9 10 11 12 /** 13 * Constructs a new ScriptTrigger. 14 * @param root the xml element to load the parameters from. 15 * 16 */ 11 17 ScriptTrigger::ScriptTrigger(const TiXmlElement* root) 12 18 { 19 this->setClassID(CL_SCRIPT_TRIGGER, "ScriptTrigger"); 20 this->toList(OM_COMMON); 21 22 doDebugDraw = false; 13 23 scriptCalled = false; 14 24 scriptIsOk = false; 15 25 loadParams(root); 16 26 17 18 } 19 27 } 28 29 /** 30 * Deletes the ScriptTrigger. 31 * 32 */ 20 33 ScriptTrigger::~ScriptTrigger() 21 34 { … … 23 36 } 24 37 38 /** 39 * Reads the values from the tml element and sets them. 40 * @param root the xml element to load the parameters from. 41 * 42 */ 25 43 void ScriptTrigger::loadParams(const TiXmlElement* root) 26 44 { … … 53 71 .describe("True if the script shoul only be called once") 54 72 .defaultValues(""); 55 } 56 57 } 58 59 73 LoadParam(root, "debugdraw", this, ScriptTrigger, setDebugDraw) 74 .describe("True if the script should only be called once") 75 .defaultValues(""); 76 } 77 78 } 79 80 81 /** 82 * Sets the target(a world entity) of the ScriptTrigger. If the distance between the target and this trigger is smaller than the radius, the script gets triggered. 83 * @param target The worldentity that the script supervises. 84 */ 60 85 void ScriptTrigger::setTarget(const std::string& target) 61 86 { … … 72 97 } 73 98 99 /** 100 * Sets the parent of the trigger. 101 * @param parent The parrent. 102 */ 74 103 void ScriptTrigger::setTriggerParent(const std::string& parent) 75 104 { … … 89 118 void ScriptTrigger::tick(float timestep) 90 119 { 91 printf("SCRIPTTRIGGER: tick called\n"); 92 if((this->getAbsDirV()-target->getAbsDirV()).len() < radius)120 121 if( this->distance(target) < radius) 93 122 { 94 123 if(!callOnce) … … 102 131 } 103 132 } 133 //else 134 //printf("SCRIPTTRIGGER: target out of range\n"); 104 135 105 136 } … … 111 142 { 112 143 testScriptingFramework(); 113 if(!(script->selectFunction(this->functionName,0)) )144 /*if(!(script->selectFunction(this->functionName,0)) ) 114 145 printf("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str()); 115 146 if( !(script->executeFunction()) ) 116 printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str()); 147 printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());*/ 117 148 } 118 149 } … … 121 152 void ScriptTrigger::setScript(const std::string& file) 122 153 { 154 123 155 ScriptManager* scriptManager = State::getScriptManager(); 124 156 if (scriptManager != NULL) 125 157 { 158 126 159 script = scriptManager->getScriptByFile(file); 127 160 if(script != NULL) 161 { 128 162 scriptIsOk = true; 163 } 129 164 } 130 165 } … … 134 169 { 135 170 std::string file("lunartest2.lua"); 136 // Script script;171 //get script 137 172 Script* script = State::getScriptManager()->getScriptByFile(file); 138 173 printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState())); 139 140 // Register classes with the script141 // Lunar<Account>::Register(&script);142 //Lunar<Object>::Register(&script);143 144 //Object* obj= new Object();145 //Account a;146 //Account *b = new Account(30);147 148 // Add instances to the script149 //Lunar<Object>::insertObject(&script,obj,"Obj",true);150 //Lunar<Account>::insertObject(&script,&a,"a",false);151 //Lunar<Account>::insertObject(&script,b,"b",true);152 //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));153 154 //Load a file155 //std::string file("lunartest2.lua");156 157 //if(script.loadFile(file))158 //printf("File %s succefully loaded\n", file.c_str());159 //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));160 174 161 175 //execute a function … … 166 180 167 181 script->pushParam(3.14159,main); 182 printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState())); 168 183 script->executeFunction(); 169 184 170 float retf = script->getReturnedFloat(); 171 printf("main returned %f\n",retf); 172 185 int ret = script->getReturnedInt(); 186 printf("main returned %i\n",ret); 173 187 174 188 if(script->getReturnedBool()) … … 177 191 printf("main returned false\n"); 178 192 179 int ret = script->getReturnedInt(); 180 printf("main returned %i\n",ret); 181 182 //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState())); 193 float retf = script->getReturnedFloat(); 194 printf("main returned %f\n",retf); 195 196 197 printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState())); 183 198 //execute a 2nd function 184 199 printf("----------- test -----------\n"); -
trunk/src/world_entities/script_trigger.h
r8271 r8408 34 34 void setScript(const std::string& file); 35 35 void setFunction(const std::string& function){ this->functionName = function; } 36 36 void setDebugDraw(const bool draw) { this->doDebugDraw = draw; } 37 37 38 ///DRAWING 38 void draw()const{ this->debugDraw();};39 void draw()const{if(doDebugDraw)this->debugDraw();}; 39 40 40 41 private: … … 46 47 Script* script; 47 48 std::string functionName; 49 bool doDebugDraw; 48 50 49 51 //for internal use -
trunk/src/world_entities/space_ships/helicopter.cc
r8362 r8408 35 35 36 36 CREATE_FACTORY(Helicopter, CL_HELICOPTER); 37 #include "script_class.h" 38 //CREATE_SCRIPTABLE_CLASS(Helicopter, CL_HELICOPTER, NULL); 39 37 40 38 41 /** -
trunk/src/world_entities/space_ships/helicopter.h
r7810 r8408 37 37 38 38 virtual void process(const Event &event); 39 40 virtual void moveUp(bool move){bUp = move;}; 39 41 40 42 … … 78 80 }; 79 81 82 //CREATE_SCRIPTABLE_CLASS(Helicopter, CL_HELICOPTER, 83 // addMethod("moveUp", ExecutorLua1<Object,bool>(&Helicopter::moveUp)) 84 // ); 85 86 80 87 #endif /* _HELICOPTERS_H */
Note: See TracChangeset
for help on using the changeset viewer.