Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9704 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
RevLine 
[8711]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
[8093]17#include <string>
18#include <list>
[8085]19
[8408]20#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
[8202]21
[8408]22
[8085]23#include "script_manager.h"
[8155]24#include "lunar.h"
[8093]25
[8202]26#include "class_list.h"
[8093]27
[8202]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
[8239]36ScriptManager::ScriptManager(const TiXmlElement* root)
[8093]37{
[8239]38  this->setName("ScriptManager");
39  this->scripts = NULL;
40  this->triggers = NULL;
41
42  if (root != NULL)
43    this->loadParams(root);
[8093]44}
45
[8239]46
47
[8093]48ScriptManager::~ScriptManager()
49{
[8239]50  this->flush();
[8093]51}
52
[8138]53
[8155]54void ScriptManager::loadParams(const TiXmlElement* root)
55{
[8408]56  BaseObject::loadParams(root);
[8206]57  {
[8239]58    LoadParamXML(root, "Scripts", this, ScriptManager, createScripts);
[8211]59
[8239]60    LoadParamXML(root, "ScriptTriggers", this, ScriptManager, createTriggers);
[8206]61  } // make shure that the loading process is finished
[8210]62
[8206]63  // fill the scripts and triggers (doing that on runtime is very slow!)
64  getTriggers();
65  getScripts();
[8239]66}
[8210]67
68
[8155]69
[8239]70void  ScriptManager::flush()
[8208]71{
[8210]72  //Delete all scripts as they aren't deleted automatically
[8239]73  if(this->getScripts())
74    while(!scripts->empty())
75      delete scripts->front();
[9003]76  //Delete all triggers
77  if(this->getTriggers())
78    while(!triggers->empty())
79      delete triggers->front();
80 
[8208]81}
82
[8202]83void  ScriptManager::createScripts(const TiXmlElement* scripts)
[8093]84{
[8210]85
[8193]86  LOAD_PARAM_START_CYCLE(scripts, object);
87  {
88    new Script(object);
89  }
90  LOAD_PARAM_END_CYCLE(object);
[8093]91
[8202]92}
[8131]93
[8202]94void ScriptManager::createTriggers(const TiXmlElement* triggers)
95{
96  LOAD_PARAM_START_CYCLE(triggers, object);
[8155]97  {
[8202]98    new ScriptTrigger(object);
99  }
100  LOAD_PARAM_END_CYCLE(object);
[8155]101
[8093]102}
103
[8171]104
[8212]105Script* ScriptManager::getScriptByFile(const std::string& file)
[8171]106{
[8206]107  if(getScripts())
[8239]108    for(std::list<BaseObject*>::const_iterator it = scripts->begin(); it != scripts->end(); it++ )
[8206]109    {
110      if( (dynamic_cast<Script*>(*it))->getFileName().compare(file) == 0)
[8239]111      {
112        return dynamic_cast<Script*>(*it);
113      }
114    }
[8210]115
[8206]116  return NULL;
[8171]117
118}
119
[8202]120
121bool ScriptManager::getScripts()
122{
[8210]123  return (this->scripts != NULL || (this->scripts = ClassList::getList(CL_SCRIPT)) != NULL);
[8202]124}
125
[8206]126bool ScriptManager::getTriggers()
127{
[8210]128  return (this->triggers != NULL || (this->triggers = ClassList::getList(CL_SCRIPT_TRIGGER)) != NULL);
[8206]129}
[8202]130
131
[8206]132
Note: See TracBrowser for help on using the repository browser.