Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8206 in orxonox.OLD for branches


Ignore:
Timestamp:
Jun 7, 2006, 5:56:55 PM (18 years ago)
Author:
snellen
Message:

script checks now before adding an object and a class wether the class or object has already been added

Location:
branches/script_engine/src/lib/script_engine
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/lib/script_engine/script.cc

    r8202 r8206  
    9595   if (scriptClass != NULL)
    9696   {
     97     if( !classIsRegistered(className) )
    9798     static_cast<ScriptClass*>(scriptClass)->registerClass(this);
    9899     
    99100     BaseObject* object = ClassList::getObject(objectName, className);
    100      if (object != NULL)
     101     if (object != NULL && !objectIsAdded(objectName))
    101102     {
    102103        static_cast<ScriptClass*>(scriptClass)->insertObject(this, object, false);
     
    292293 }
    293294
     295 
     296 bool Script::classIsRegistered(const std::string& type)
     297 {
     298   for(std::list<worldObject>::const_iterator it = registeredObjects.begin(); it != registeredObjects.end(); it++ )
     299   {
     300     if( (*it).type == type)
     301     {
     302       return true;
     303     }
     304   }
     305   return false;
     306 }
     307 
     308 
     309 
     310 bool Script::objectIsAdded(const std::string& name)
     311 {
     312   for(std::list<worldObject>::const_iterator it = registeredObjects.begin(); it != registeredObjects.end(); it++ )
     313   {
     314     if( (*it).name == name)
     315     {
     316       return true;
     317     }
     318   }
     319   return false;
     320 
     321 
     322 }
  • branches/script_engine/src/lib/script_engine/script.h

    r8202 r8206  
    55#include "base_object.h"
    66
     7
    78struct lua_State;
     9
     10struct worldObject
     11{
     12  std::string name;
     13  std::string type;
     14};
    815
    916class Script : public BaseObject
     
    1825    void loadFileNoRet(const std::string& filename) { loadFile(filename); };
    1926    bool loadFile(const std::string& filename);
     27    void addObject(const std::string& className, const std::string& objectName);
     28   
     29    /// QUERRYING
    2030    /** @returns fileName */
    2131    std::string getFileName() { return currentFile; }
    22 
    23     void addObject(const std::string& className, const std::string& objectName);
    24    
    25        
    26 
    2732    lua_State* getLuaState() const { return luaState; }
    2833
     
    5156  private:
    5257
    53     int reportError(int error);          //!< Get errormessage from the lua stack and print it.
     58    int  reportError(int error);                      //!< Get errormessage from the lua stack and print it.
     59    bool classIsRegistered(const std::string& type);
     60    bool objectIsAdded(const std::string& name);
    5461
    55     lua_State*         luaState;         //!< The lua_State that the Script works on
    56     std::string        currentFile;      //!< The file that is loaded in the script
    57     std::string        currentFunction;  //!< The name of the current active function (the one that gets the pushed parameter)
    58     int                argumentCount;    //!< Number of arguments for the current function
    59     int                returnCount;      //!< Number of return values of the current function
     62    lua_State*              luaState;                //!< The lua_State that the Script works on
     63    std::string             currentFile;             //!< The file that is loaded in the script
     64    std::string             currentFunction;         //!< The name of the current active function (the one that gets the pushed parameter)
     65    int                     argumentCount;           //!< Number of arguments for the current function
     66    int                     returnCount;             //!< Number of return values of the current function
     67   
     68    std::list<worldObject>  registeredObjects;       //!< The list of all the objects and their type that have been registered with this script
    6069
    6170
  • branches/script_engine/src/lib/script_engine/script_manager.cc

    r8202 r8206  
    3131{
    3232  //BaseObject::loadParams(root);
    33 
     33  {
    3434  LoadParamXML(root, "ScriptTriggers", this, ScriptManager, createTriggers);
    3535 
    3636  LoadParamXML(root, "Scripts", this, ScriptManager, createScripts);
     37  } // make shure that the loading process is finished
     38 
     39  // fill the scripts and triggers (doing that on runtime is very slow!)
     40  getTriggers();
     41  getScripts();
     42 
     43 
    3744}
    3845
     
    7279Script* ScriptManager::getScriptByFile(std::string& file)
    7380{
    74 
    75 //   for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ )
    76 //   {
    77 //     if( (*it).name.compare(file) == 0)
    78 //     {
    79 //       return &((*it).script);
    80 //     }
    81 //   }
    82 //   return NULL;
     81  if(getScripts())
     82   for(std::list<BaseObject*>::const_iterator it = scripts->begin(); it != scripts->end(); it++ )
     83    {
     84      if( (dynamic_cast<Script*>(*it))->getFileName().compare(file) == 0)
     85     {
     86       return dynamic_cast<Script*>(*it);
     87     }
     88   }
     89   
     90  return NULL;
    8391
    8492}
     
    9098}
    9199
     100bool ScriptManager::getTriggers()
     101{
     102  return (this->triggers != NULL || (this->triggers = ClassList::getList(CL_SCRIPT_TRIGGER)) != NULL);
     103}
    92104
    93105
     106
  • branches/script_engine/src/lib/script_engine/script_manager.h

    r8202 r8206  
    2020
    2121  virtual void loadParams(const TiXmlElement* root);
    22 
    2322
    2423  Script* getScriptByFile(std::string& file);
  • branches/script_engine/src/lib/script_engine/script_trigger.cc

    r8205 r8206  
    102102     ScriptManager* scriptManager = ScriptManager::getInstance();
    103103     Script* script = scriptManager->getScriptByFile(this->scriptFile);
     104     if(script != NULL)
    104105     if(!(script->selectFunction(this->functionName,0)) )
    105106       printf("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), scriptFile.c_str());
Note: See TracChangeset for help on using the changeset viewer.