Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9699 in orxonox.OLD for branches


Ignore:
Timestamp:
Aug 25, 2006, 12:03:59 AM (18 years ago)
Author:
bensch
Message:

adapted script_engine

Location:
branches/new_class_id/src/lib
Files:
6 edited

Legend:

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

    r9668 r9699  
    1818SUBDIRS = \
    1919        . \
     20\
     21                shell \
     22        parser \
     23        script_engine
     24#\
    2025        math \
    2126        lang \
     
    2934        collision_reaction \
    3035        gui \
    31         network \
    32         parser \
    33         shell \
    34         script_engine
     36        network
  • branches/new_class_id/src/lib/script_engine/script.cc

    r9692 r9699  
    2323#include "parser/tinyxml/tinyxml.h"
    2424
    25 #include "class_list.h"
    2625CREATE_SCRIPTABLE_CLASS(Script, Script::classID(),
    2726                    addMethod("addObject", ExecutorLua2<Script,const std::string&, const std::string& >(&Script::addObject))
     
    5453Script::Script(const std::string& filename)
    5554{
    56   this->setClassID(CL_SCRIPT, "Script");
     55  this->registerObject(this, Script::_objectList);
    5756
    5857  returnCount = argumentCount = 0;
     
    144143   //printf(("Script %s: I am about to add %s of class %s\n",this->getName(),objectName.c_str(),className.c_str());
    145144
    146    BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
     145   ScriptClass* scriptClass = ScriptClass::objectList().getObject(className);
    147146  // printf(("The script class for %s is at %p \n",className.c_str(),scriptClass);
    148147   WorldObject tmpObj;
     
    152151     if( !classIsRegistered(className) )
    153152     {
    154      static_cast<ScriptClass*>(scriptClass)->registerClass(this);
    155      }
    156 
    157      BaseObject* object = ClassList::getObject(objectName, className);
     153       scriptClass->registerClass(this);
     154     }
     155
     156     BaseObject* object = NewObjectListBase::getBaseObject(objectName, className);
    158157    // printf(("%s is at %p \n",objectName.c_str(),object);
    159158     if (object != NULL && !objectIsAdded(objectName))
    160159     {
    161         static_cast<ScriptClass*>(scriptClass)->insertObject(this, object, false);
     160        scriptClass->insertObject(this, object, false);
    162161        tmpObj.name = objectName;
    163162        registeredObjects.push_back(tmpObj);
     
    354353void Script::addThisScript()
    355354{
    356   BaseObject* scriptClass = ClassList::getObject("Script", CL_SCRIPT_CLASS);
    357    if (scriptClass != NULL)
    358    {
    359      static_cast<ScriptClass*>(scriptClass)->registerClass(this);
    360      static_cast<ScriptClass*>(scriptClass)->insertObject(this, this,"thisscript", false);
     355  ScriptClass* scriptClass = ScriptClass::objectList().getObject("Script");
     356
     357  if (scriptClass != NULL)
     358   {
     359     scriptClass->registerClass(this);
     360     scriptClass->insertObject(this, this,"thisscript", false);
    361361   }
    362362}
     
    388388 void Script::registerClass( const std::string& className)
    389389 {
    390    BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
     390   ScriptClass* scriptClass = ScriptClass::objectList().getObject(className);
    391391   //printf(("The script class for %s is at %p \n",className.c_str(),scriptClass);
     392
    392393   WorldObject tmpObj;
    393394   if (scriptClass != NULL)
  • branches/new_class_id/src/lib/script_engine/script_class.cc

    r9692 r9699  
    2424 * @todo this constructor is not jet implemented - do it
    2525*/
    26 ScriptClass::ScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods)
    27     : BaseObject(name)
     26ScriptClass::ScriptClass(const std::string& name, const NewClassID& classID, ScriptMethod* scriptMethods)
     27    : BaseObject(name), _classID(classID)
    2828{
    2929  assert(scriptMethods != NULL);
    30   this->registerObject(this, Shell::_objectList);
     30  this->registerObject(this, ScriptClass::_objectList);
    3131
    3232  this->_classID = classID;
  • branches/new_class_id/src/lib/script_engine/script_class.h

    r9686 r9699  
    2323
    2424//! A class for ...
    25 class ScriptClass : protected BaseObject
     25class ScriptClass : public BaseObject
    2626{
     27  NewObjectListDeclaration(ScriptClass);
    2728
    2829public:
    2930  virtual ~ScriptClass();
    3031
    31   bool operator==(const std::string& name) { return (this->getName() == name); }
    32   bool operator==(NewClassID classID) { return (this->_classID == classID); }
     32  const std::string& getName() const { return this->getName(); }
     33  bool operator==(const std::string& name) const { return (this->getName() == name); }
     34  bool operator==(NewClassID classID) const { return (this->_classID == classID); }
    3335
    3436  virtual void registerClass(Script* script) = 0;
     
    3941
    4042protected:
    41   ScriptClass(const std::string& name, NewClassID classID, ScriptMethod* scriptMethods);
     43  ScriptClass(const std::string& name, const NewClassID& classID, ScriptMethod* scriptMethods);
    4244
    4345private:
    44   const NewClassID&   _classID;
     46  NewClassID          _classID;
    4547  ScriptMethod*       _scriptMethods;
    4648};
  • branches/new_class_id/src/lib/script_engine/script_manager.cc

    r9003 r9699  
    2424#include "lunar.h"
    2525
    26 #include "class_list.h"
    27 
    2826#include "script.h"
    2927#include "script_trigger.h"
     
    3735{
    3836  this->setName("ScriptManager");
    39   this->scripts = NULL;
    40   this->triggers = NULL;
    4137
    4238  if (root != NULL)
     
    6258
    6359  // fill the scripts and triggers (doing that on runtime is very slow!)
    64   getTriggers();
    65   getScripts();
    6660}
    6761
     
    7165{
    7266  //Delete all scripts as they aren't deleted automatically
    73   if(this->getScripts())
    74     while(!scripts->empty())
    75       delete scripts->front();
     67  while(!Script::objectList().empty())
     68    delete Script::objectList().front();
    7669  //Delete all triggers
    77   if(this->getTriggers())
    78     while(!triggers->empty())
    79       delete triggers->front();
    80  
     70  while(!ScriptTrigger::objectList().empty())
     71    delete ScriptTrigger::objectList().front();
     72
    8173}
    8274
     
    10597Script* ScriptManager::getScriptByFile(const std::string& file)
    10698{
    107   if(getScripts())
    108     for(std::list<BaseObject*>::const_iterator it = scripts->begin(); it != scripts->end(); it++ )
    109     {
    110       if( (dynamic_cast<Script*>(*it))->getFileName().compare(file) == 0)
    111       {
    112         return dynamic_cast<Script*>(*it);
    113       }
    114     }
     99  for (NewObjectList<Script>::const_iterator it = Script::objectList().begin();
     100       it != Script::objectList().end();
     101       ++it)
     102    if( ((*it))->getFileName().compare(file) == 0)
     103      return (*it);
    115104
    116105  return NULL;
    117106
    118107}
    119 
    120 
    121 bool ScriptManager::getScripts()
    122 {
    123   return (this->scripts != NULL || (this->scripts = ClassList::getList(CL_SCRIPT)) != NULL);
    124 }
    125 
    126 bool ScriptManager::getTriggers()
    127 {
    128   return (this->triggers != NULL || (this->triggers = ClassList::getList(CL_SCRIPT_TRIGGER)) != NULL);
    129 }
    130 
    131 
    132 
  • branches/new_class_id/src/lib/script_engine/script_manager.h

    r8894 r9699  
    3434   void  createTriggers(const TiXmlElement* triggers);
    3535
    36    bool getTriggers();
    37    bool getScripts();
    38 
    3936   static ScriptManager*             singletonRef;   //!< Reference to this class
    40 
    41    const std::list<BaseObject*>*     triggers;       //!< A list of all the triggers in the world
    42 
    43    const std::list<BaseObject*>*     scripts;        //!< A list of all the scripts in the world
    44 
    45 
    4637};
    4738#endif
Note: See TracChangeset for help on using the changeset viewer.