Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/scriptimprovements/src/lib/script_engine/script_manager.cc @ 10611

Last change on this file since 10611 was 10611, checked in by snellen, 17 years ago

Triggers can now be creater from the xml file… again

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