Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/script_engine/script_manager.cc @ 8645

Last change on this file since 8645 was 8408, checked in by bensch, 18 years ago

trunk: merged the script_engine branche back here
merged with command
svn merge https://svn.orxonox.net/orxonox/branches/script_engine . -r8284:HEAD
no conflicts

File size: 2.1 KB
RevLine 
[8093]1#include <string>
2#include <list>
[8085]3
[8408]4#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
[8202]5
[8408]6
[8085]7#include "script_manager.h"
[8155]8#include "lunar.h"
[8093]9
[8202]10#include "class_list.h"
[8093]11
[8202]12#include "script.h"
13#include "script_trigger.h"
14#include "luaincl.h"
15#include "loading/load_param.h"
16#include "parser/tinyxml/tinyxml.h"
17
18
19
[8239]20ScriptManager::ScriptManager(const TiXmlElement* root)
[8093]21{
[8239]22  this->setName("ScriptManager");
23  this->scripts = NULL;
24  this->triggers = NULL;
25
26  if (root != NULL)
27    this->loadParams(root);
[8093]28}
29
[8239]30
31
[8093]32ScriptManager::~ScriptManager()
33{
[8239]34  this->flush();
[8093]35}
36
[8138]37
[8155]38void ScriptManager::loadParams(const TiXmlElement* root)
39{
[8408]40  BaseObject::loadParams(root);
[8206]41  {
[8239]42    LoadParamXML(root, "Scripts", this, ScriptManager, createScripts);
[8211]43
[8239]44    LoadParamXML(root, "ScriptTriggers", this, ScriptManager, createTriggers);
[8206]45  } // make shure that the loading process is finished
[8210]46
[8206]47  // fill the scripts and triggers (doing that on runtime is very slow!)
48  getTriggers();
49  getScripts();
[8239]50}
[8210]51
52
[8155]53
[8239]54void  ScriptManager::flush()
[8208]55{
[8210]56  //Delete all scripts as they aren't deleted automatically
[8239]57  if(this->getScripts())
58    while(!scripts->empty())
59      delete scripts->front();
[8208]60}
61
[8202]62void  ScriptManager::createScripts(const TiXmlElement* scripts)
[8093]63{
[8210]64
[8193]65  LOAD_PARAM_START_CYCLE(scripts, object);
66  {
67    new Script(object);
68  }
69  LOAD_PARAM_END_CYCLE(object);
[8093]70
[8202]71}
[8131]72
[8202]73void ScriptManager::createTriggers(const TiXmlElement* triggers)
74{
75  LOAD_PARAM_START_CYCLE(triggers, object);
[8155]76  {
[8202]77    new ScriptTrigger(object);
78  }
79  LOAD_PARAM_END_CYCLE(object);
[8155]80
[8093]81}
82
[8171]83
[8212]84Script* ScriptManager::getScriptByFile(const std::string& file)
[8171]85{
[8206]86  if(getScripts())
[8239]87    for(std::list<BaseObject*>::const_iterator it = scripts->begin(); it != scripts->end(); it++ )
[8206]88    {
89      if( (dynamic_cast<Script*>(*it))->getFileName().compare(file) == 0)
[8239]90      {
91        return dynamic_cast<Script*>(*it);
92      }
93    }
[8210]94
[8206]95  return NULL;
[8171]96
97}
98
[8202]99
100bool ScriptManager::getScripts()
101{
[8210]102  return (this->scripts != NULL || (this->scripts = ClassList::getList(CL_SCRIPT)) != NULL);
[8202]103}
104
[8206]105bool ScriptManager::getTriggers()
106{
[8210]107  return (this->triggers != NULL || (this->triggers = ClassList::getList(CL_SCRIPT_TRIGGER)) != NULL);
[8206]108}
[8202]109
110
[8206]111
Note: See TracBrowser for help on using the repository browser.