[513] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License |
---|
| 9 | * as published by the Free Software Foundation; either version 2 |
---|
| 10 | * of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 20 | * |
---|
[616] | 21 | * Author: |
---|
[585] | 22 | * Nicolas Perrenoud <nicolape@ee.ethz.ch> |
---|
[513] | 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
[507] | 28 | #include <string> |
---|
| 29 | #include <vector> |
---|
[164] | 30 | #include <iostream> |
---|
[507] | 31 | #include <algorithm> |
---|
| 32 | #include <iterator> |
---|
[164] | 33 | |
---|
[521] | 34 | #include <OgreOverlayManager.h> |
---|
| 35 | |
---|
[164] | 36 | #include "LevelLoader.h" |
---|
[471] | 37 | #include "tinyxml/tinyxml.h" |
---|
[496] | 38 | #include "orxonox/core/CoreIncludes.h" |
---|
[480] | 39 | #include "orxonox/core/Error.h" |
---|
| 40 | #include "orxonox/objects/BaseObject.h" |
---|
[584] | 41 | #include "audio/AudioManager.h" |
---|
[614] | 42 | #include "orxonox/Orxonox.h" |
---|
[164] | 43 | |
---|
| 44 | using namespace std; |
---|
| 45 | |
---|
| 46 | namespace loader |
---|
| 47 | { |
---|
| 48 | |
---|
[480] | 49 | LevelLoader::LevelLoader(string file, string path) |
---|
[164] | 50 | { |
---|
[480] | 51 | valid_ = false; |
---|
[513] | 52 | |
---|
[164] | 53 | // Load XML level file |
---|
[480] | 54 | path.append("/"); |
---|
[513] | 55 | path.append(file); |
---|
| 56 | |
---|
[474] | 57 | // Open xml file |
---|
[480] | 58 | doc.LoadFile(path); |
---|
[474] | 59 | |
---|
| 60 | // Check if file was loaded |
---|
| 61 | if (doc.LoadFile()) |
---|
[471] | 62 | { |
---|
[474] | 63 | TiXmlHandle hDoc(&doc); |
---|
[513] | 64 | TiXmlHandle hRoot(0); |
---|
[474] | 65 | TiXmlElement* pElem; |
---|
| 66 | |
---|
| 67 | // Check for root element |
---|
| 68 | pElem = hDoc.FirstChildElement("orxonoxworld").Element(); |
---|
| 69 | if (pElem) |
---|
| 70 | { |
---|
| 71 | // Set root element |
---|
| 72 | hRoot = TiXmlHandle(pElem); |
---|
[480] | 73 | rootElement = hRoot.Element(); |
---|
[474] | 74 | |
---|
| 75 | // Set level description |
---|
| 76 | pElem = hRoot.FirstChild("description").Element(); |
---|
| 77 | if (pElem) |
---|
| 78 | { |
---|
[513] | 79 | description_ = pElem->GetText(); |
---|
[474] | 80 | } |
---|
[513] | 81 | |
---|
[474] | 82 | // Set level name |
---|
[480] | 83 | name_ = rootElement->Attribute("name"); |
---|
| 84 | image_ = rootElement->Attribute("image"); |
---|
[513] | 85 | |
---|
[480] | 86 | valid_ = true; |
---|
| 87 | } |
---|
| 88 | else |
---|
| 89 | { |
---|
| 90 | orxonox::Error("Level file has no valid root node"); |
---|
[513] | 91 | } |
---|
[480] | 92 | } |
---|
| 93 | else |
---|
| 94 | { |
---|
| 95 | orxonox::Error("Could not load level file "); |
---|
[513] | 96 | } |
---|
[480] | 97 | } |
---|
| 98 | |
---|
| 99 | void LevelLoader::loadLevel() |
---|
| 100 | { |
---|
| 101 | if (valid_) |
---|
| 102 | { |
---|
| 103 | TiXmlElement* loadElem; |
---|
[584] | 104 | TiXmlElement* audioElem; |
---|
[480] | 105 | TiXmlElement* worldElem; |
---|
| 106 | TiXmlElement* tElem; |
---|
| 107 | TiXmlNode* tNode; |
---|
[513] | 108 | |
---|
[525] | 109 | Ogre::OverlayManager& omgr = Ogre::OverlayManager::getSingleton(); |
---|
| 110 | Ogre::Overlay* mLoadOverlay; |
---|
[513] | 111 | |
---|
[474] | 112 | // Set loading screen |
---|
[480] | 113 | loadElem = rootElement->FirstChildElement("loading"); |
---|
| 114 | if (loadElem) |
---|
[474] | 115 | { |
---|
| 116 | // Set background |
---|
[480] | 117 | tElem = loadElem->FirstChildElement("background"); |
---|
| 118 | if (tElem) |
---|
[474] | 119 | { |
---|
[480] | 120 | loadingBackgroundColor_ = tElem->Attribute("color"); |
---|
| 121 | loadingBackgroundImage_ = tElem->Attribute("image"); |
---|
[474] | 122 | } |
---|
| 123 | // Set bar |
---|
[480] | 124 | tElem = loadElem->FirstChildElement("bar"); |
---|
| 125 | if (tElem) |
---|
[474] | 126 | { |
---|
[480] | 127 | loadingBarImage_ = tElem->Attribute("image");; |
---|
| 128 | loadingBarTop_ = tElem->Attribute("top"); |
---|
| 129 | loadingBarLeft_ = tElem->Attribute("left"); |
---|
| 130 | loadingBarWidth_ = tElem->Attribute("width"); |
---|
| 131 | loadingBarHeight_ = tElem->Attribute("height"); |
---|
[474] | 132 | } |
---|
[559] | 133 | |
---|
| 134 | |
---|
[525] | 135 | mLoadOverlay = (Ogre::Overlay*)omgr.getByName("Orxonox/LoadingScreenSample"); |
---|
[559] | 136 | mLoadOverlay->show(); |
---|
[525] | 137 | |
---|
[560] | 138 | COUT(0) << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n"; |
---|
| 139 | COUT(0) << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n"; |
---|
| 140 | COUT(4) << "Backgroundcolor: " << loadingBackgroundColor_ << "\nBackgroundimage:" << loadingBackgroundImage_ << "\n\n\n"; |
---|
[559] | 141 | |
---|
[474] | 142 | } |
---|
[513] | 143 | |
---|
[480] | 144 | // Load audio |
---|
[584] | 145 | audio::AudioManager* auMan = orxonox::Orxonox::getSingleton()->getAudioManagerPointer(); |
---|
| 146 | audioElem = rootElement->FirstChildElement("audio"); |
---|
| 147 | if (audioElem) |
---|
| 148 | { |
---|
| 149 | audioElem = audioElem->FirstChildElement("ambient"); |
---|
| 150 | if (audioElem) |
---|
| 151 | { |
---|
| 152 | tNode = 0; |
---|
| 153 | while( tNode = audioElem->IterateChildren( tNode ) ) |
---|
| 154 | { |
---|
[625] | 155 | if (tNode->Type() == TiXmlNode::ELEMENT) |
---|
| 156 | { |
---|
| 157 | tElem = tNode->ToElement(); |
---|
| 158 | std::string elemVal = tElem->Value(); |
---|
| 159 | if (elemVal == "ogg") |
---|
| 160 | { |
---|
| 161 | auMan->ambientAdd(tElem->Attribute("src")); |
---|
| 162 | } |
---|
| 163 | } |
---|
[616] | 164 | } |
---|
| 165 | } |
---|
[584] | 166 | } |
---|
[616] | 167 | |
---|
[480] | 168 | // Load world |
---|
| 169 | worldElem = rootElement->FirstChildElement("world"); |
---|
| 170 | if (worldElem) |
---|
[513] | 171 | { |
---|
[480] | 172 | tNode = 0; |
---|
[625] | 173 | while (tNode = worldElem->IterateChildren(tNode)) |
---|
[480] | 174 | { |
---|
[625] | 175 | if (tNode->Type() == TiXmlNode::ELEMENT) |
---|
| 176 | { |
---|
| 177 | tElem = tNode->ToElement(); |
---|
| 178 | orxonox::Identifier* id = ID(tElem->Value()); |
---|
| 179 | if (id) |
---|
| 180 | { |
---|
| 181 | orxonox::BaseObject* obj = id->fabricate(); |
---|
| 182 | obj->loadParams(tElem); |
---|
| 183 | } |
---|
| 184 | else |
---|
| 185 | { |
---|
| 186 | COUT(2) << "Warning: '"<< tElem->Value() <<"' is not a valid classname.\n"; |
---|
| 187 | } |
---|
| 188 | } |
---|
[513] | 189 | } |
---|
[480] | 190 | } |
---|
[559] | 191 | |
---|
[525] | 192 | if (loadElem) |
---|
| 193 | { |
---|
| 194 | mLoadOverlay->hide(); |
---|
| 195 | } |
---|
[560] | 196 | COUT(0) << "Loading finished!\n\n\n\n\n"; |
---|
[474] | 197 | } |
---|
[471] | 198 | } |
---|
[513] | 199 | |
---|
[507] | 200 | LevelLoader::~LevelLoader() |
---|
| 201 | { |
---|
| 202 | |
---|
| 203 | } |
---|
[513] | 204 | |
---|
| 205 | |
---|
[507] | 206 | string LevelLoader::name() |
---|
[164] | 207 | { |
---|
[507] | 208 | return this->name_; |
---|
[164] | 209 | } |
---|
[513] | 210 | |
---|
[507] | 211 | string LevelLoader::description() |
---|
[164] | 212 | { |
---|
[507] | 213 | return this->description_; |
---|
[164] | 214 | } |
---|
[513] | 215 | |
---|
[507] | 216 | string LevelLoader::image() |
---|
[164] | 217 | { |
---|
[507] | 218 | return this->image_; |
---|
[164] | 219 | } |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | } |
---|
| 223 | |
---|