Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8711 in orxonox.OLD


Ignore:
Timestamp:
Jun 22, 2006, 1:09:20 PM (18 years ago)
Author:
bensch
Message:

merged the script_engine back here

Location:
trunk/src
Files:
1 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/class_id.h

    r8619 r8711  
    222222  // Testing Entities
    223223  CL_TEST_ENTITY                =    0x00000409,
    224   CL_ACCOUNT                    =    0x00000410,
    225   CL_TEST_OBJECT                =    0x00000411,
    226224
    227225  // misc
  • trunk/src/lib/coord/p_node.h

    r8490 r8711  
    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  /** @returns the absolute position */
    106113  inline const Vector& getLastAbsCoor () const { return this->lastAbsCoordinate; };
     114 
    107115  void shiftCoor (const Vector& shift);
    108116  void shiftCoor (float x, float y, float z) { this->shiftCoor(Vector(x, y, z)); };
  • trunk/src/lib/gui/gl/glgui_handler.cc

    r8450 r8711  
    2323
    2424#include "class_list.h"
     25#include <cassert>
    2526
    2627#include <cassert>
  • trunk/src/lib/script_engine/Makefile.am

    r8408 r8711  
    1616                script_manager.cc \
    1717                script_class.cc \
    18                 script_method.cc \
    19                 \
    20                 account.cc \
    21                 object.cc
    22 
    23 
     18                script_method.cc
     19               
    2420AM_CPPFLAGS= @LUA_INCLUDES@
    2521
  • trunk/src/lib/script_engine/lunartest2.lua

    r8408 r8711  
    2222
    2323function main(arg)
    24   io.write("hello i am main!")
     24  io.write("hello i am main!\n")
    2525  -- use parameter
    2626  io.write("main received ", arg)
    2727  io.write(" as parameter\n")
    2828
    29  o = Object()
    30   o:printName()
     29 
    3130  --call member of an inserted object
    3231  Obj:printName()
    3332
    3433  --create object of a registered type
    35   --o = Object()
    36   --o:printName()
     34  o = Object()
     35  o:printName()
    3736
    3837  --take returnvalue from c
  • trunk/src/lib/script_engine/script.cc

    r8408 r8711  
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2004 orx
     5
     6   This program is free software; you can redistribute it and/or modify
     7   it under the terms of the GNU General Public License as published by
     8   the Free Software Foundation; either version 2, or (at your option)
     9   any later version.
     10
     11### File Specific:
     12   main-programmer: Silvan Nellen
     13   co-programmer: Benjamin Grauer
     14*/
     15
    116#include "script.h"
    217#include "script_class.h"
    318#include "luaincl.h"
    419
     20#include "util/loading/resource_manager.h"
    521
    622#include "loading/load_param.h"
     
    5874 {
    5975
     76   std::string filedest(ResourceManager::getInstance()->getDataDir());
     77   filedest += "scripts/" + filename;
     78   
    6079   if(currentFile.length() != 0)
    6180   {
     
    6483    }
    6584
    66    int error = luaL_loadfile (luaState, filename.c_str());
     85   int error = luaL_loadfile (luaState, filedest.c_str());
    6786
    6887   if(error == 0)
    6988   {
     89     
    7090     error = lua_pcall(luaState, 0, 0, 0);
    7191
     
    192212 bool Script::pushParam(int param, std::string& toFunction)
    193213 {
    194    if(currentFunction.compare(toFunction) == 0)
     214   if(currentFunction == toFunction)
    195215   {
    196216     lua_pushnumber(luaState, (lua_Number) param);
    197217     argumentCount++;
    198     return true;
     218     return true;
    199219   }
    200220   else
     
    267287       returnCount--;
    268288     }
     289     else
     290       printf("ERROR: Form %s : trying to retreive non bolean value",this->currentFile.c_str());
    269291   }
    270292   return returnValue;
     
    313335 }
    314336
     337 bool Script::registerStandartClasses()
     338 {
     339   bool success = false;
     340   
     341   //success = this->registerClass(std::string("Vector"));
     342   
     343   return success;
     344 }
     345 
     346 
     347 bool Script::registerClass( const std::string& className)
     348 {
     349   BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
     350   //printf("The script class for %s is at %p \n",className.c_str(),scriptClass);
     351   WorldObject tmpObj;
     352   if (scriptClass != NULL)
     353   {
     354     tmpObj.type = className;
     355     if( !classIsRegistered(className) )
     356     {
     357       static_cast<ScriptClass*>(scriptClass)->registerClass(this);
     358       tmpObj.name = "";
     359       registeredObjects.push_back(tmpObj);
     360       return true;
     361     }
     362   }
     363   return false;
     364 
     365 }
    315366
    316367 bool Script::classIsRegistered(const std::string& type)
  • trunk/src/lib/script_engine/script.h

    r8408 r8711  
     1/*!
     2 * @file scrip.h
     3 *  wrapper for a lua_State
     4 */
     5
    16#ifndef _SCRIPT_H
    27#define _SCRIPT_H
     
    5863
    5964    int  reportError(int error);                      //!< Get errormessage from the lua stack and print it.
     65    bool registerStandartClasses();                   //!< Register all the classes that the script might need
     66    bool registerClass(const std::string& className); //!< Register a class but dont add any instances
    6067    bool classIsRegistered(const std::string& type);  //!< Checks wheter the class "type" has already been registered with the script
    6168    bool objectIsAdded(const std::string& name);      //!< Checks wheter the object "name" has already been added to the script
  • trunk/src/lib/script_engine/script_class.cc

    r8408 r8711  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
    1414*/
  • trunk/src/lib/script_engine/script_manager.cc

    r8408 r8711  
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2004 orx
     5
     6   This program is free software; you can redistribute it and/or modify
     7   it under the terms of the GNU General Public License as published by
     8   the Free Software Foundation; either version 2, or (at your option)
     9   any later version.
     10
     11### File Specific:
     12   main-programmer: Silvan Nellen
     13   co-programmer: Benjamin Grauer
     14*/
     15
     16
    117#include <string>
    218#include <list>
  • trunk/src/lib/script_engine/script_manager.h

    r8271 r8711  
     1/*!
     2 * @file scrip_manager.h
     3 *  manages the scripts
     4 */
     5
    16#ifndef _SCRIPT_MANAGER_H
    27#define _SCRIPT_MANAGER_H
  • trunk/src/lib/script_engine/script_method.cc

    r8413 r8711  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
    1414*/
  • trunk/src/lib/script_engine/script_method.h

    r8413 r8711  
    11/*!
    2  * @file script_class.h
     2 * @file script_method.h
    33 * @brief Definition of ...
    44*/
  • trunk/src/lib/util/executor/executor_lua.h

    r8527 r8711  
    182182
    183183
     184///////////
     185//// 3 ////
     186///////////
     187//! Executes a Function with a lua_State* parameter.
     188template<class T, typename type0, typename type1, typename type2> class ExecutorLua3 : public Executor
     189{
     190  public:
     191    /**
     192   * @brief Constructor of a ExecutorXML
     193   * @param function a Function to call
     194     */
     195    ExecutorLua3(void(T::*function)(type0, type1, type2))
     196  : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>())
     197    {
     198      this->functionPointer = function;
     199      this->functorType = Executor_Objective | Executor_NoLoadString;
     200    }
     201
     202    /**
     203     * @brief executes the Command on BaseObject
     204     * @param object the BaseObject to execute this Executor on
     205     * @param loadString ignored in this case
     206     */
     207    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
     208    {
     209      PRINTF(1)("no usefull executor\n");
     210    }
     211
     212    virtual void operator()(BaseObject* object, int& count, void* values) const
     213    {
     214      lua_State* state = (lua_State*)values;
     215      count = 0;
     216
     217      (dynamic_cast<T*>(object)->*(functionPointer))(
     218          fromLua<type0>(state, 1),
     219          fromLua<type1>(state, 2),
     220          fromLua<type2>(state, 3) );
     221    }
     222
     223    /**
     224     * @returns a _new_ Copy of this Executor
     225     */
     226    virtual Executor* clone () const
     227    {
     228      return new ExecutorLua3<T, type0, type1, type2>(this->functionPointer);
     229    }
     230  private:
     231    void          (T::*functionPointer)(type0, type1, type2);
     232};
     233
    184234
    185235
     
    209259      this->functorType = Executor_Objective | Executor_NoLoadString;
    210260    }
    211 
     261   
    212262    /**
    213263     * @brief executes the Command on BaseObject
  • trunk/src/story_entities/game_world.cc

    r8490 r8711  
    142142}
    143143
    144 #include "account.cc"
    145 #include "object.cc"
    146144/**
    147145 *  loads the GameWorld by initializing all resources, and set their default values.
     
    187185
    188186  //remove this after finished testing !!!!
    189   Object* obj= new Object();
    190   obj->setName("Obj");
    191   Account* a = new Account();
    192   a->setName("a");
    193   Account *b = new Account(30);
    194   b->setName("b");
    195  
     187  //Object* obj= new Object();
     188  //obj->setName("Obj");
     189  //Account* a = new Account();
     190  //a->setName("a");
     191  //Account *b = new Account(30);
     192  //b->setName("b");
    196193 
    197194  LoadParamXML(root, "ScriptManager", &this->scriptManager, ScriptManager, loadParams);
  • trunk/src/world_entities/script_trigger.cc

    r8408 r8711  
    1 //for testing
    2 #include "luaincl.h"
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2004 orx
     5
     6   This program is free software; you can redistribute it and/or modify
     7   it under the terms of the GNU General Public License as published by
     8   the Free Software Foundation; either version 2, or (at your option)
     9   any later version.
     10
     11### File Specific:
     12   main-programmer: Silvan Nellen
     13   co-programmer: ...
     14*/
     15
    316
    417#include "script_trigger.h"
     
    2033  this->toList(OM_COMMON);
    2134
     35  returnCount = 1;
     36  actionFinished = false;
    2237  doDebugDraw = false;
     38  invert = false;
    2339  scriptCalled = false;
    2440  scriptIsOk = false;
     41  triggerLasts = false;
    2542  loadParams(root);
    2643
     
    7188        .describe("True if the script shoul only be called once")
    7289        .defaultValues("");
     90    LoadParam(root, "invert", this, ScriptTrigger, setInvert)
     91        .describe("")
     92        .defaultValues("");
     93    LoadParam(root, "triggerlasts", this, ScriptTrigger, setTriggerLasts)
     94        .describe("")
     95        .defaultValues("");
    7396    LoadParam(root, "debugdraw", this, ScriptTrigger, setDebugDraw)
    7497        .describe("True if the script should only be called once")
     
    118141void ScriptTrigger::tick(float timestep)
    119142{
    120 
    121   if( this->distance(target) < radius)
     143  if(actionFinished) return;
     144
     145  if(triggerLasts && scriptCalled)
     146  {
     147    executeAction(timestep);
     148    return;
     149  }
     150 
     151  if( !invert && this->distance(target) < radius)
    122152 {
    123153  if(!callOnce)
    124154   {
    125     executeAction();
     155    executeAction(timestep);
     156    scriptCalled = true;
    126157   }
    127158  else if(callOnce && !scriptCalled)
    128159  {
    129    executeAction();
     160   executeAction(timestep);
    130161   scriptCalled = true;
    131162  }
     163 
     164 }
     165 else if( invert && this->distance(target) > radius)
     166 {
     167   if(!callOnce)
     168   {
     169     executeAction(timestep);
     170   }
     171   else if(callOnce && !scriptCalled)
     172   {
     173     executeAction(timestep);
     174     scriptCalled = true;
     175   }
     176   
    132177 }
    133178 //else
     
    137182
    138183
    139 void ScriptTrigger::executeAction()
     184void ScriptTrigger::executeAction(float timestep)
    140185{
    141186     if(scriptIsOk)
    142187     {
    143        testScriptingFramework();
    144      /*if(!(script->selectFunction(this->functionName,0)) )
     188       //testScriptingFramework();
     189     if(!(script->selectFunction(this->functionName,returnCount)) )
    145190       printf("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
     191     
     192     script->pushParam( timestep, this->functionName);
     193     
    146194     if( !(script->executeFunction()) )
    147        printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());*/
     195       printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
     196     
     197     actionFinished = script->getReturnedBool();
    148198     }
     199     
     200     
    149201}
    150202
     
    165217}
    166218
    167 
     219/*
    168220 void ScriptTrigger::testScriptingFramework()
    169221 {
     
    208260   printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState()));
    209261
    210  }
     262}*/
  • trunk/src/world_entities/script_trigger.h

    r8408 r8711  
     1/*!
     2 * @file scrip_trigger.h
     3 *  triggeres a script
     4 */
     5
    16#ifndef _SCRIPT_TRIGGER_H
    27#define _SCRIPT_TRIGGER_H
     
    2227    /// DO WORK
    2328    virtual void tick(float timestep);
    24     virtual void executeAction();
     29    virtual void executeAction(float timestep);
    2530    void testScriptingFramework();
    2631
     
    3035    void setTriggerParent(const std::string& name);
    3136    void setCallOnce(const bool call) { this->callOnce = call; }
     37    void setTriggerLasts(const bool lasts) { this->triggerLasts = lasts; }
     38    void setInvert(const bool inv) { this->invert = invert; }
    3239    void setRadius(const float radius) { if(radius>0) this->radius = radius; }
    3340    void setDelay(const float time){if(delay>0) this->delay = delay; }
    3441    void setScript(const std::string& file);
    35     void setFunction(const std::string& function){ this->functionName = function; }
     42    void setFunction(const std::string& function){ this->functionName = function;}
    3643    void setDebugDraw(const bool draw) { this->doDebugDraw = draw; }
    3744
     
    4350    WorldEntity* target;
    4451    bool         callOnce;
     52    bool         triggerLasts;
     53    bool         invert;
    4554    float        radius;
    4655    float        delay;
     
    5261    bool         scriptCalled;
    5362    bool         scriptIsOk;
     63    bool         actionFinished;
     64    int          returnCount;        //TODO: set return count correctly
    5465
    5566};
  • trunk/src/world_entities/space_ships/helicopter.h

    r8408 r8711  
    1212#include "sound_buffer.h"
    1313#include "sound_source.h"
     14
     15#include "script_class.h"
    1416
    1517class Helicopter : public Playable
     
    3840    virtual void process(const Event &event);
    3941   
    40     virtual void moveUp(bool move){bUp = move;};
     42    virtual void moveUp(bool move){bAscend = move;};
     43    virtual void moveDown(bool move){bDescend = move;};
    4144
    4245
     
    8083};
    8184
    82 //CREATE_SCRIPTABLE_CLASS(Helicopter, CL_HELICOPTER,
    83                        // addMethod("moveUp", ExecutorLua1<Object,bool>(&Helicopter::moveUp))
    84                        // );
     85CREATE_SCRIPTABLE_CLASS(Helicopter, CL_HELICOPTER,
     86                        addMethod("moveUp", ExecutorLua1<Helicopter,bool>(&Helicopter::moveUp))
     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                           
     93                        );
    8594
    8695
Note: See TracChangeset for help on using the changeset viewer.