Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8155 in orxonox.OLD for branches/script_engine/src/lib


Ignore:
Timestamp:
Jun 5, 2006, 3:47:10 PM (18 years ago)
Author:
snellen
Message:

this won't compile

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

Legend:

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

    r8132 r8155  
    2727    bool  pushParam(float param, std::string& toFunction);
    2828    bool  pushParam(double param, std::string& toFunction);
    29     // get returned values the last return value in lua is the first in c.
     29    // get returned values the last return value in lua is the first in c. TODO: change order of return
    3030    int   getReturnedInt();
    3131    bool  getReturnedBool();
    3232    float getReturnedFloat();
    33     void getReturnedString(std::string& string);
     33    void  getReturnedString(std::string& string);
    3434
    3535
  • branches/script_engine/src/lib/script_engine/script_manager.cc

    r8138 r8155  
    44#include "script.h"
    55#include "script_manager.h"
     6#include "lunar.h"
    67
    78
    8 ScriptManager::ScriptManager(std::string& world)
     9ScriptManager::ScriptManager()
    910{
    10   this->init(world);
    11 
     11  this->init();
    1212}
    1313
     
    2727}
    2828
     29void ScriptManager::loadParams(const TiXmlElement* root)
     30{
     31  //BaseObject::loadParams(root);
    2932
    30 //!< Fills the worldObject list
     33  const TiXmlElement* scripts = root->FirstChildElement("Scripts");
    3134
    32 void ScriptManager::init(std::string& world)
    33 {
     35  if( element == NULL)
     36  {
     37    PRINTF(1)("ScriptManager is missing 'Scripts'\n");
     38  }
     39  else
     40  {
     41    createScriptList(scripts);
     42  }
    3443
    3544
    3645}
    3746
    38 
    39 
    40 void ScriptManager::loadParams(const TiXmlElement* root)
    41 {
    42   //BaseObject::loadParams(root);
    43 
    44 
    45 }
    46 
    47 
    4847void ScriptManager::tick(float timestep)
    49 {
    50 }
    51 
    52 void ScriptManager::changeWorld(std::string& newWorld)
    5348{
    5449}
     
    5752void ScriptManager::initScripts()
    5853{
     54  for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ )
     55  {
     56    (*it).script.loadFile((*it).name);
     57  }
     58}
     59
     60void ScriptManager::init()
     61{
     62  currentWorld.assign("");
     63
    5964}
    6065
    6166
     67void  ScriptManager::createScriptList(TiXmlElement* scripts)
     68{
     69  const TiXmlElement* script = scripts->FirstChildElement();
     70  const TiXmlElement* object;
     71
     72  PRINTF(4)("Creating scriptlist\n");
     73
     74  while( script != NULL)
     75  {
     76    LoadParam(script, "file", this, ScriptManager, setCurrentScriptFile)
     77        .describe("the fileName of the script, that should be loaded into this world")
     78        .defaultValues("");
     79
     80    if(!currentScript.name.empty()) // if LoadParam didn't fail... fill the object list with the needed objects
     81    {
     82    object = script->FirstChildElement("object");
     83
     84    while(object != NULL)
     85    {
     86      addObjectToScript(object->Value(), currentScript);
     87      object = object->NextSiblingElement("object");
     88    }
     89
     90    scriptList.push_back(currentScript);
     91    }
     92
     93    script = script->NextSiblingElement("Script");
     94
     95  }
     96
     97
     98}
     99
     100void  ScriptManager::setCurrentScriptFile(std::string& file)
     101 {
     102   if( !fileIsInScriptList(file) )
     103     currentScript.name = file;
     104   else
     105     currentScript.name.assign("");
     106 }
     107
     108void  ScriptManager::addObjectToScript(std::string& object, LuaScript& script)
     109{
     110  if(!objectIsInObjectList(object,script))
     111    script.objectList.push_back(object);
     112}
     113
     114
     115bool ScriptManager::fileIsInScriptList(std::string& file)
     116{
     117  for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ )
     118  {
     119    if( (*it).name.compare(file) == 0)
     120    {
     121      return true;
     122    }
     123  }
     124  return false;
     125}
     126
     127
     128bool ScriptManager::objectIsInObjectList(std::string& object, const LuaScript& script)
     129{
     130  for(std::list<std::string>::iterator it = script.objectList.begin(); it != script.objectList.end(); it++ )
     131  {
     132    if( (*it).compare(object) == 0)
     133    {
     134      return true;
     135    }
     136  }
     137  return false;
     138}
     139
     140
  • branches/script_engine/src/lib/script_engine/script_manager.h

    r8139 r8155  
    1111
    1212
    13 //!< Contains the names of all objects in a world and a list of all script files that need the object.
    14 struct worldObject
     13//!< Contains the name of a lua script file  and a list of all objects that the script needs
     14struct LuaScript
    1515{
    1616  std::string name;
    17   std::list<std::string> scriptFiles;
     17  std::list<std::string> objectList;
     18  Script script;
    1819};
    1920
     
    2223 public:
    2324   ScriptManager();
    24    ScriptManager(std::string& world);
    2525   ~ScriptManager();
    2626
    27    inline static ScriptManager* getInstance();
     27  inline static ScriptManager* getInstance();
    2828
    29   void loadParams(const TiXmlElement* root);
     29  virtual void loadParams(const TiXmlElement* root);
     30  void setWorld(std::string& world){currentWorld = world;}
    3031
    3132  void tick(float timestep);
    32 
    33   void changeWorld(std::string& newWorld);
    34 
    3533
    3634  void initScripts(); // initializes all scripts
     
    3836 private:
    3937
    40    void  init(std::string& world);
     38   void  init();
     39   void  createScriptList(TiXmlElement* scripts);
     40   void  setCurrentScriptFile(std::string& file);
     41   void  addObjectToScript(std::string& object, LuaScript& script);
    4142
    42    static ScriptManager*      singletonRef; //!< Reference to this class
    43    std::list<worldObject> objectList; //!< The list of all Objects in a world (read from the *.oxw file of the world)
    44    std::string currentWorld;
     43   bool fileIsInScriptList(std::string& file);
     44   bool objectIsInObjectList(std::string& object,const LuaScript& script);
     45
     46
     47   static ScriptManager*      singletonRef;   //!< Reference to this class
     48   std::list<LuaScript>       scriptList;     //!< The list of all scripts that the current world needs
     49   std::string                currentWorld;
     50   LuaScript                  currentScript;  //!< For temorary use
     51
    4552
    4653
Note: See TracChangeset for help on using the changeset viewer.