Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8485 in orxonox.OLD for branches/script_engine


Ignore:
Timestamp:
Jun 15, 2006, 5:33:25 PM (19 years ago)
Author:
snellen
Message:

helicopter scripted

Location:
branches/script_engine/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/lib/coord/p_node.h

    r8186 r8485  
    103103  /** @returns the absolute position */
    104104  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 
    105112  void shiftCoor (const Vector& shift);
    106113  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  
    192192 bool Script::pushParam(int param, std::string& toFunction)
    193193 {
    194    if(currentFunction.compare(toFunction) == 0)
     194   if(currentFunction == toFunction)
    195195   {
    196196     lua_pushnumber(luaState, (lua_Number) param);
     
    267267       returnCount--;
    268268     }
     269     else
     270       printf("ERROR: Form %s : trying to retreive non bolean value",this->currentFile.c_str());
    269271   }
    270272   return returnValue;
     
    313315 }
    314316
     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 }
    315346
    316347 bool Script::classIsRegistered(const std::string& type)
  • branches/script_engine/src/lib/script_engine/script.h

    r8408 r8485  
    5858
    5959    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
    6062    bool classIsRegistered(const std::string& type);  //!< Checks wheter the class "type" has already been registered with the script
    6163    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  
    183183
    184184
     185///////////
     186//// 3 ////
     187///////////
     188//! Executes a Function with a lua_State* parameter.
     189template<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
    185235
    186236
     
    210260      this->functorType = Executor_Objective | Executor_NoLoadString;
    211261    }
    212 
     262   
    213263    /**
    214264     * @brief executes the Command on BaseObject
  • branches/script_engine/src/world_entities/script_trigger.cc

    r8417 r8485  
    2020  this->toList(OM_COMMON);
    2121
     22  returnCount = 1;
     23  actionFinished = false;
    2224  doDebugDraw = false;
     25  invert = false;
    2326  scriptCalled = false;
    2427  scriptIsOk = false;
     28  triggerLasts = false;
    2529  loadParams(root);
    2630
     
    7175        .describe("True if the script shoul only be called once")
    7276        .defaultValues("");
     77    LoadParam(root, "invert", this, ScriptTrigger, setInvert)
     78        .describe("")
     79        .defaultValues("");
     80    LoadParam(root, "triggerlasts", this, ScriptTrigger, setTriggerLasts)
     81        .describe("")
     82        .defaultValues("");
    7383    LoadParam(root, "debugdraw", this, ScriptTrigger, setDebugDraw)
    7484        .describe("True if the script should only be called once")
     
    118128void ScriptTrigger::tick(float timestep)
    119129{
    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)
    122140 {
    123141  if(!callOnce)
    124142   {
    125     executeAction();
     143    executeAction(timestep);
     144    scriptCalled = true;
    126145   }
    127146  else if(callOnce && !scriptCalled)
    128147  {
    129    executeAction();
     148   executeAction(timestep);
    130149   scriptCalled = true;
    131150  }
     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   
    132165 }
    133166 //else
     
    137170
    138171
    139 void ScriptTrigger::executeAction()
     172void ScriptTrigger::executeAction(float timestep)
    140173{
    141174     if(scriptIsOk)
    142175     {
    143        testScriptingFramework();
    144      if(!(script->selectFunction(this->functionName,0)) )
     176       //testScriptingFramework();
     177     if(!(script->selectFunction(this->functionName,returnCount)) )
    145178       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     
    146182     if( !(script->executeFunction()) )
    147183       printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
    148184     }
     185     
     186     actionFinished = script->getReturnedBool();
    149187}
    150188
  • branches/script_engine/src/world_entities/script_trigger.h

    r8408 r8485  
    2222    /// DO WORK
    2323    virtual void tick(float timestep);
    24     virtual void executeAction();
     24    virtual void executeAction(float timestep);
    2525    void testScriptingFramework();
    2626
     
    3030    void setTriggerParent(const std::string& name);
    3131    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; }
    3234    void setRadius(const float radius) { if(radius>0) this->radius = radius; }
    3335    void setDelay(const float time){if(delay>0) this->delay = delay; }
    3436    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;}
    3638    void setDebugDraw(const bool draw) { this->doDebugDraw = draw; }
    3739
     
    4345    WorldEntity* target;
    4446    bool         callOnce;
     47    bool         triggerLasts;
     48    bool         invert;
    4549    float        radius;
    4650    float        delay;
     
    5256    bool         scriptCalled;
    5357    bool         scriptIsOk;
     58    bool         actionFinished;
     59    int          returnCount;
    5460
    5561};
  • branches/script_engine/src/world_entities/space_ships/helicopter.h

    r8417 r8485  
    8686                        addMethod("moveUp", ExecutorLua1<Helicopter,bool>(&Helicopter::moveUp))
    8787                        ->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                           
    8893                        );
    8994
Note: See TracChangeset for help on using the changeset viewer.