From 4d1fbc60458554b1bd77e2aae7ae3d3a0192e1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Fri, 5 Dec 2014 14:45:44 +0100 Subject: [PATCH] Implemented error checking for XML. Fixed loading of OBJ-Files. --- Levels/ObjectSetups/Compositions.xml | 23 +++++++------ level.cc | 48 ++++++++++++++++++++++------ level.hh | 1 + 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/Levels/ObjectSetups/Compositions.xml b/Levels/ObjectSetups/Compositions.xml index 0b8dc86..4e69e2b 100644 --- a/Levels/ObjectSetups/Compositions.xml +++ b/Levels/ObjectSetups/Compositions.xml @@ -1,7 +1,7 @@ 20 - ../Levels/Geometry/MarbleSmooth.obj + MarbleSmooth.obj 0.0 0.0 0.0 @@ -12,7 +12,7 @@ 40 - ../Levels/Geometry/Block.obj + Block.obj 0.0 1.0 2.0 @@ -23,7 +23,7 @@ 60 - ../Levels/Geometry/Column.obj + Column.obj 0.0 0.0 0.0 @@ -34,13 +34,13 @@ 80 - ../Levels/Geometry/torch.obj + torch.obj 0.0 0.0 0.0 1.0 - + 0.0 1.0 0.0 @@ -48,28 +48,27 @@ 1.0 1.0 5.0 - 0.0 - + 99 - ../Levels/Geometry/Column.obj + Column.obj 0.0 0.0 0.0 1.0 - ../Levels/Geometry/Column.obj + Column.obj 2.0 0.0 0.0 1.0 - ../Levels/Geometry/Block.obj + Block.obj 1.0 3.0 0.0 @@ -80,14 +79,14 @@ 120 - ../Levels/Geometry/switch_inner.obj + switch_inner.obj 0.0 0.0 0.0 1.0 - ../Levels/Geometry/switch_outer.obj + switch_outer.obj 0.0 0.0 0.0 diff --git a/level.cc b/level.cc index 1765bd5..08cc477 100644 --- a/level.cc +++ b/level.cc @@ -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); } } } diff --git a/level.hh b/level.hh index a54263c..3c08e77 100644 --- a/level.hh +++ b/level.hh @@ -28,6 +28,7 @@ class Level { glm::vec4 getFogColor(); void setSkydomeSize(float size); private: + void errorCheck(tinyxml2::XMLError error); std::string levelNum; std::vector objects; std::vector physicObjects;