[7379] | 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: Andreas Maechler, David Hasenfratz |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include "atmospheric_engine.h" |
---|
| 17 | |
---|
| 18 | #include "util/loading/resource_manager.h" |
---|
| 19 | |
---|
| 20 | #include "effects/fog_effect.h" |
---|
| 21 | |
---|
| 22 | #include "util/loading/load_param.h" |
---|
| 23 | #include "util/loading/factory.h" |
---|
| 24 | #include "class_list.h" |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | |
---|
[9406] | 28 | |
---|
[7379] | 29 | /** |
---|
| 30 | * @param root The XML-element to load the AtmosphericEngine from |
---|
| 31 | */ |
---|
[8495] | 32 | AtmosphericEngine::AtmosphericEngine() { |
---|
| 33 | this->setClassID(CL_ATMOSPHERIC_ENGINE, "AtmosphericEngine"); |
---|
[7379] | 34 | } |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | * The Pointer to this AtmosphericEngine |
---|
| 38 | */ |
---|
| 39 | AtmosphericEngine* AtmosphericEngine::singletonRef = NULL; |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * destroys a AtmosphericEngine |
---|
| 44 | */ |
---|
[8495] | 45 | AtmosphericEngine::~AtmosphericEngine() { |
---|
| 46 | AtmosphericEngine::singletonRef = NULL; |
---|
[7503] | 47 | |
---|
[8495] | 48 | const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT); |
---|
[7503] | 49 | |
---|
[8495] | 50 | if (weatherEffects != NULL) { |
---|
| 51 | while(!weatherEffects->empty()) |
---|
| 52 | delete weatherEffects->front(); |
---|
| 53 | } |
---|
[7379] | 54 | } |
---|
| 55 | |
---|
| 56 | /** |
---|
| 57 | * @param root The XML-element to load the AtmosphericEngine from |
---|
| 58 | */ |
---|
[8495] | 59 | void AtmosphericEngine::loadParams(const TiXmlElement* root) { |
---|
| 60 | LoadParamXML(root, "WeatherEffect", this, AtmosphericEngine, loadWeatherEffect); |
---|
| 61 | LoadParamXML(root, "SunEffect", this, AtmosphericEngine, loadSunEffect); |
---|
[7379] | 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | * @param root The XML-element to load WeatherEffects from |
---|
| 66 | */ |
---|
[8495] | 67 | void AtmosphericEngine::loadWeatherEffect(const TiXmlElement* root) { |
---|
| 68 | LOAD_PARAM_START_CYCLE(root, element); |
---|
| 69 | { |
---|
| 70 | PRINTF(4)("element is: %s\n", element->Value()); |
---|
| 71 | // Factory::fabricate(element); |
---|
[7532] | 72 | |
---|
[8495] | 73 | BaseObject* bo = Factory::fabricate(element); |
---|
| 74 | if( bo == NULL) |
---|
| 75 | PRINTF(0)(" Could not create Element %s\n", element->Value()); |
---|
| 76 | } |
---|
| 77 | LOAD_PARAM_END_CYCLE(element); |
---|
[7379] | 78 | } |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | * @param root The XML-element to load SunEffects from |
---|
| 82 | */ |
---|
[8495] | 83 | void AtmosphericEngine::loadSunEffect(const TiXmlElement* root) { |
---|
| 84 | LOAD_PARAM_START_CYCLE(root, element); |
---|
| 85 | { |
---|
| 86 | PRINTF(4)("element is: %s\n", element->Value()); |
---|
| 87 | } |
---|
| 88 | LOAD_PARAM_END_CYCLE(element); |
---|
[7379] | 89 | } |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * draws the effect, if needed |
---|
| 94 | */ |
---|
[8495] | 95 | void AtmosphericEngine::draw() const { |
---|
| 96 | const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT); |
---|
[7379] | 97 | |
---|
[8495] | 98 | // draw the weather effects |
---|
| 99 | if (weatherEffects != NULL) { |
---|
| 100 | std::list<BaseObject*>::const_iterator it; |
---|
| 101 | for (it = weatherEffects->begin(); it != weatherEffects->end(); it++) |
---|
| 102 | dynamic_cast<WeatherEffect*>(*it)->draw(); |
---|
| 103 | } |
---|
[7514] | 104 | } |
---|
[7379] | 105 | |
---|
| 106 | |
---|
[7514] | 107 | |
---|
[7379] | 108 | /** |
---|
| 109 | * ticks the effect if there is any time dependancy |
---|
| 110 | */ |
---|
[8495] | 111 | void AtmosphericEngine::tick(float dt) { |
---|
| 112 | const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT); |
---|
[7514] | 113 | |
---|
[8495] | 114 | // tick the weather effects |
---|
| 115 | if (weatherEffects != NULL) { |
---|
| 116 | std::list<BaseObject*>::const_iterator it; |
---|
| 117 | for (it = weatherEffects->begin(); it != weatherEffects->end(); it++) { |
---|
[9406] | 118 | /* printf("%s::%s \n", (*it)->getClassCName(), (*it)->getName());*/ |
---|
[8495] | 119 | dynamic_cast<WeatherEffect*>(*it)->tick(dt); |
---|
| 120 | } |
---|
[7836] | 121 | } |
---|
[7514] | 122 | } |
---|