Moved loading of the config.xml to the loader class.
This commit is contained in:
parent
096cf12df0
commit
2b4a8885b5
120
application.cc
120
application.cc
@ -1,10 +1,10 @@
|
|||||||
#include "application.hh"
|
#include "application.hh"
|
||||||
#include "loader.hh"
|
#include "loader.hh"
|
||||||
using namespace tinyxml2;
|
|
||||||
|
|
||||||
Application::Application() {
|
Application::Application() {
|
||||||
|
Loader loader = Loader();
|
||||||
//load the config.xml
|
//load the config.xml
|
||||||
loadConfig();
|
loader.loadConfig(this);
|
||||||
graphics = Graphics(glm::uvec2(windowWidth, windowHeight), 0.1f, farPlane);
|
graphics = Graphics(glm::uvec2(windowWidth, windowHeight), 0.1f, farPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,86 +79,42 @@ bool Application::isLocked() {
|
|||||||
return cameraLock;
|
return cameraLock;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::loadConfig() {
|
void Application::setWindowWidth(int windowWidth) {
|
||||||
XMLDocument* config = new XMLDocument();
|
this->windowWidth = windowWidth;
|
||||||
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){
|
void Application::setWindowHeight(int windowHeight) {
|
||||||
if (error) {
|
this->windowHeight = windowHeight;
|
||||||
printf("XMLError: ");
|
}
|
||||||
if (error == XML_WRONG_ATTRIBUTE_TYPE) {
|
|
||||||
printf("Wrong attribute type.\n");
|
void Application::setFarPlane(float farPlane) {
|
||||||
}
|
this->farPlane = farPlane;
|
||||||
else if (error == XML_NO_ATTRIBUTE) {
|
}
|
||||||
printf("No attribute.\n");
|
|
||||||
}
|
void Application::setCompositionsPath(std::string compositionsPath) {
|
||||||
else if (error == XML_CAN_NOT_CONVERT_TEXT) {
|
this->compositionsPath = compositionsPath;
|
||||||
printf("Can not convert text.\n");
|
}
|
||||||
}
|
|
||||||
else if (error == XML_NO_TEXT_NODE) {
|
void Application::setShaderPath(std::string shaderPath) {
|
||||||
printf("No text.\n");
|
this->shaderPath = shaderPath;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
printf("Unknown error.\n");
|
void Application::setGeometryPath(std::string geometryPath) {
|
||||||
}
|
this->geometryPath = geometryPath;
|
||||||
exit(-1);
|
}
|
||||||
}
|
|
||||||
|
void Application::setTexturePath(std::string texturePath) {
|
||||||
|
this->texturePath = texturePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::setScriptPath(std::string scriptPath) {
|
||||||
|
this->scriptPath = scriptPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::setHeightmapPath(std::string heightmapPath) {
|
||||||
|
this->heightmapPath = heightmapPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::setLevelXmlPath(std::string levelXmlPath) {
|
||||||
|
this->levelXmlPath = levelXmlPath;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#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,9 +18,17 @@ class Application {
|
|||||||
void ignoreNextMouseUpdate();
|
void ignoreNextMouseUpdate();
|
||||||
int getIgnoredMouseUpdates();
|
int getIgnoredMouseUpdates();
|
||||||
void ignoredOneMouseUpdate();
|
void ignoredOneMouseUpdate();
|
||||||
|
void setWindowWidth(int windowWidth);
|
||||||
|
void setWindowHeight(int windowHeight);
|
||||||
|
void setFarPlane(float farPlane);
|
||||||
|
void setCompositionsPath(std::string compositionsPath);
|
||||||
|
void setShaderPath(std::string shaderPath);
|
||||||
|
void setGeometryPath(std::string geometryPath);
|
||||||
|
void setTexturePath(std::string texturePath);
|
||||||
|
void setScriptPath(std::string scriptPath);
|
||||||
|
void setHeightmapPath(std::string heightmapPath);
|
||||||
|
void setLevelXmlPath(std::string levelXmlPath);
|
||||||
private:
|
private:
|
||||||
void loadConfig();
|
|
||||||
void errorCheck(tinyxml2::XMLError error);
|
|
||||||
int ignoredMouseUpdates;
|
int ignoredMouseUpdates;
|
||||||
bool focused;
|
bool focused;
|
||||||
bool cameraLock;
|
bool cameraLock;
|
||||||
|
76
loader.cc
76
loader.cc
@ -4,6 +4,82 @@ using namespace tinyxml2;
|
|||||||
Loader::Loader() {
|
Loader::Loader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Loader::loadConfig(Application* application) {
|
||||||
|
int windowWidth, windowHeight;
|
||||||
|
float farPlane;
|
||||||
|
std::string compositionsPath, shaderPath, geometryPath, texturePath, scriptPath, heightmapPath, levelXmlPath;
|
||||||
|
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;
|
||||||
|
|
||||||
|
application->setWindowWidth(windowWidth);
|
||||||
|
application->setWindowHeight(windowHeight);
|
||||||
|
application->setFarPlane(farPlane);
|
||||||
|
application->setCompositionsPath(compositionsPath);
|
||||||
|
application->setShaderPath(shaderPath);
|
||||||
|
application->setGeometryPath(geometryPath);
|
||||||
|
application->setTexturePath(texturePath);
|
||||||
|
application->setScriptPath(scriptPath);
|
||||||
|
application->setHeightmapPath(heightmapPath);
|
||||||
|
application->setLevelXmlPath(levelXmlPath);
|
||||||
|
}
|
||||||
|
|
||||||
void Loader::load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath) {
|
void Loader::load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath) {
|
||||||
//Loading from xml:
|
//Loading from xml:
|
||||||
XMLDocument* doc = new XMLDocument();
|
XMLDocument* doc = new XMLDocument();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "application.hh"
|
||||||
#include "level.hh"
|
#include "level.hh"
|
||||||
#include "tinyxml2.hh"
|
#include "tinyxml2.hh"
|
||||||
|
|
||||||
@ -7,6 +8,7 @@ class Loader {
|
|||||||
public:
|
public:
|
||||||
Loader();
|
Loader();
|
||||||
void load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath);
|
void load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath);
|
||||||
|
void loadConfig(Application* application);
|
||||||
private:
|
private:
|
||||||
void errorCheck(tinyxml2::XMLError error);
|
void errorCheck(tinyxml2::XMLError error);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user