[513] | 1 | /* |
---|
[682] | 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 | * |
---|
| 21 | * Author: |
---|
| 22 | * Nicolas Perrenoud <nicolape@ee.ethz.ch> |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
[513] | 27 | |
---|
[682] | 28 | #include <OgreOverlay.h> |
---|
[521] | 29 | #include <OgreOverlayManager.h> |
---|
| 30 | |
---|
[682] | 31 | #include "orxonox/core/Error.h" |
---|
| 32 | #include "orxonox/core/Debug.h" |
---|
[496] | 33 | #include "orxonox/core/CoreIncludes.h" |
---|
[682] | 34 | |
---|
| 35 | #include "audio/AudioManager.h" |
---|
[480] | 36 | #include "orxonox/objects/BaseObject.h" |
---|
[614] | 37 | #include "orxonox/Orxonox.h" |
---|
[164] | 38 | |
---|
[682] | 39 | #include "LevelLoader.h" |
---|
[164] | 40 | |
---|
| 41 | namespace loader |
---|
| 42 | { |
---|
| 43 | |
---|
[682] | 44 | LevelLoader::LevelLoader(std::string file, std::string path) |
---|
| 45 | { |
---|
| 46 | valid_ = false; |
---|
[513] | 47 | |
---|
[682] | 48 | // Load XML level file |
---|
| 49 | path.append("/"); |
---|
| 50 | path.append(file); |
---|
[513] | 51 | |
---|
[682] | 52 | // Open xml file |
---|
| 53 | doc_.LoadFile(path); |
---|
[474] | 54 | |
---|
[682] | 55 | // Check if file was loaded |
---|
| 56 | if (doc_.LoadFile()) |
---|
[661] | 57 | { |
---|
[682] | 58 | TiXmlHandle hDoc(&doc_); |
---|
| 59 | TiXmlHandle hRoot(0); |
---|
| 60 | TiXmlElement* pElem; |
---|
[474] | 61 | |
---|
[682] | 62 | // Check for root element |
---|
| 63 | pElem = hDoc.FirstChildElement("orxonoxworld").Element(); |
---|
[661] | 64 | if (pElem) |
---|
| 65 | { |
---|
[682] | 66 | // Set root element |
---|
| 67 | hRoot = TiXmlHandle(pElem); |
---|
| 68 | rootElement_ = hRoot.Element(); |
---|
[513] | 69 | |
---|
[682] | 70 | // Set level description |
---|
| 71 | pElem = hRoot.FirstChild("description").Element(); |
---|
| 72 | if (pElem) |
---|
| 73 | { |
---|
| 74 | description_ = pElem->GetText(); |
---|
| 75 | } |
---|
[513] | 76 | |
---|
[682] | 77 | // Set level name |
---|
| 78 | name_ = rootElement_->Attribute("name"); |
---|
| 79 | image_ = rootElement_->Attribute("image"); |
---|
| 80 | |
---|
| 81 | valid_ = true; |
---|
| 82 | } |
---|
| 83 | else |
---|
| 84 | { |
---|
| 85 | orxonox::Error("Level file has no valid root node"); |
---|
| 86 | } |
---|
[661] | 87 | } |
---|
| 88 | else |
---|
| 89 | { |
---|
[682] | 90 | orxonox::Error("Could not load level file "); |
---|
[661] | 91 | } |
---|
| 92 | } |
---|
[480] | 93 | |
---|
[661] | 94 | void LevelLoader::loadLevel() |
---|
| 95 | { |
---|
| 96 | if (valid_) |
---|
| 97 | { |
---|
| 98 | TiXmlElement* loadElem; |
---|
| 99 | TiXmlElement* audioElem; |
---|
| 100 | TiXmlElement* worldElem; |
---|
| 101 | TiXmlElement* tElem; |
---|
| 102 | TiXmlNode* tNode; |
---|
[513] | 103 | |
---|
[661] | 104 | Ogre::OverlayManager& omgr = Ogre::OverlayManager::getSingleton(); |
---|
| 105 | Ogre::Overlay* mLoadOverlay; // FIXME: mey be uninitialized |
---|
[513] | 106 | |
---|
[661] | 107 | // Set loading screen |
---|
[682] | 108 | loadElem = rootElement_->FirstChildElement("loading"); |
---|
[661] | 109 | if (loadElem) |
---|
| 110 | { |
---|
| 111 | // Set background |
---|
| 112 | tElem = loadElem->FirstChildElement("background"); |
---|
| 113 | if (tElem) |
---|
| 114 | { |
---|
| 115 | loadingBackgroundColor_ = tElem->Attribute("color"); |
---|
| 116 | loadingBackgroundImage_ = tElem->Attribute("image"); |
---|
| 117 | } |
---|
| 118 | // Set bar |
---|
| 119 | tElem = loadElem->FirstChildElement("bar"); |
---|
| 120 | if (tElem) |
---|
| 121 | { |
---|
| 122 | loadingBarImage_ = tElem->Attribute("image");; |
---|
| 123 | loadingBarTop_ = tElem->Attribute("top"); |
---|
| 124 | loadingBarLeft_ = tElem->Attribute("left"); |
---|
| 125 | loadingBarWidth_ = tElem->Attribute("width"); |
---|
| 126 | loadingBarHeight_ = tElem->Attribute("height"); |
---|
| 127 | } |
---|
[559] | 128 | |
---|
| 129 | |
---|
[661] | 130 | mLoadOverlay = (Ogre::Overlay*)omgr.getByName("Orxonox/LoadingScreenSample"); |
---|
| 131 | mLoadOverlay->show(); |
---|
[525] | 132 | |
---|
[677] | 133 | COUT(0) << "This is Orxonox" << std::endl; |
---|
| 134 | COUT(0) << "the hottest 3D action shooter ever to exist" << std::endl; |
---|
| 135 | COUT(0) << "Level: " << name() << std::endl << "Description:" << description() << std::endl << "Image:" << image() << std::endl; |
---|
| 136 | COUT(4) << "Backgroundcolor: " << loadingBackgroundColor_ << std::endl << "Backgroundimage:" << loadingBackgroundImage_ << std::endl; |
---|
[559] | 137 | |
---|
[661] | 138 | } |
---|
[513] | 139 | |
---|
[661] | 140 | // Load audio |
---|
| 141 | audio::AudioManager* auMan = orxonox::Orxonox::getSingleton()->getAudioManagerPointer(); |
---|
[682] | 142 | audioElem = rootElement_->FirstChildElement("audio"); |
---|
[655] | 143 | |
---|
[661] | 144 | if (audioElem) |
---|
| 145 | { |
---|
| 146 | audioElem = audioElem->FirstChildElement("ambient"); |
---|
| 147 | if (audioElem) |
---|
| 148 | { |
---|
| 149 | tNode = 0; |
---|
[660] | 150 | //FIXME something is wrong, probably missing == |
---|
[661] | 151 | while( tNode = audioElem->IterateChildren( tNode ) ) |
---|
| 152 | { |
---|
[625] | 153 | if (tNode->Type() == TiXmlNode::ELEMENT) |
---|
| 154 | { |
---|
[655] | 155 | |
---|
[661] | 156 | tElem = tNode->ToElement(); |
---|
| 157 | std::string elemVal = tElem->Value(); |
---|
| 158 | if (elemVal == "ogg") |
---|
| 159 | { |
---|
[677] | 160 | COUT(3) << "Adding sound "<< tElem->Attribute("src") << std::endl; |
---|
[655] | 161 | |
---|
[661] | 162 | auMan->ambientAdd(tElem->Attribute("src")); |
---|
| 163 | } |
---|
[625] | 164 | } |
---|
[661] | 165 | } |
---|
| 166 | auMan->ambientStart(); |
---|
| 167 | } |
---|
| 168 | } |
---|
[616] | 169 | |
---|
[661] | 170 | // Load world |
---|
[682] | 171 | worldElem = rootElement_->FirstChildElement("world"); |
---|
[661] | 172 | if (worldElem) |
---|
| 173 | { |
---|
| 174 | tNode = 0; |
---|
[663] | 175 | //FIXME something is wrong, probably missing == |
---|
[661] | 176 | while (tNode = worldElem->IterateChildren(tNode)) |
---|
| 177 | { |
---|
[625] | 178 | if (tNode->Type() == TiXmlNode::ELEMENT) |
---|
| 179 | { |
---|
[661] | 180 | tElem = tNode->ToElement(); |
---|
| 181 | orxonox::Identifier* id = ID(tElem->Value()); |
---|
| 182 | if (id) |
---|
| 183 | { |
---|
[677] | 184 | orxonox::BaseObject* obj = id->fabricate(); |
---|
| 185 | obj->loadParams(tElem); |
---|
[661] | 186 | } |
---|
| 187 | else |
---|
| 188 | { |
---|
[682] | 189 | COUT(2) << "Warning: '"<< tElem->Value() <<"' is not a valid classname." << std::endl; |
---|
[661] | 190 | } |
---|
[625] | 191 | } |
---|
[661] | 192 | } |
---|
| 193 | } |
---|
[559] | 194 | |
---|
[661] | 195 | if (loadElem) |
---|
| 196 | { |
---|
[681] | 197 | // FIXME: check for potential initialisation of mLoadOverlay |
---|
[682] | 198 | mLoadOverlay->hide(); |
---|
[661] | 199 | } |
---|
[659] | 200 | |
---|
| 201 | |
---|
[677] | 202 | COUT(0) << "Loading finished!" << std::endl << std::endl; |
---|
[661] | 203 | } |
---|
| 204 | } |
---|
[513] | 205 | |
---|
[661] | 206 | LevelLoader::~LevelLoader() |
---|
| 207 | { |
---|
[507] | 208 | |
---|
[661] | 209 | } |
---|
[513] | 210 | |
---|
[164] | 211 | } |
---|