Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8202 in orxonox.OLD for branches/script_engine/src


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

renamed scriptable to scriptclass, made ScriptManager create the script triggers

Location:
branches/script_engine/src/lib/script_engine
Files:
7 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/lib/script_engine/Makefile.am

    r8193 r8202  
    1515                script.cc\
    1616                script_manager.cc\
    17                 scriptable.cc \
     17                script_class.cc \
    1818                script_trigger.cc
    1919
     
    2424                script.h\
    2525                script_manager.h\
    26                 scriptable.h \
     26                script_class.h \
    2727                script_trigger.h
    2828
  • branches/script_engine/src/lib/script_engine/script.cc

    r8199 r8202  
    11#include "script.h"
    2 #include "scriptable.h"
     2#include "script_class.h"
     3#include "luaincl.h"
     4
    35
    46#include "loading/load_param.h"
     
    9092 void Script::addObject(const std::string& className, const std::string& objectName)
    9193 {
    92    BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPTABLE);
     94   BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
    9395   if (scriptClass != NULL)
    9496   {
    95      static_cast<Scriptable*>(scriptClass)->registerClass(this);
     97     static_cast<ScriptClass*>(scriptClass)->registerClass(this);
    9698     
    9799     BaseObject* object = ClassList::getObject(objectName, className);
    98100     if (object != NULL)
    99101     {
    100         static_cast<Scriptable*>(scriptClass)->insertObject(this, object, false);
     102        static_cast<ScriptClass*>(scriptClass)->insertObject(this, object, false);
    101103     }
    102104   }
  • branches/script_engine/src/lib/script_engine/script.h

    r8193 r8202  
    55#include "base_object.h"
    66
    7 #include "luaincl.h"
    8 
     7struct lua_State;
    98
    109class Script : public BaseObject
  • branches/script_engine/src/lib/script_engine/script_class.cc

    r8193 r8202  
    1616//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1717
    18 #include "scriptable.h"
     18#include "script_class.h"
    1919
    2020using namespace std;
     
    2525 * @todo this constructor is not jet implemented - do it
    2626*/
    27 Scriptable::Scriptable(const std::string& name, ClassID classID)
     27ScriptClass::ScriptClass(const std::string& name, ClassID classID)
    2828 : BaseObject(name)
    2929{
    30    this->setClassID(CL_SCRIPTABLE, "Scriptable");
     30   this->setClassID(CL_SCRIPT_CLASS, "ScriptClass");
    3131   this->classID = classID;
    32 
    33 
    3432}
    3533
     
    3836 * standard deconstructor
    3937*/
    40 Scriptable::~Scriptable ()
     38ScriptClass::~ScriptClass ()
    4139{
    4240  // delete what has to be deleted here
  • branches/script_engine/src/lib/script_engine/script_class.h

    r8197 r8202  
    11/*!
    2  * @file scriptable.h
     2 * @file script_class.h
    33 * @brief Definition of ...
    44*/
    55
    6 #ifndef _SCRIPTABLE_H
    7 #define _SCRIPTABLE_H
     6#ifndef _SCRIPT_CLASS_H
     7#define _SCRIPT_CLASS_H
    88
    99#include "base_object.h"
     
    2525
    2626//! A class for ...
    27 class Scriptable : protected BaseObject
     27class ScriptClass : protected BaseObject
    2828{
    2929
    3030public:
    31   Scriptable(const std::string& name, ClassID classID);
    32   virtual ~Scriptable();
     31  ScriptClass(const std::string& name, ClassID classID);
     32  virtual ~ScriptClass();
    3333
    3434  bool operator==(const std::string& name) { return (this->getName() == name); }
     
    4646
    4747template <class T>
    48 class tScriptable : public Scriptable
     48class tScriptable : public ScriptClass
    4949{
    5050  tScriptable(const std::string& name, ClassID classID)
    51   : Scriptable(name, classID)
     51  : ScriptClass(name, classID)
    5252  { }
    5353
     
    6767
    6868
    69 #endif /* _SCRIPTABLE_H */
     69#endif /* _SCRIPT_CLASS_H */
  • branches/script_engine/src/lib/script_engine/script_manager.cc

    r8193 r8202  
    22#include <list>
    33
    4 #include "script.h"
     4
    55#include "script_manager.h"
    66#include "lunar.h"
     7
     8#include "class_list.h"
     9
     10#include "script.h"
     11#include "script_trigger.h"
     12#include "luaincl.h"
     13#include "loading/load_param.h"
     14#include "parser/tinyxml/tinyxml.h"
     15
    716
    817
     
    2332  //BaseObject::loadParams(root);
    2433
    25   const TiXmlElement* scripttrigger= root->FirstChildElement("ScriptTrigger");
    26 
    27   while( scripttrigger != NULL)
    28    {
    29      //TODO: generate script trigger in factory and let them load their params.
    30       scripttrigger = scripttrigger->NextSiblingElement("ScriptTrigger");
    31    }
    32 
    33    
    34    LoadParamXML(root, "Scripts", this, ScriptManager, createScriptList);
    35 }
    36 
    37 void ScriptManager::tick(float timestep)
    38 {
     34  LoadParamXML(root, "ScriptTriggers", this, ScriptManager, createTriggers);
     35 
     36  LoadParamXML(root, "Scripts", this, ScriptManager, createScripts);
    3937}
    4038
     
    4240void ScriptManager::init()
    4341{
    44 
     42  //this->setClassID("");
     43  this->setName("ScriptManager");
     44 
     45  this->scripts = NULL;
     46  this->triggers = NULL;
    4547}
    4648
    4749
    48 void  ScriptManager::createScriptList(const TiXmlElement* scripts)
     50void  ScriptManager::createScripts(const TiXmlElement* scripts)
    4951{
    5052 
     
    5456  }
    5557  LOAD_PARAM_END_CYCLE(object);
    56      
    57      
    58   /*
    59   const TiXmlElement* script = scripts->FirstChildElement();
    6058
    61   PRINTF(4)("Creating scriptlist\n");
     59}
    6260
    63   while( script != NULL)
     61void ScriptManager::createTriggers(const TiXmlElement* triggers)
     62{
     63  LOAD_PARAM_START_CYCLE(triggers, object);
    6464  {
    65     { // scope to make the LoadParam work
    66     LoadParam(script, "file", this, ScriptManager, setCurrentScriptFile)
    67         .describe("the fileName of the script, that should be loaded into this world")
    68         .defaultValues("");
    69     }
    70 
    71     if(!currentScript.name.empty()) // if LoadParam didn't fail... fill the object list with the needed objects
    72     {
    73 
    74     LOAD_PARAM_START_CYCLE(script, object);
    75     {
    76      // LoadParam_CYCLE(object, "object", this, ScriptManager, addObjectToScript)
    77        //   .describe("The name of an object that is needed by a script");
    78     }
    79     LOAD_PARAM_END_CYCLE(object);
    80 
    81     scriptList.push_back(currentScript);
    82     }
    83 
    84     script = script->NextSiblingElement("Script");
    85 
    86   }*/
    87 
     65    new ScriptTrigger(object);
     66  }
     67  LOAD_PARAM_END_CYCLE(object);
    8868
    8969}
     
    10484}
    10585
     86
     87bool ScriptManager::getScripts()
     88{
     89  return (this->scripts != NULL || (this->scripts = ClassList::getList(CL_SCRIPT)) != NULL);
     90}
     91
     92
     93
  • branches/script_engine/src/lib/script_engine/script_manager.h

    r8193 r8202  
    33
    44#include <list>
    5 #include <string>
    65
     6#include "base_object.h"
    77#include "script.h"
    8 #include "base_object.h"
    9 #include "luaincl.h"
    10 #include "loading/load_param.h"
    118
    129
     
    2421  virtual void loadParams(const TiXmlElement* root);
    2522
    26   void tick(float timestep);
    2723
    2824  Script* getScriptByFile(std::string& file);
     
    3329
    3430   void  init();
    35    void  createScriptList(const TiXmlElement* scripts);
    36    void  addObjectToScript(const std::string object);
    37 
     31   void  createScripts(const TiXmlElement* scripts);
     32   void  createTriggers(const TiXmlElement* triggers);
     33   
     34   bool getTriggers();
     35   bool getScripts();
    3836
    3937   static ScriptManager*             singletonRef;   //!< Reference to this class
    4038
    41    const std::list<BaseObject*>*     triggerList;
     39   const std::list<BaseObject*>*     triggers;
    4240
    43    const std::list<BaseObject*>*     scriptableClasses;
    4441   const std::list<BaseObject*>*     scripts;
    4542
  • branches/script_engine/src/lib/script_engine/script_trigger.cc

    r8199 r8202  
    11#include "script_trigger.h"
     2#include "class_list.h"
     3#include "script.h"
    24
    35
    4 ScriptTrigger::ScriptTrigger()
     6ScriptTrigger::ScriptTrigger(const TiXmlElement* root)
    57{
    6  scriptCalled = false;
    7  callScript = false;
    8  triggered = false;
     8  scriptCalled = false;
     9  callScript = false;
     10  triggered = false;
     11  loadParams(root);
     12
     13
    914}
    1015
     
    1621void ScriptTrigger::loadParams(const TiXmlElement* root)
    1722{
    18   WorldEntity::loadParams(root);
     23  WorldEntity ::loadParams(root);
    1924 
    2025   /*{ LoadParam(root, "file", this, ScriptTrigger, setScript)
     
    5560  else
    5661  {
    57     PRINTF(2)("Target %s for %s::%s does not Exist\n", taget.c_str(), this->getClassName(), this->getName());
     62    PRINTF(2)("Target %s for %s::%s does not Exist\n", target.c_str(), this->getClassName(), this->getName());
    5863  }
    5964}
  • branches/script_engine/src/lib/script_engine/script_trigger.h

    r8199 r8202  
    1212{
    1313  public:
    14     ScriptTrigger();
     14    ScriptTrigger(const TiXmlElement* root);
    1515    ~ScriptTrigger();
    1616
     
    2121   
    2222    void setTarget(const std::string& targetName);
    23    
    24     void setTarget(WorldEntity* target) { if(target!=NULL) this->target=target;if(worldEntityIsParent)this->setParent(target); }
    25     void setTargetName(std::string& name){ this->targetName = name; }
     23    void setTarget(WorldEntity* target) { if(target!=NULL) this->target=target; }
     24 
    2625    void setCallOnce(bool call) { this->callOnce = call;}
    2726    void setRadius(float radius) { if(radius>0) this->radius = radius;}
     
    3029    void setFunction(std::string& function){this->functionName = function;}
    3130
    32     std::string getTargetName(){return targetName;}
     31    std::string getTargetName();
    3332
    3433  private:
     
    3635    std::string  parentName;
    3736    WorldEntity* target;
    38     std::string  targetName;
    3937    bool         worldEntityIsParent;
    4038    bool         callOnce;
    41     bool scriptCalled;
    42     float radius;
    43     float delay;
    44     std::string scriptFile;
    45     std::string functionName;
     39    bool         scriptCalled;
     40    float        radius;
     41    float        delay;
     42    std::string  scriptFile;
     43    std::string  functionName;
    4644
    4745    bool callScript;
Note: See TracChangeset for help on using the changeset viewer.