Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9467 was 9003, checked in by bensch, 18 years ago

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

File size: 2.6 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  //Delete all triggers
77  if(this->getTriggers())
78    while(!triggers->empty())
79      delete triggers->front();
80 
81}
82
83void  ScriptManager::createScripts(const TiXmlElement* scripts)
84{
85
86  LOAD_PARAM_START_CYCLE(scripts, object);
87  {
88    new Script(object);
89  }
90  LOAD_PARAM_END_CYCLE(object);
91
92}
93
94void ScriptManager::createTriggers(const TiXmlElement* triggers)
95{
96  LOAD_PARAM_START_CYCLE(triggers, object);
97  {
98    new ScriptTrigger(object);
99  }
100  LOAD_PARAM_END_CYCLE(object);
101
102}
103
104
105Script* ScriptManager::getScriptByFile(const std::string& file)
106{
107  if(getScripts())
108    for(std::list<BaseObject*>::const_iterator it = scripts->begin(); it != scripts->end(); it++ )
109    {
110      if( (dynamic_cast<Script*>(*it))->getFileName().compare(file) == 0)
111      {
112        return dynamic_cast<Script*>(*it);
113      }
114    }
115
116  return NULL;
117
118}
119
120
121bool ScriptManager::getScripts()
122{
123  return (this->scripts != NULL || (this->scripts = ClassList::getList(CL_SCRIPT)) != NULL);
124}
125
126bool ScriptManager::getTriggers()
127{
128  return (this->triggers != NULL || (this->triggers = ClassList::getList(CL_SCRIPT_TRIGGER)) != NULL);
129}
130
131
132
Note: See TracBrowser for help on using the repository browser.