Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/lib/script_engine/script_manager.cc @ 8484

Last change on this file since 8484 was 8278, checked in by bensch, 18 years ago

merge

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