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