[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] | 36 | ScriptManager::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] | 48 | ScriptManager::~ScriptManager() |
---|
| 49 | { |
---|
[8239] | 50 | this->flush(); |
---|
[8093] | 51 | } |
---|
| 52 | |
---|
[8138] | 53 | |
---|
[8155] | 54 | void 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] | 70 | void 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(); |
---|
[8208] | 76 | } |
---|
| 77 | |
---|
[8202] | 78 | void ScriptManager::createScripts(const TiXmlElement* scripts) |
---|
[8093] | 79 | { |
---|
[8210] | 80 | |
---|
[8193] | 81 | LOAD_PARAM_START_CYCLE(scripts, object); |
---|
| 82 | { |
---|
| 83 | new Script(object); |
---|
| 84 | } |
---|
| 85 | LOAD_PARAM_END_CYCLE(object); |
---|
[8093] | 86 | |
---|
[8202] | 87 | } |
---|
[8131] | 88 | |
---|
[8202] | 89 | void ScriptManager::createTriggers(const TiXmlElement* triggers) |
---|
| 90 | { |
---|
| 91 | LOAD_PARAM_START_CYCLE(triggers, object); |
---|
[8155] | 92 | { |
---|
[8202] | 93 | new ScriptTrigger(object); |
---|
| 94 | } |
---|
| 95 | LOAD_PARAM_END_CYCLE(object); |
---|
[8155] | 96 | |
---|
[8093] | 97 | } |
---|
| 98 | |
---|
[8171] | 99 | |
---|
[8212] | 100 | Script* ScriptManager::getScriptByFile(const std::string& file) |
---|
[8171] | 101 | { |
---|
[8206] | 102 | if(getScripts()) |
---|
[8239] | 103 | for(std::list<BaseObject*>::const_iterator it = scripts->begin(); it != scripts->end(); it++ ) |
---|
[8206] | 104 | { |
---|
| 105 | if( (dynamic_cast<Script*>(*it))->getFileName().compare(file) == 0) |
---|
[8239] | 106 | { |
---|
| 107 | return dynamic_cast<Script*>(*it); |
---|
| 108 | } |
---|
| 109 | } |
---|
[8210] | 110 | |
---|
[8206] | 111 | return NULL; |
---|
[8171] | 112 | |
---|
| 113 | } |
---|
| 114 | |
---|
[8202] | 115 | |
---|
| 116 | bool ScriptManager::getScripts() |
---|
| 117 | { |
---|
[8210] | 118 | return (this->scripts != NULL || (this->scripts = ClassList::getList(CL_SCRIPT)) != NULL); |
---|
[8202] | 119 | } |
---|
| 120 | |
---|
[8206] | 121 | bool ScriptManager::getTriggers() |
---|
| 122 | { |
---|
[8210] | 123 | return (this->triggers != NULL || (this->triggers = ClassList::getList(CL_SCRIPT_TRIGGER)) != NULL); |
---|
[8206] | 124 | } |
---|
[8202] | 125 | |
---|
| 126 | |
---|
[8206] | 127 | |
---|