Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8408 in orxonox.OLD for trunk/src/world_entities


Ignore:
Timestamp:
Jun 14, 2006, 5:50:18 PM (19 years ago)
Author:
bensch
Message:

trunk: merged the script_engine branche back here
merged with command
svn merge https://svn.orxonox.net/orxonox/branches/script_engine . -r8284:HEAD
no conflicts

Location:
trunk/src/world_entities
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/script_trigger.cc

    r8271 r8408  
    11//for testing
    22#include "luaincl.h"
     3
    34#include "script_trigger.h"
    45#include "class_list.h"
     
    67
    78#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 */
    1117ScriptTrigger::ScriptTrigger(const TiXmlElement* root)
    1218{
     19  this->setClassID(CL_SCRIPT_TRIGGER, "ScriptTrigger");
     20  this->toList(OM_COMMON);
     21
     22  doDebugDraw = false;
    1323  scriptCalled = false;
    1424  scriptIsOk = false;
    1525  loadParams(root);
    1626
    17 
    18 }
    19 
     27}
     28
     29/**
     30 * Deletes the ScriptTrigger.
     31 *
     32 */
    2033ScriptTrigger::~ScriptTrigger()
    2134{
     
    2336}
    2437
     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 */
    2543void ScriptTrigger::loadParams(const TiXmlElement* root)
    2644{
     
    5371        .describe("True if the script shoul only be called once")
    5472        .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 */
    6085void ScriptTrigger::setTarget(const std::string& target)
    6186{
     
    7297}
    7398
     99/**
     100 * Sets the parent of the trigger.
     101 * @param parent The parrent.
     102 */
    74103void ScriptTrigger::setTriggerParent(const std::string& parent)
    75104{
     
    89118void ScriptTrigger::tick(float timestep)
    90119{
    91   printf("SCRIPTTRIGGER: tick called\n");
    92  if((this->getAbsDirV()-target->getAbsDirV()).len() < radius)
     120
     121  if( this->distance(target) < radius)
    93122 {
    94123  if(!callOnce)
     
    102131  }
    103132 }
     133 //else
     134   //printf("SCRIPTTRIGGER: target out of range\n");
    104135
    105136}
     
    111142     {
    112143       testScriptingFramework();
    113      if(!(script->selectFunction(this->functionName,0)) )
     144     /*if(!(script->selectFunction(this->functionName,0)) )
    114145       printf("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
    115146     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());*/
    117148     }
    118149}
     
    121152void ScriptTrigger::setScript(const std::string& file)
    122153{
     154
    123155  ScriptManager* scriptManager = State::getScriptManager();
    124156  if (scriptManager != NULL)
    125157  {
     158
    126159    script = scriptManager->getScriptByFile(file);
    127160    if(script != NULL)
     161    {
    128162      scriptIsOk = true;
     163    }
    129164  }
    130165}
     
    134169 {
    135170   std::string file("lunartest2.lua");
    136      // Script script;
     171   //get script
    137172   Script* script = State::getScriptManager()->getScriptByFile(file);
    138173   printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState()));
    139 
    140       // Register classes with the script
    141       // 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 script
    149       //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 file
    155       //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()));
    160174
    161175      //execute a function
     
    166180
    167181   script->pushParam(3.14159,main);
     182   printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState()));
    168183   script->executeFunction();
    169184
    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);
    173187
    174188   if(script->getReturnedBool())
     
    177191     printf("main returned false\n");
    178192
    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()));
    183198      //execute a 2nd function
    184199   printf("----------- test -----------\n");
  • trunk/src/world_entities/script_trigger.h

    r8271 r8408  
    3434    void setScript(const std::string& file);
    3535    void setFunction(const std::string& function){ this->functionName = function; }
    36    
     36    void setDebugDraw(const bool draw) { this->doDebugDraw = draw; }
     37
    3738    ///DRAWING
    38     void draw()const{this->debugDraw();};
     39    void draw()const{if(doDebugDraw)this->debugDraw();};
    3940
    4041  private:
     
    4647    Script*      script;
    4748    std::string  functionName;
     49    bool         doDebugDraw;
    4850
    4951    //for internal use
  • trunk/src/world_entities/space_ships/helicopter.cc

    r8362 r8408  
    3535
    3636CREATE_FACTORY(Helicopter, CL_HELICOPTER);
     37#include "script_class.h"
     38//CREATE_SCRIPTABLE_CLASS(Helicopter, CL_HELICOPTER, NULL);
     39
    3740
    3841/**
  • trunk/src/world_entities/space_ships/helicopter.h

    r7810 r8408  
    3737
    3838    virtual void process(const Event &event);
     39   
     40    virtual void moveUp(bool move){bUp = move;};
    3941
    4042
     
    7880};
    7981
     82//CREATE_SCRIPTABLE_CLASS(Helicopter, CL_HELICOPTER,
     83                       // addMethod("moveUp", ExecutorLua1<Object,bool>(&Helicopter::moveUp))
     84                       // );
     85
     86
    8087#endif /* _HELICOPTERS_H */
Note: See TracChangeset for help on using the changeset viewer.