Changeset 8485 in orxonox.OLD for branches/script_engine/src
- Timestamp:
- Jun 15, 2006, 5:33:25 PM (18 years ago)
- Location:
- branches/script_engine/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/coord/p_node.h
r8186 r8485 103 103 /** @returns the absolute position */ 104 104 inline const Vector& getAbsCoor () const { return this->absCoordinate; }; 105 /** @returns the absolute X coordinate. */ 106 inline float getAbsCoorX() { return this->absCoordinate.x; }; 107 /** @returns the absolute Y Coordinate */ 108 inline float getAbsCoorY() { return this->absCoordinate.y; }; 109 /** @returns the absolute Z Coordinate */ 110 inline float getAbsCoorZ() { return this->absCoordinate.z; }; 111 105 112 void shiftCoor (const Vector& shift); 106 113 void shiftCoor (float x, float y, float z) { this->shiftCoor(Vector(x, y, z)); }; -
branches/script_engine/src/lib/script_engine/script.cc
r8408 r8485 192 192 bool Script::pushParam(int param, std::string& toFunction) 193 193 { 194 if(currentFunction .compare(toFunction) == 0)194 if(currentFunction == toFunction) 195 195 { 196 196 lua_pushnumber(luaState, (lua_Number) param); … … 267 267 returnCount--; 268 268 } 269 else 270 printf("ERROR: Form %s : trying to retreive non bolean value",this->currentFile.c_str()); 269 271 } 270 272 return returnValue; … … 313 315 } 314 316 317 bool Script::registerStandartClasses() 318 { 319 bool success = false; 320 321 //success = this->registerClass(std::string("Vector")); 322 323 return success; 324 } 325 326 327 bool Script::registerClass( const std::string& className) 328 { 329 BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS); 330 //printf("The script class for %s is at %p \n",className.c_str(),scriptClass); 331 WorldObject tmpObj; 332 if (scriptClass != NULL) 333 { 334 tmpObj.type = className; 335 if( !classIsRegistered(className) ) 336 { 337 static_cast<ScriptClass*>(scriptClass)->registerClass(this); 338 tmpObj.name = ""; 339 registeredObjects.push_back(tmpObj); 340 return true; 341 } 342 } 343 return false; 344 345 } 315 346 316 347 bool Script::classIsRegistered(const std::string& type) -
branches/script_engine/src/lib/script_engine/script.h
r8408 r8485 58 58 59 59 int reportError(int error); //!< Get errormessage from the lua stack and print it. 60 bool registerStandartClasses(); //!< Register all the classes that the script might need 61 bool registerClass(const std::string& className); //!< Register a class but dont add any instances 60 62 bool classIsRegistered(const std::string& type); //!< Checks wheter the class "type" has already been registered with the script 61 63 bool objectIsAdded(const std::string& name); //!< Checks wheter the object "name" has already been added to the script -
branches/script_engine/src/lib/util/executor/executor_lua.h
r8408 r8485 183 183 184 184 185 /////////// 186 //// 3 //// 187 /////////// 188 //! Executes a Function with a lua_State* parameter. 189 template<class T, typename type0, typename type1, typename type2> class ExecutorLua3 : public Executor 190 { 191 public: 192 /** 193 * @brief Constructor of a ExecutorXML 194 * @param function a Function to call 195 */ 196 ExecutorLua3(void(T::*function)(type0, type1, type2)) 197 : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>()) 198 { 199 this->functionPointer = function; 200 this->functorType = Executor_Objective | Executor_NoLoadString; 201 } 202 203 /** 204 * @brief executes the Command on BaseObject 205 * @param object the BaseObject to execute this Executor on 206 * @param loadString ignored in this case 207 */ 208 virtual void operator()(BaseObject* object, const SubString& = SubString()) const 209 { 210 PRINTF(1)("no usefull executor\n"); 211 } 212 213 virtual void operator()(BaseObject* object, int& count, void* values) const 214 { 215 lua_State* state = (lua_State*)values; 216 count = 0; 217 218 (dynamic_cast<T*>(object)->*(functionPointer))( 219 fromLua<type0>(state, 1), 220 fromLua<type1>(state, 2), 221 fromLua<type2>(state, 3) ); 222 } 223 224 /** 225 * @returns a _new_ Copy of this Executor 226 */ 227 virtual Executor* clone () const 228 { 229 return new ExecutorLua3<T, type0, type1, type2>(this->functionPointer); 230 } 231 private: 232 void (T::*functionPointer)(type0, type1, type2); 233 }; 234 185 235 186 236 … … 210 260 this->functorType = Executor_Objective | Executor_NoLoadString; 211 261 } 212 262 213 263 /** 214 264 * @brief executes the Command on BaseObject -
branches/script_engine/src/world_entities/script_trigger.cc
r8417 r8485 20 20 this->toList(OM_COMMON); 21 21 22 returnCount = 1; 23 actionFinished = false; 22 24 doDebugDraw = false; 25 invert = false; 23 26 scriptCalled = false; 24 27 scriptIsOk = false; 28 triggerLasts = false; 25 29 loadParams(root); 26 30 … … 71 75 .describe("True if the script shoul only be called once") 72 76 .defaultValues(""); 77 LoadParam(root, "invert", this, ScriptTrigger, setInvert) 78 .describe("") 79 .defaultValues(""); 80 LoadParam(root, "triggerlasts", this, ScriptTrigger, setTriggerLasts) 81 .describe("") 82 .defaultValues(""); 73 83 LoadParam(root, "debugdraw", this, ScriptTrigger, setDebugDraw) 74 84 .describe("True if the script should only be called once") … … 118 128 void ScriptTrigger::tick(float timestep) 119 129 { 120 121 if( this->distance(target) < radius) 130 if(actionFinished) return; 131 132 if(triggerLasts && scriptCalled) 133 { 134 executeAction(timestep); 135 return; 136 } 137 138 139 if( !invert && this->distance(target) < radius) 122 140 { 123 141 if(!callOnce) 124 142 { 125 executeAction(); 143 executeAction(timestep); 144 scriptCalled = true; 126 145 } 127 146 else if(callOnce && !scriptCalled) 128 147 { 129 executeAction( );148 executeAction(timestep); 130 149 scriptCalled = true; 131 150 } 151 152 } 153 else if( invert && this->distance(target) > radius) 154 { 155 if(!callOnce) 156 { 157 executeAction(timestep); 158 } 159 else if(callOnce && !scriptCalled) 160 { 161 executeAction(timestep); 162 scriptCalled = true; 163 } 164 132 165 } 133 166 //else … … 137 170 138 171 139 void ScriptTrigger::executeAction( )172 void ScriptTrigger::executeAction(float timestep) 140 173 { 141 174 if(scriptIsOk) 142 175 { 143 testScriptingFramework();144 if(!(script->selectFunction(this->functionName, 0)) )176 //testScriptingFramework(); 177 if(!(script->selectFunction(this->functionName,returnCount)) ) 145 178 printf("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str()); 179 180 script->pushParam( timestep, this->functionName); 181 146 182 if( !(script->executeFunction()) ) 147 183 printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str()); 148 184 } 185 186 actionFinished = script->getReturnedBool(); 149 187 } 150 188 -
branches/script_engine/src/world_entities/script_trigger.h
r8408 r8485 22 22 /// DO WORK 23 23 virtual void tick(float timestep); 24 virtual void executeAction( );24 virtual void executeAction(float timestep); 25 25 void testScriptingFramework(); 26 26 … … 30 30 void setTriggerParent(const std::string& name); 31 31 void setCallOnce(const bool call) { this->callOnce = call; } 32 void setTriggerLasts(const bool lasts) { this->triggerLasts = lasts; } 33 void setInvert(const bool inv) { this->invert = invert; } 32 34 void setRadius(const float radius) { if(radius>0) this->radius = radius; } 33 35 void setDelay(const float time){if(delay>0) this->delay = delay; } 34 36 void setScript(const std::string& file); 35 void setFunction(const std::string& function){ this->functionName = function; 37 void setFunction(const std::string& function){ this->functionName = function;} 36 38 void setDebugDraw(const bool draw) { this->doDebugDraw = draw; } 37 39 … … 43 45 WorldEntity* target; 44 46 bool callOnce; 47 bool triggerLasts; 48 bool invert; 45 49 float radius; 46 50 float delay; … … 52 56 bool scriptCalled; 53 57 bool scriptIsOk; 58 bool actionFinished; 59 int returnCount; 54 60 55 61 }; -
branches/script_engine/src/world_entities/space_ships/helicopter.h
r8417 r8485 86 86 addMethod("moveUp", ExecutorLua1<Helicopter,bool>(&Helicopter::moveUp)) 87 87 ->addMethod("moveDown", ExecutorLua1<Helicopter,bool>(&Helicopter::moveDown)) 88 ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor)) 89 ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX)) 90 ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY)) 91 ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ)) 92 88 93 ); 89 94
Note: See TracChangeset
for help on using the changeset viewer.