diff --git a/application.cc b/application.cc index 5bfbc9f..f23bf8e 100644 --- a/application.cc +++ b/application.cc @@ -1,8 +1,10 @@ #include "application.hh" #include "loader.hh" - +using namespace tinyxml2; Application::Application() { + //load the config.xml + loadConfig(); graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 150.0f); } @@ -74,3 +76,87 @@ int Application::getIgnoredMouseUpdates() { bool Application::isLocked() { return cameraLock; } + +void Application::loadConfig() { + XMLDocument* config = new XMLDocument(); + const char* xmlFile = "../data/config.xml"; + config->LoadFile(xmlFile); + if (config->ErrorID()!=0){ + printf("Could not open config.xml!\n"); + exit(-1); + } + XMLElement* resolution = config->FirstChildElement("resolution"); + errorCheck(resolution->FirstChildElement("width")->QueryIntText(&windowWidth)); + errorCheck(resolution->FirstChildElement("height")->QueryIntText(&windowHeight)); + errorCheck(config->FirstChildElement("farPlane")->QueryFloatText(&farPlane)); + const char* charCompositionsPath = config->FirstChildElement("compositionsPath")->GetText(); + if(charCompositionsPath == NULL){ + printf("XMLError: No compositionsPath found.\n"); + exit(-1); + } + compositionsPath = charCompositionsPath; + + const char* charShaderPath = config->FirstChildElement("shaderPath")->GetText(); + if(charShaderPath == NULL){ + printf("XMLError: No shaderPath found.\n"); + exit(-1); + } + shaderPath = charShaderPath; + + const char* charGeometryPath = config->FirstChildElement("geometryPath")->GetText(); + if(charGeometryPath == NULL){ + printf("XMLError: No geometryPath found.\n"); + exit(-1); + } + geometryPath = charGeometryPath; + + const char* charTexturePath = config->FirstChildElement("texturePath")->GetText(); + if(charTexturePath == NULL){ + printf("XMLError: No texturePath found.\n"); + exit(-1); + } + texturePath = charTexturePath; + + const char* charScriptPath = config->FirstChildElement("scriptPath")->GetText(); + if(charScriptPath == NULL){ + printf("XMLError: No scriptPath found.\n"); + exit(-1); + } + scriptPath = charScriptPath; + + const char* charHeightmapPath = config->FirstChildElement("heightmapPath")->GetText(); + if(charHeightmapPath == NULL){ + printf("XMLError: No heightmapPath found.\n"); + exit(-1); + } + heightmapPath = charHeightmapPath; + + const char* charLevelXmlPath = config->FirstChildElement("levelXmlPath")->GetText(); + if(charLevelXmlPath == NULL){ + printf("XMLError: No levelXmlPath found.\n"); + exit(-1); + } + levelXmlPath = charLevelXmlPath; +} + +void Application::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"); + } + exit(-1); + } +} diff --git a/application.hh b/application.hh index 4de5007..8da9529 100644 --- a/application.hh +++ b/application.hh @@ -4,6 +4,7 @@ #include "physics.hh" #include "graphics.hh" #include "level.hh" +#include "tinyxml2.hh" class Application { public: @@ -19,11 +20,23 @@ class Application { int getIgnoredMouseUpdates(); void ignoredOneMouseUpdate(); private: + void loadConfig(); + void errorCheck(tinyxml2::XMLError error); int ignoredMouseUpdates; bool focused; bool cameraLock; Graphics graphics; Level level; + int windowWidth; + int windowHeight; + float farPlane; + std::string compositionsPath; + std::string shaderPath; + std::string geometryPath; + std::string texturePath; + std::string scriptPath; + std::string heightmapPath; + std::string levelXmlPath; }; #endif