Changeset 790 for code/trunk/src/loader
- Timestamp:
- Feb 7, 2008, 5:01:44 PM (17 years ago)
- Location:
- code/trunk
- Files:
-
- 4 deleted
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
Property
svn:ignore
set to
dependencies
-
Property
svn:ignore
set to
-
code/trunk/src/loader/LevelLoader.cc
r164 r790 1 #include <string.h> 2 #include <iostream> 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 * 21 * Author: 22 * Nicolas Perrenoud <nicolape@ee.ethz.ch> 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 #include "OrxonoxStableHeaders.h" 29 30 #include <OgreOverlay.h> 31 #include <OgreOverlayManager.h> 32 33 #include "core/Error.h" 34 #include "core/Debug.h" 35 #include "core/CoreIncludes.h" 36 37 #include "audio/AudioManager.h" 38 #include "core/BaseObject.h" 39 #include "orxonox/Orxonox.h" 3 40 4 41 #include "LevelLoader.h" 5 #include "../xml/xmlParser.h"6 7 using namespace std;8 42 9 43 namespace loader 10 44 { 11 45 12 LevelLoader::LevelLoader(string file, string dir) 13 { 14 // Load XML level file 15 dir.append("/"); 16 dir.append(file); 17 rootNode = XMLNode::openFileHelper(dir.c_str(),"WorldDataFile"); 18 // TODO: Error handling 19 20 // Assing general level infos to class variables 21 this->name_ = rootNode.getChildNode("name").getText(); 22 this->description_ = rootNode.getChildNode("description").getText(); 23 this->image_ = rootNode.getChildNode("image").getText(); 24 25 this->loadingScreen(); 26 27 // Assign sub-nodes 28 if (rootNode.nChildNode("LightManager")==1) 46 LevelLoader::LevelLoader(std::string file, std::string path) 29 47 { 30 // Init Luightmanager... 48 valid_ = false; 49 50 // Load XML level file 51 path.append("/"); 52 path.append(file); 53 54 // Open xml file 55 doc_.LoadFile(path.c_str()); 56 57 // Check if file was loaded 58 if (doc_.LoadFile()) 59 { 60 TiXmlHandle hDoc(&doc_); 61 TiXmlHandle hRoot(0); 62 TiXmlElement* pElem; 63 64 // Check for root element 65 pElem = hDoc.FirstChildElement("orxonoxworld").Element(); 66 if (pElem) 67 { 68 // Set root element 69 hRoot = TiXmlHandle(pElem); 70 rootElement_ = hRoot.Element(); 71 72 // Set level description 73 pElem = hRoot.FirstChild("description").Element(); 74 if (pElem) 75 { 76 description_ = pElem->GetText(); 77 } 78 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 } 89 } 90 else 91 { 92 orxonox::Error("Could not load level file "); 93 } 31 94 } 32 33 /* 34 35 worldNode = rootNode.getChildNode("WorldEntities"); 36 scriptNode = rootNode.getChildNode("ScriptManager"); 37 cameraNode = rootNode.getChildNode("CameraMan"); 38 lightNode = rootNode.getChildNode("LightManager"); 39 */ 95 96 void LevelLoader::loadLevel() 97 { 98 if (valid_) 99 { 100 TiXmlElement* loadElem; 101 TiXmlElement* audioElem; 102 TiXmlElement* worldElem; 103 TiXmlElement* tElem; 104 TiXmlNode* tNode; 105 106 Ogre::OverlayManager& omgr = Ogre::OverlayManager::getSingleton(); 107 Ogre::Overlay* mLoadOverlay; // FIXME: may be uninitialized 108 109 // Set loading screen 110 loadElem = rootElement_->FirstChildElement("loading"); 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 } 130 131 132 mLoadOverlay = (Ogre::Overlay*)omgr.getByName("Orxonox/LoadingScreenSample"); 133 mLoadOverlay->show(); 134 135 COUT(0) << "This is Orxonox" << std::endl; 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; 139 140 } 141 142 // Load audio 143 audio::AudioManager* auMan = orxonox::Orxonox::getSingleton()->getAudioManagerPointer(); 144 audioElem = rootElement_->FirstChildElement("audio"); 145 146 if (audioElem) 147 { 148 audioElem = audioElem->FirstChildElement("ambient"); 149 if (audioElem) 150 { 151 tNode = 0; 152 //FIXME something is wrong, probably missing == 153 while( tNode = audioElem->IterateChildren( tNode ) ) 154 { 155 if (tNode->Type() == TiXmlNode::ELEMENT) 156 { 157 158 tElem = tNode->ToElement(); 159 std::string elemVal = tElem->Value(); 160 if (elemVal == "ogg") 161 { 162 COUT(3) << "Adding sound "<< tElem->Attribute("src") << std::endl; 163 164 auMan->ambientAdd(tElem->Attribute("src")); 165 } 166 } 167 } 168 auMan->ambientStart(); 169 } 170 } 171 172 // Load world 173 worldElem = rootElement_->FirstChildElement("world"); 174 if (worldElem) 175 { 176 tNode = 0; 177 //FIXME something is wrong, probably missing == 178 while (tNode = worldElem->IterateChildren(tNode)) 179 { 180 if (tNode->Type() == TiXmlNode::ELEMENT) 181 { 182 tElem = tNode->ToElement(); 183 orxonox::Identifier* id = ID(tElem->Value()); 184 if (id) 185 { 186 orxonox::BaseObject* obj = id->fabricate(); 187 obj->loadParams(tElem); 188 } 189 else 190 { 191 COUT(2) << "Warning: '"<< tElem->Value() <<"' is not a valid classname." << std::endl; 192 } 193 } 194 } 195 } 196 197 if (loadElem) 198 { 199 // FIXME: check for potential initialisation of mLoadOverlay 200 mLoadOverlay->hide(); 201 } 202 203 204 COUT(0) << "Loading finished!" << std::endl << std::endl; 205 } 206 } 207 208 LevelLoader::~LevelLoader() 209 { 210 211 } 40 212 41 213 } 42 43 LevelLoader::~LevelLoader()44 {45 46 47 }48 49 50 string LevelLoader::name()51 {52 return this->name_;53 }54 55 string LevelLoader::description()56 {57 return this->description_;58 }59 60 string LevelLoader::image()61 {62 return this->image_;63 }64 65 void LevelLoader::loadingScreen()66 {67 cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n";68 cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n";69 }70 71 /*72 73 74 void LevelLoader::loadWorld(WorldManager* wm)75 {76 if (!worldNode.getChildNode("lights").isEmpty())77 {78 79 80 }81 }82 83 84 void LevelLoader::loadLights(LightManager* lm)85 {86 if (!lightNode.getChildNode("lights").isEmpty())87 {88 int nLights = lightNode.getChildNode("lights").nChildNode("light");89 for (int i=0; i<nLights;i++)90 {91 XMLNode t = lightNode.getChildNode("lights").getChildNode("light",i);92 const char* diffuse = t.getAttribute("diffuse-color");93 const char* coor = t.getAttribute("abs-coor");94 lm->addLight(diffuse,coor);95 }96 }97 lm->setAmbient(lightNode.getChildNode("ambient").getAttribute("color"));98 }99 100 void LevelLoader::loadCameras(CameraManager* cm)101 {102 if (!cameraNode.getChildNode("cameras").isEmpty())103 {104 int nCameras = cameraNode.getChildNode("cameras").nChildNode("camera");105 for (int i=0; i<nCameras;i++)106 {107 XMLNode t = cameraNode.getChildNode("cameras").getChildNode("camera",i);108 109 110 cm->addCamera();111 }112 }113 }114 115 116 void LevelLoader::loadScripts(ScriptManager* sm)117 {118 if (!scriptNode.getChildNode("scripts").isEmpty())119 {120 int nScripts = scriptNode.getChildNode("scripts").nChildNode("script");121 for (int i=0; i<nScripts;i++)122 {123 XMLNode t = scriptNode.getChildNode("scripts").getChildNode("script",i);124 sm->addScript(t.getAttribute("file"));125 }126 127 }128 }129 */130 131 132 }133 -
code/trunk/src/loader/LevelLoader.h
r164 r790 2 2 * Orxonox - www.orxonox.net 3 3 * Level Loader class 4 * 4 * 5 5 * @author Nicolas Perrenoud <nicolape@ee.ethz.ch> 6 6 */ 7 7 8 #ifndef _LevelLoader_H__ 9 #define _LevelLoader_H__ 10 8 11 #include <string> 9 #include <iostream>10 12 11 #include "../xml/xmlParser.h" 13 #include "LoaderPrereqs.h" 14 #include "util/tinyxml/tinyxml.h" 12 15 13 #ifndef __MODULE_LEVELLOADER__ 14 #define __MODULE_LEVELLOADER__ 15 16 using namespace std; 16 class TiXmlDocument; // Forward declaration 17 class TiXmlElement; // Forward declaration 17 18 18 19 namespace loader 19 20 { 20 class LevelLoader 21 { 22 private: 23 24 // XML Nodes 25 XMLNode rootNode; 26 XMLNode worldNode; 27 XMLNode scriptNode; 28 XMLNode cameraNode; 29 XMLNode lightNode; 30 31 // Level information 32 string name_; 33 string description_; 34 string image_; 35 36 public: 21 class _LoaderExport LevelLoader 22 { 23 public: 24 // Constructors, loads the level file and some information data 25 LevelLoader(std::string file, std::string dir = "levels"); 26 // Destructor 27 virtual ~LevelLoader(); 28 // Loads all level data 29 void loadLevel(); 37 30 38 // Constructors 39 LevelLoader(string file, string dir="levels"); 40 ~LevelLoader(); 41 42 void loadingScreen(); 43 44 // Getters 45 string name(); 46 string description(); 47 string image(); 48 49 // Managers 50 51 52 }; 31 // Getters 32 inline std::string name() {return name_; }; 33 inline std::string description() {return description_; }; 34 inline std::string image() {return image_; }; 35 private: 36 //! Level information 37 std::string name_; 38 std::string description_; 39 std::string image_; 40 std::string loadingBackgroundColor_; 41 std::string loadingBackgroundImage_; 42 std::string loadingBarImage_; 43 std::string loadingBarTop_; 44 std::string loadingBarLeft_; 45 std::string loadingBarWidth_; 46 std::string loadingBarHeight_; 47 48 //! Set to true if it was possible to load the level file 49 bool valid_; 50 51 // Xml-Stuff 52 TiXmlDocument doc_; 53 TiXmlElement *rootElement_; 54 }; 53 55 } 54 #endif 56 57 #endif /* _LevelLoader_H__ */
Note: See TracChangeset
for help on using the changeset viewer.