Implemented error checking for XML. Fixed loading of OBJ-Files.

This commit is contained in:
Steffen Fündgens 2014-12-05 14:45:44 +01:00
parent 5e44f9680e
commit 24edf1aca9
3 changed files with 51 additions and 21 deletions

View File

@ -1,7 +1,7 @@
<composition> <composition>
<typeID>20</typeID> <typeID>20</typeID>
<object> <object>
<filePath>../Levels/Geometry/MarbleSmooth.obj</filePath> <modelPath>MarbleSmooth.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
<yOffset>0.0</yOffset> <yOffset>0.0</yOffset>
<zOffset>0.0</zOffset> <zOffset>0.0</zOffset>
@ -12,7 +12,7 @@
<composition> <composition>
<typeID>40</typeID> <typeID>40</typeID>
<object> <object>
<filePath>../Levels/Geometry/Block.obj</filePath> <modelPath>Block.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
<yOffset>1.0</yOffset> <yOffset>1.0</yOffset>
<zOffset>2.0</zOffset> <zOffset>2.0</zOffset>
@ -23,7 +23,7 @@
<composition> <composition>
<typeID>60</typeID> <typeID>60</typeID>
<object> <object>
<filePath>../Levels/Geometry/Column.obj</filePath> <modelPath>Column.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
<yOffset>0.0</yOffset> <yOffset>0.0</yOffset>
<zOffset>0.0</zOffset> <zOffset>0.0</zOffset>
@ -34,13 +34,13 @@
<composition> <composition>
<typeID>80</typeID> <typeID>80</typeID>
<object> <object>
<filePath>../Levels/Geometry/torch.obj</filePath> <modelPath>torch.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
<yOffset>0.0</yOffset> <yOffset>0.0</yOffset>
<zOffset>0.0</zOffset> <zOffset>0.0</zOffset>
<scale>1.0</scale> <scale>1.0</scale>
</object> </object>
<object> <light>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
<yOffset>1.0</yOffset> <yOffset>1.0</yOffset>
<zOffset>0.0</zOffset> <zOffset>0.0</zOffset>
@ -48,28 +48,27 @@
<gColour>1.0</gColour> <gColour>1.0</gColour>
<bColour>1.0</bColour> <bColour>1.0</bColour>
<intensity>5.0</intensity> <intensity>5.0</intensity>
<scale>0.0</scale> </light>
</object>
</composition> </composition>
<composition> <composition>
<typeID>99</typeID> <typeID>99</typeID>
<object> <object>
<filePath>../Levels/Geometry/Column.obj</filePath> <modelPath>Column.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
<yOffset>0.0</yOffset> <yOffset>0.0</yOffset>
<zOffset>0.0</zOffset> <zOffset>0.0</zOffset>
<scale>1.0</scale> <scale>1.0</scale>
</object> </object>
<object> <object>
<filePath>../Levels/Geometry/Column.obj</filePath> <modelPath>Column.obj</modelPath>
<xOffset>2.0</xOffset> <xOffset>2.0</xOffset>
<yOffset>0.0</yOffset> <yOffset>0.0</yOffset>
<zOffset>0.0</zOffset> <zOffset>0.0</zOffset>
<scale>1.0</scale> <scale>1.0</scale>
</object> </object>
<object> <object>
<filePath>../Levels/Geometry/Block.obj</filePath> <modelPath>Block.obj</modelPath>
<xOffset>1.0</xOffset> <xOffset>1.0</xOffset>
<yOffset>3.0</yOffset> <yOffset>3.0</yOffset>
<zOffset>0.0</zOffset> <zOffset>0.0</zOffset>
@ -80,14 +79,14 @@
<composition> <composition>
<typeID>120</typeID> <typeID>120</typeID>
<object> <object>
<filePath>../Levels/Geometry/switch_inner.obj</filePath> <modelPath>switch_inner.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
<yOffset>0.0</yOffset> <yOffset>0.0</yOffset>
<zOffset>0.0</zOffset> <zOffset>0.0</zOffset>
<scale>1.0</scale> <scale>1.0</scale>
</object> </object>
<object> <object>
<filePath>../Levels/Geometry/switch_outer.obj</filePath> <modelPath>switch_outer.obj</modelPath>
<xOffset>0.0</xOffset> <xOffset>0.0</xOffset>
<yOffset>0.0</yOffset> <yOffset>0.0</yOffset>
<zOffset>0.0</zOffset> <zOffset>0.0</zOffset>

