Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/mountain_lake/src/lib/script_engine/script_manager.cc @ 8902

Last change on this file since 8902 was 8711, checked in by bensch, 18 years ago

merged the script_engine back here

File size: 2.5 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Silvan Nellen
13   co-programmer: Benjamin Grauer
14*/
15
16
17#include <string>
18#include <list>
19
20#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
21
22
23#include "script_manager.h"
24#include "lunar.h"
25
26#include "class_list.h"
27
28#include "script.h"
29#include "script_trigger.h"
30#include "luaincl.h"
31#include "loading/load_param.h"
32#include "parser/tinyxml/tinyxml.h"
33
34
35
36ScriptManager::ScriptManager(const TiXmlElement* root)
37{
38  this->setName("ScriptManager");
39  this->scripts = NULL;
40  this->triggers = NULL;
41
42  if (root != NULL)
43    this->loadParams(root);
44}
45
46
47
48ScriptManager::~ScriptManager()
49{
50  this->flush();
51}
52
53
54void ScriptManager::loadParams(const TiXmlElement* root)
55{
56  BaseObject::loadParams(root);
57  {
58    LoadParamXML(root, "Scripts", this, ScriptManager, createScripts);
59
60    LoadParamXML(root, "ScriptTriggers", this, ScriptManager, createTriggers);
61  } // make shure that the loading process is finished
62
63  // fill the scripts and triggers (doing that on runtime is very slow!)
64  getTriggers();
65  getScripts();
66}
67
68
69
70void  ScriptManager::flush()
71{
72  //Delete all scripts as they aren't deleted automatically
73  if(this->getScripts())
74    while(!scripts->empty())
75      delete scripts->front();
76}
77
78void  ScriptManager::createScripts(const TiXmlElement* scripts)
79{
80
81  LOAD_PARAM_START_CYCLE(scripts, object);
82  {
83    new Script(object);
84  }
85  LOAD_PARAM_END_CYCLE(object);
86
87}
88
89void ScriptManager::createTriggers(const TiXmlElement* triggers)
90{
91  LOAD_PARAM_START_CYCLE(triggers, object);
92  {
93    new ScriptTrigger(object);
94  }
95  LOAD_PARAM_END_CYCLE(object);
96
97}
98
99
100Script* ScriptManager::getScriptByFile(const std::string& file)
101{
102  if(getScripts())
103    for(std::list<BaseObject*>::const_iterator it = scripts->begin(); it != scripts->end(); it++ )
104    {
105      if( (dynamic_cast<Script*>(*it))->getFileName().compare(file) == 0)
106      {
107        return dynamic_cast<Script*>(*it);
108      }
109    }
110
111  return NULL;
112
113}
114
115
116bool ScriptManager::getScripts()
117{
118  return (this->scripts != NULL || (this->scripts = ClassList::getList(CL_SCRIPT)) != NULL);
119}
120
121bool ScriptManager::getTriggers()
122{
123  return (this->triggers != NULL || (this->triggers = ClassList::getList(CL_SCRIPT_TRIGGER)) != NULL);
124}
125
126
127
Note: See TracBrowser for help on using the repository browser.