Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8193 in orxonox.OLD


Ignore:
Timestamp:
Jun 7, 2006, 3:04:14 PM (18 years ago)
Author:
snellen
Message:

script_engine: swapping to integrate into the ORXONOX framework

Location:
branches/script_engine/src
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/defs/class_id.h

    r8035 r8193  
    8383
    8484  CL_WORLD_ENTITY               =    0x40000000,
    85 
    86   CL_RESOURCE                   =    0x80000000,
    8785
    8886  /// subsuper-classes
     
    238236  CL_AMMO_CONTAINER             =    0x00000604,
    239237  CL_HUD                        =    0x00000620,
     238 
     239 
     240  CL_SCRIPT_MANAGER             =    0x00000650,
     241  CL_SCRIPT                     =    0x00000651,
     242  CL_SCRIPTABLE                 =    0x00000652,
     243  CL_SCRIPT_TRIGGER             =    0x00000652,
    240244
    241245
  • branches/script_engine/src/lib/script_engine/Makefile.am

    r8170 r8193  
    1515                script.cc\
    1616                script_manager.cc\
     17                scriptable.cc \
    1718                script_trigger.cc
    1819
     
    2324                script.h\
    2425                script_manager.h\
     26                scriptable.h \
    2527                script_trigger.h
    2628
  • branches/script_engine/src/lib/script_engine/lunar.h

    r8101 r8193  
    33
    44#include <string>
     5#include <cassert>
    56#include "script.h"
    67
     
    140141      static int insertObject(Script* script, T* obj, const std::string& name, bool gc=false)
    141142      {
    142         if(script != NULL)
    143           return insertObject(script->getLuaState(), obj, name, gc);
    144 
    145 
     143        assert (script != NULL);
     144        return insertObject(script->getLuaState(), obj, name, gc);
    146145      }
    147146
  • branches/script_engine/src/lib/script_engine/script.cc

    r8134 r8193  
    11#include "script.h"
    2 
    3 
    4 Script::Script()
     2#include "loading/load_param.h"
     3
     4
     5Script::Script(const TiXmlElement* root)
    56{
     7  this->setClassID(CL_SCRIPT, "Script");
     8 
    69  returnCount = argumentCount = 0;
    710
     
    1417  luaopen_math(luaState);
    1518  luaopen_debug(luaState);
     19 
     20  if (root != NULL)
     21    this->loadParams(root);
    1622
    1723}
     
    2531
    2632
    27 bool Script::loadFile(std::string& filename)
     33void Script::loadParams(const TiXmlElement* root)
     34{
     35  LOAD_PARAM_START_CYCLE(root, objectElement);
     36  {
     37    LoadParam_CYCLE(objectElement, "object", this, Script, addObject)
     38        .describe("The name of an object that is needed by a script");
     39  }
     40  LOAD_PARAM_END_CYCLE(objectElement);
     41
     42
     43  LoadParam(root, "file", this, Script, loadFileNoRet)
     44      .describe("the fileName of the script, that should be loaded into this world")
     45      .defaultValues("");
     46}
     47
     48
     49
     50bool Script::loadFile(const std::string& filename)
    2851 {
    2952
     
    5982 }
    6083
     84 
     85 void Script::addObject(const std::string& className, const std::string& objectName)
     86 {
     87   
     88 }
     89
     90 
     91 
     92 
    6193 bool Script::executeFile()
    6294 {
  • branches/script_engine/src/lib/script_engine/script.h

    r8155 r8193  
    33
    44
    5 #include <string>
    65#include "base_object.h"
    76
     
    98
    109
    11 class Script
     10class Script : public BaseObject
    1211{
    1312  public:
    14     Script();
     13    Script(const TiXmlElement* root = NULL);
    1514    ~Script();
     15   
     16    /// LOADING
     17    void loadParams(const TiXmlElement* root);
    1618
    17     bool loadFile(std::string& filename);
    18     std::string getFileName(){return currentFile;}
    19     bool executeFile();
     19    void loadFileNoRet(const std::string& filename) { loadFile(filename); };
     20    bool loadFile(const std::string& filename);
     21    /** @returns fileName */
     22    std::string getFileName() { return currentFile; }
    2023
    21     lua_State* getLuaState() const{return luaState;}
     24    void addObject(const std::string& className, const std::string& objectName);
     25   
     26       
    2227
     28    lua_State* getLuaState() const { return luaState; }
     29
     30
     31   
     32    /// EXECUTING
     33    // first select function
    2334    bool selectFunction(std::string& functionName, int retCount);
    24     bool executeFunction();
     35
    2536    // push parameters for luafunction
    2637    bool  pushParam(int param, std::string& toFunction);
    2738    bool  pushParam(float param, std::string& toFunction);
    2839    bool  pushParam(double param, std::string& toFunction);
    29     // get returned values the last return value in lua is the first in c. TODO: change order of return
     40
     41    // Execute the Function
     42    bool executeFunction();
     43   
     44     // get returned values the last return value in lua is the first in c. TODO: change order of return
    3045    int   getReturnedInt();
    3146    bool  getReturnedBool();
     
    3348    void  getReturnedString(std::string& string);
    3449
     50    bool executeFile();
    3551
    3652  private:
     
    4662
    4763
    48 
    4964};
    5065#endif /* _SCRIPT_H */
  • branches/script_engine/src/lib/script_engine/script_manager.cc

    r8178 r8193  
    3131   }
    3232
    33   const TiXmlElement* scripts = root->FirstChildElement("Scripts");
    34 
    35   if( scripts == NULL)
    36   {
    37     PRINTF(1)("ScriptManager is missing 'Scripts'\n");
    38   }
    39   else
    40   {
    41     createScriptList(scripts);
    42   }
    43 
    44 
     33   
     34   LoadParamXML(root, "Scripts", this, ScriptManager, createScriptList);
    4535}
    4636
     
    5040
    5141
    52 void ScriptManager::initScripts()
    53 {
    54   for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ )
    55   {
    56     (*it).script.loadFile((*it).name);
    57   }
    58 }
    59 
    6042void ScriptManager::init()
    6143{
    62   currentWorld.assign("");
    6344
    6445}
     
    6748void  ScriptManager::createScriptList(const TiXmlElement* scripts)
    6849{
     50 
     51  LOAD_PARAM_START_CYCLE(scripts, object);
     52  {
     53    new Script(object);
     54  }
     55  LOAD_PARAM_END_CYCLE(object);
     56     
     57     
     58  /*
    6959  const TiXmlElement* script = scripts->FirstChildElement();
    7060
     
    9484    script = script->NextSiblingElement("Script");
    9585
    96   }
     86  }*/
    9787
    9888
     
    10393{
    10494
    105   for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ )
    106   {
    107     if( (*it).name.compare(file) == 0)
    108     {
    109       return &((*it).script);
    110     }
    111   }
    112   return NULL;
     95//   for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ )
     96//   {
     97//     if( (*it).name.compare(file) == 0)
     98//     {
     99//       return &((*it).script);
     100//     }
     101//   }
     102//   return NULL;
    113103
    114104}
    115105
    116 void  ScriptManager::setCurrentScriptFile(const std::string& file)
    117  {
    118    if( !fileIsInScriptList(file) )
    119      currentScript.name = file;
    120    else
    121      currentScript.name.assign("");
    122  }
    123 
    124 void  ScriptManager::addObjectToScript(const std::string object)
    125 {
    126   if(!objectIsInObjectList(object,currentScript))
    127     currentScript.objectList.push_back(object);
    128 }
    129 
    130 
    131 bool ScriptManager::fileIsInScriptList(const std::string& file)
    132 {
    133   for(std::list<LuaScript>::const_iterator it = scriptList.begin(); it != scriptList.end(); it++ )
    134   {
    135     if( (*it).name.compare(file) == 0)
    136     {
    137       return true;
    138     }
    139   }
    140   return false;
    141 }
    142 
    143 
    144 bool ScriptManager::objectIsInObjectList(const std::string& object, const LuaScript& script)
    145 {
    146   for(std::list<std::string>::const_iterator it = script.objectList.begin(); it != script.objectList.end(); it++ )
    147   {
    148     if( (*it).compare(object) == 0)
    149     {
    150       return true;
    151     }
    152   }
    153   return false;
    154 }
    155 
    156 
  • branches/script_engine/src/lib/script_engine/script_manager.h

    r8178 r8193  
    66
    77#include "script.h"
    8 #include "script_trigger.h"
    98#include "base_object.h"
    109#include "luaincl.h"
     
    1211
    1312
    14 //!< Contains the name of a lua script file  and a list of all objects that the script needs
    15 struct LuaScript
    16 {
    17   std::string name;
    18   std::list<std::string> objectList;
    19   Script script;
    20 };
    21 
     13class ScriptTrigger;
     14class Scriptable;
    2215
    2316class ScriptManager : public BaseObject
     
    2720   ~ScriptManager();
    2821
    29   inline static ScriptManager* getInstance(){if (!ScriptManager::singletonRef)ScriptManager::singletonRef = new ScriptManager();return ScriptManager::singletonRef;}
     22  inline static ScriptManager* getInstance() { if (!ScriptManager::singletonRef)ScriptManager::singletonRef = new ScriptManager(); return ScriptManager::singletonRef; }
    3023
    3124  virtual void loadParams(const TiXmlElement* root);
    32   void setWorld(const std::string& world) {currentWorld = world;}
    3325
    3426  void tick(float timestep);
    3527
    36   void initScripts(); // initializes all scripts
    3728  Script* getScriptByFile(std::string& file);
    3829
     30
     31 
    3932 private:
    4033
    4134   void  init();
    4235   void  createScriptList(const TiXmlElement* scripts);
    43    void  setCurrentScriptFile(const std::string& file);
    4436   void  addObjectToScript(const std::string object);
    4537
    46    bool fileIsInScriptList(const std::string& file);
    47    bool objectIsInObjectList(const std::string& object, const LuaScript& script);
    4838
     39   static ScriptManager*             singletonRef;   //!< Reference to this class
    4940
    50    static ScriptManager*      singletonRef;   //!< Reference to this class
    51    std::list<LuaScript>       scriptList;     //!< The list of all scripts that the current world needs
    52    std::string                currentWorld;
    53    LuaScript                  currentScript;  //!< For temorary use
     41   const std::list<BaseObject*>*     triggerList;
    5442
    55 
    56 
     43   const std::list<BaseObject*>*     scriptableClasses;
     44   const std::list<BaseObject*>*     scripts;
    5745
    5846
  • branches/script_engine/src/lib/script_engine/script_trigger.h

    r8178 r8193  
    2121    void setTarget(WorldEntity* target){ if(target!=NULL) this->target=target;if(worldEntityIsParent)this->setParent(target);}
    2222    void setTargetName(std::string& name){this->targetName = name;}
    23     void setCallOnce(bool call){this->callOnce = call;}
    24     void setRadius(float radius){if(radius>0) this->radius = radius;}
     23    void setCallOnce(bool call) { this->callOnce = call;}
     24    void setRadius(float radius) { if(radius>0) this->radius = radius;}
    2525    void setDelay(float time){if(delay>0) this->delay = delay;}
    2626    void setScript(std::string& script){this->scriptFile = script;}
     
    3131  private:
    3232
     33    std::string  parentName;
    3334    WorldEntity* target;
    3435    std::string  targetName;
  • branches/script_engine/src/lib/script_engine/scriptable.cc

    r8183 r8193  
    1616//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1717
    18 #include "proto_class.h"
     18#include "scriptable.h"
    1919
    2020using namespace std;
     
    2525 * @todo this constructor is not jet implemented - do it
    2626*/
    27 ProtoClass::ProtoClass ()
     27Scriptable::Scriptable(const std::string& name, ClassID classID)
     28 : BaseObject(name)
    2829{
    29    this->setClassID(CL_PROTO_ID, "ProtoClass");
     30   this->setClassID(CL_SCRIPTABLE, "Scriptable");
     31   this->classID = classID;
    3032
    31    /* If you make a new class, what is most probably the case when you write this file
    32       don't forget to:
    33        1. Add the new file new_class.cc to the ./src/Makefile.am
    34        2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS
    3533
    36       Advanced Topics:
    37       - if you want to let your object be managed via the ObjectManager make sure to read
    38         the object_manager.h header comments. You will use this most certanly only if you
    39         make many objects of your class, like a weapon bullet.
    40    */
    4134}
    4235
     
    4538 * standard deconstructor
    4639*/
    47 ProtoClass::~ProtoClass ()
     40Scriptable::~Scriptable ()
    4841{
    4942  // delete what has to be deleted here
  • branches/script_engine/src/lib/script_engine/scriptable.h

    r8183 r8193  
    11/*!
    2  * @file proto_class.h
     2 * @file scriptable.h
    33 * @brief Definition of ...
    44*/
    55
    6 #ifndef _PROTO_CLASS_H
    7 #define _PROTO_CLASS_H
     6#ifndef _SCRIPTABLE_H
     7#define _SCRIPTABLE_H
    88
    99#include "base_object.h"
     10
     11#include "script.h"
     12#include "lunar.h"
    1013
    1114// FORWARD DECLARATION
    1215
    1316
     17/**
     18 * Creates a factory to a Loadable Class.
     19 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
     20 */
     21#define CREATE_SCRIPTABLE_CLASS(CLASS_NAME, CLASS_ID) \
     22    tScriptable<CLASS_NAME> global_##CLASS_NAME##_ScriptableClass(#CLASS_NAME, CLASS_ID)
     23
     24
    1425
    1526//! A class for ...
    16 class ProtoClass : public BaseObject {
     27class Scriptable : virtual protected BaseObject
     28{
    1729
    18  public:
    19   ProtoClass();
    20   virtual ~ProtoClass();
     30public:
     31  Scriptable(const std::string& name, ClassID classID);
     32  virtual ~Scriptable();
     33
     34  bool operator==(const std::string& name) { return (this->getName() == name); }
     35  bool operator==(ClassID classID) { return (this->classID == classID); }
     36 
     37  virtual void registerClass(Script* script) = 0;
     38  virtual int insertObject(Script* L, BaseObject* obj, const std::string& name, bool gc=false) = 0;
     39
     40private:
     41  ClassID             classID;
     42};
    2143
    2244
    23  private:
    2445
    25 };
    2646
    27 #endif /* _PROTO_CLASS_H */
     47template <class T>
     48class tScriptable : public Scriptable
     49{
     50  tScriptable(const std::string& name, ClassID classID)
     51  : Scriptable(name, classID)
     52  { }
     53
     54  virtual void registerClass(Script* script)
     55  {
     56    Lunar<T>::Register(script);
     57  }
     58  virtual int insertObject(Script* L, BaseObject* obj, const std::string& name, bool gc=false)
     59  {
     60    Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), name, gc);
     61  }
     62 
     63
     64
     65}
     66;
     67
     68
     69#endif /* _SCRIPTABLE_H */
  • branches/script_engine/src/lib/util/loading/resource.cc

    r7195 r8193  
    2626Resource::Resource (const std::string& fileName)
    2727{
    28    this->setClassID(CL_RESOURCE, "Resource");
     28//   this->setClassID(CL_RESOURCE, "Resource");
    2929
    3030}
Note: See TracChangeset for help on using the changeset viewer.