Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merge

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