Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/script_engine/script_manager.cc @ 9715

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

renamed newclassid to classid and newobjectlist to objectlist

File size: 2.2 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 "script.h"
27#include "script_trigger.h"
28#include "luaincl.h"
29#include "loading/load_param.h"
30#include "parser/tinyxml/tinyxml.h"
31
32
33
34ScriptManager::ScriptManager(const TiXmlElement* root)
35{
36  this->setName("ScriptManager");
37
38  if (root != NULL)
39    this->loadParams(root);
40}
41
42
43
44ScriptManager::~ScriptManager()
45{
46  this->flush();
47}
48
49
50void ScriptManager::loadParams(const TiXmlElement* root)
51{
52  BaseObject::loadParams(root);
53  {
54    LoadParamXML(root, "Scripts", this, ScriptManager, createScripts);
55
56    LoadParamXML(root, "ScriptTriggers", this, ScriptManager, createTriggers);
57  } // make shure that the loading process is finished
58
59  // fill the scripts and triggers (doing that on runtime is very slow!)
60}
61
62
63
64void  ScriptManager::flush()
65{
66  //Delete all scripts as they aren't deleted automatically
67  while(!Script::objectList().empty())
68    delete Script::objectList().front();
69  //Delete all triggers
70  while(!ScriptTrigger::objectList().empty())
71    delete ScriptTrigger::objectList().front();
72
73}
74
75void  ScriptManager::createScripts(const TiXmlElement* scripts)
76{
77
78  LOAD_PARAM_START_CYCLE(scripts, object);
79  {
80    new Script(object);
81  }
82  LOAD_PARAM_END_CYCLE(object);
83
84}
85
86void ScriptManager::createTriggers(const TiXmlElement* triggers)
87{
88  LOAD_PARAM_START_CYCLE(triggers, object);
89  {
90    new ScriptTrigger(object);
91  }
92  LOAD_PARAM_END_CYCLE(object);
93
94}
95
96
97Script* ScriptManager::getScriptByFile(const std::string& file)
98{
99  for (ObjectList<Script>::const_iterator it = Script::objectList().begin();
100       it != Script::objectList().end();
101       ++it)
102    if( ((*it))->getFileName().compare(file) == 0)
103      return (*it);
104
105  return NULL;
106
107}
Note: See TracBrowser for help on using the repository browser.