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

View File

@ -1,5 +1,5 @@
#include "level.hh"
using namespace tinyxml2;
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.init();
@ -43,22 +64,31 @@ void Level::load() {
}
XMLElement* thisComposition = doc->FirstChildElement("composition");
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
int thisType;
thisComposition->QueryIntAttribute("typeID", &thisType);
int thisType = 0;
error = thisComposition->FirstChildElement("typeID")->QueryIntText(&thisType);
errorCheck(error);
XMLElement* compositionType = compositions->FirstChildElement("composition");
for(; compositionType; compositionType=compositionType->NextSiblingElement("composition")){
int compositionID;
compositionType->QueryIntAttribute("typeID", &compositionID);
int compositionID = 0;
error = compositionType->FirstChildElement("typeID")->QueryIntText(&compositionID);
errorCheck(error);
if(thisType == compositionID){
XMLElement* object = compositionType->FirstChildElement("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");
for(; light; light=light->NextSiblingElement("light")){
}
//Model model = Model("MarbleSmooth.obj", 0.75f);
}
}
}

View File

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