Changeset 480 for code/branches/FICN/src/loader
- Timestamp:
- Dec 12, 2007, 7:54:44 PM (17 years ago)
- Location:
- code/branches/FICN/src/loader
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/loader/CMakeLists.txt
r471 r480 4 4 SET( LOADER_SRC_FILES 5 5 LevelLoader.cc 6 #../xml/xmlParser.cc7 ../tinyxml/tinystr.cc8 ../tinyxml/tinyxml.cc9 ../tinyxml/tinyxmlerror.cc10 ../tinyxml/tinyxmlparser.cc11 6 ) 12 7 13 8 ADD_LIBRARY(loader SHARED ${LOADER_SRC_FILES}) 9 10 TARGET_LINK_LIBRARIES( loader 11 xml 12 ) -
code/branches/FICN/src/loader/LevelLoader.cc
r474 r480 5 5 #include "tinyxml/tinyxml.h" 6 6 #include "orxonox/core/IdentifierIncludes.h" 7 #include "orxonox/core/Error.h" 8 #include "orxonox/objects/BaseObject.h" 7 9 8 10 using namespace std; … … 11 13 { 12 14 13 LevelLoader::LevelLoader(string file, string dir) 14 { 15 LevelLoader::LevelLoader(string file, string path) 16 { 17 valid_ = false; 18 15 19 // Load XML level file 16 dir.append("/");17 dir.append(file);20 path.append("/"); 21 path.append(file); 18 22 19 23 // Open xml file 20 TiXmlDocument doc(file);24 doc.LoadFile(path); 21 25 22 26 // Check if file was loaded … … 24 28 { 25 29 TiXmlHandle hDoc(&doc); 26 TiXmlHandle hRoot(0); 27 30 TiXmlHandle hRoot(0); 28 31 TiXmlElement* pElem; 29 30 32 31 33 // Check for root element … … 35 37 // Set root element 36 38 hRoot = TiXmlHandle(pElem); 39 rootElement = hRoot.Element(); 37 40 38 41 // Set level description … … 44 47 45 48 // Set level name 46 pElem = hRoot.Element(); 47 name_ = pElem->Attribute("name"); 48 image_ = pElem->Attribute("image"); 49 name_ = rootElement->Attribute("name"); 50 image_ = rootElement->Attribute("image"); 51 52 valid_ = true; 53 } 54 else 55 { 56 orxonox::Error("Level file has no valid root node"); 57 } 58 } 59 else 60 { 61 orxonox::Error("Could not load level file "); 62 } 63 } 64 65 void LevelLoader::loadLevel() 66 { 67 if (valid_) 68 { 69 TiXmlElement* loadElem; 70 TiXmlElement* worldElem; 71 TiXmlElement* tElem; 72 TiXmlNode* tNode; 73 49 74 50 75 // Set loading screen 51 pElem = hRoot.FirstChild("loading").Element();52 if ( pElem)76 loadElem = rootElement->FirstChildElement("loading"); 77 if (loadElem) 53 78 { 54 79 // Set background 55 pElem = hRoot.FirstChild("loading").FirstChild("background").Element();56 if ( pElem)80 tElem = loadElem->FirstChildElement("background"); 81 if (tElem) 57 82 { 58 loadingBackgroundColor_ = pElem->Attribute("color");59 loadingBackgroundImage_ = pElem->Attribute("image");83 loadingBackgroundColor_ = tElem->Attribute("color"); 84 loadingBackgroundImage_ = tElem->Attribute("image"); 60 85 } 61 86 // Set bar 62 pElem = hRoot.FirstChild("loading").FirstChild("bar").Element();63 if ( pElem)87 tElem = loadElem->FirstChildElement("bar"); 88 if (tElem) 64 89 { 65 loadingBarImage_ = pElem->Attribute("image");;66 loadingBarTop_ = pElem->Attribute("top");67 loadingBarLeft_ = pElem->Attribute("left");68 loadingBarWidth_ = pElem->Attribute("width");69 loadingBarHeight_ = pElem->Attribute("height");90 loadingBarImage_ = tElem->Attribute("image");; 91 loadingBarTop_ = tElem->Attribute("top"); 92 loadingBarLeft_ = tElem->Attribute("left"); 93 loadingBarWidth_ = tElem->Attribute("width"); 94 loadingBarHeight_ = tElem->Attribute("height"); 70 95 } 96 showLoadingScreen(); 71 97 } 72 73 74 } 75 else 76 { 77 std::string err = "Level file has no valid root node"; 78 std::cout << err << std::endl; 79 } 80 } 81 else 82 { 83 std::string err = "Could not load level file "; 84 err.append(file); 85 std::cout << err << std::endl; 86 } 98 99 // Load audio 100 // TODO 101 102 // Load scripts 103 // TODO 104 105 // Load world 106 worldElem = rootElement->FirstChildElement("world"); 107 if (worldElem) 108 { 109 tNode = 0; 110 while( tNode = worldElem->IterateChildren( tNode ) ) 111 { 112 tElem = tNode->ToElement(); 113 orxonox::BaseObject* obj = orxonox::ID(tElem->Value())->fabricate(); 114 obj->loadParams(tElem); 115 } 116 } 117 118 std::cout << "Loading finished!\n\n\n\n\n"; 119 } 120 } 121 122 void LevelLoader::showLoadingScreen() 123 { 124 std::cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n"; 125 std::cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n"; 126 std::cout << "Backgroundcolor: " << loadingBackgroundColor_ << "\nBackgroundimage:" << loadingBackgroundImage_ << "\n\n\n"; 127 } 87 128 88 129 … … 130 171 */ 131 172 132 } 173 133 174 134 175 LevelLoader::~LevelLoader() … … 154 195 } 155 196 156 void LevelLoader::showLoadingScreen()157 {158 cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n";159 cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n";160 }161 197 162 198 /* -
code/branches/FICN/src/loader/LevelLoader.h
r474 r480 24 24 { 25 25 private: 26 /*27 // XML Nodes28 XMLNode rootNode;29 XMLNode loadingScreenNode;30 XMLNode worldNode;31 XMLNode audioNode;32 XMLNode scriptsNode;33 */34 26 // Level information 35 27 std::string name_; 36 28 std::string description_; 37 29 std::string image_; 38 39 30 std::string loadingBackgroundColor_; 40 31 std::string loadingBackgroundImage_; … … 44 35 std::string loadingBarWidth_; 45 36 std::string loadingBarHeight_; 37 38 bool valid_; 46 39 40 TiXmlDocument doc; 41 TiXmlElement* rootElement; 47 42 public: 48 43 … … 52 47 53 48 void showLoadingScreen(); 49 void loadLevel(); 54 50 55 51 // Getters
Note: See TracChangeset
for help on using the changeset viewer.