Implemented loading of config.xml, the loaded values are not used yet.
This commit is contained in:
parent
ea58f2fbce
commit
a14d3420d5
@ -1,8 +1,10 @@
|
|||||||
#include "application.hh"
|
#include "application.hh"
|
||||||
#include "loader.hh"
|
#include "loader.hh"
|
||||||
|
using namespace tinyxml2;
|
||||||
|
|
||||||
Application::Application() {
|
Application::Application() {
|
||||||
|
//load the config.xml
|
||||||
|
loadConfig();
|
||||||
graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 150.0f);
|
graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 150.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,3 +76,87 @@ int Application::getIgnoredMouseUpdates() {
|
|||||||
bool Application::isLocked() {
|
bool Application::isLocked() {
|
||||||
return cameraLock;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "physics.hh"
|
#include "physics.hh"
|
||||||
#include "graphics.hh"
|
#include "graphics.hh"
|
||||||
#include "level.hh"
|
#include "level.hh"
|
||||||
|
#include "tinyxml2.hh"
|
||||||
|
|
||||||
class Application {
|
class Application {
|
||||||
public:
|
public:
|
||||||
@ -19,11 +20,23 @@ class Application {
|
|||||||
int getIgnoredMouseUpdates();
|
int getIgnoredMouseUpdates();
|
||||||
void ignoredOneMouseUpdate();
|
void ignoredOneMouseUpdate();
|
||||||
private:
|
private:
|
||||||
|
void loadConfig();
|
||||||
|
void errorCheck(tinyxml2::XMLError error);
|
||||||
int ignoredMouseUpdates;
|
int ignoredMouseUpdates;
|
||||||
bool focused;
|
bool focused;
|
||||||
bool cameraLock;
|
bool cameraLock;
|
||||||
Graphics graphics;
|
Graphics graphics;
|
||||||
Level level;
|
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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user