View File

@ -1,5 +1,5 @@
#include "level.hh" #include "level.hh"
using namespace tinyxml2;
Level::Level(std::string levelNum){ Level::Level(std::string levelNum){
@ -17,9 +17,30 @@ Level::~Level() {
} }
} }
using namespace tinyxml2;
void Level::load() {
void Level::errorCheck(XMLError error){
if (error) {
printf("XMLError: ");
if (error == XML_WRONG_ATTRIBUTE_TYPE) {
printf("Wrong attribute type.\n");
}
else if (error == XML_NO_ATTRIBUTE) {
printf("No attribute.\n");
}
else if (error == XML_CAN_NOT_CONVERT_TEXT) {
printf("Can not convert text.\n");
}
else if (error == XML_NO_TEXT_NODE) {
printf("No text.\n");
}
else {
printf("Unknown error.\n");
}
}
}
void Level::load() {
XMLError error=XML_NO_ERROR;
this->physics = Physics(); this->physics = Physics();
this->physics.init(); this->physics.init();
@ -43,22 +64,31 @@ void Level::load() {
} }
XMLElement* thisComposition = doc->FirstChildElement("composition"); XMLElement* thisComposition = doc->FirstChildElement("composition");
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){ for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
int thisType; int thisType = 0;
thisComposition->QueryIntAttribute("typeID", &thisType); error = thisComposition->FirstChildElement("typeID")->QueryIntText(&thisType);
errorCheck(error);
XMLElement* compositionType = compositions->FirstChildElement("composition"); XMLElement* compositionType = compositions->FirstChildElement("composition");
for(; compositionType; compositionType=compositionType->NextSiblingElement("composition")){ for(; compositionType; compositionType=compositionType->NextSiblingElement("composition")){
int compositionID; int compositionID = 0;
compositionType->QueryIntAttribute("typeID", &compositionID); error = compositionType->FirstChildElement("typeID")->QueryIntText(&compositionID);
errorCheck(error);
if(thisType == compositionID){ if(thisType == compositionID){
XMLElement* object = compositionType->FirstChildElement("object"); XMLElement* object = compositionType->FirstChildElement("object");
for(; object; object=object->NextSiblingElement("object")){ for(; object; object=object->NextSiblingElement("object")){
const char* charModelPath = object->FirstChildElement("modelPath")->GetText();
if(charModelPath == NULL){
printf("XMLError: No modelPath found.\n");
}
std::string modelPath = charModelPath;
float scale;
object->FirstChildElement("scale")->QueryFloatText(&scale);
Model model = Model(modelPath, scale);
} }
XMLElement* light = compositionType->FirstChildElement("light"); XMLElement* light = compositionType->FirstChildElement("light");
for(; light; light=light->NextSiblingElement("light")){ for(; light; light=light->NextSiblingElement("light")){
} }
//Model model = Model("MarbleSmooth.obj", 0.75f);
} }
} }
} }

View File

@ -28,6 +28,7 @@ class Level {
glm::vec4 getFogColor(); glm::vec4 getFogColor();
void setSkydomeSize(float size); void setSkydomeSize(float size);
private: private:
void errorCheck(tinyxml2::XMLError error);
std::string levelNum; std::string levelNum;
std::vector<Object*> objects; std::vector<Object*> objects;
std::vector<Object*> physicObjects; std::vector<Object*> physicObjects;