Added xml query functions to the loader class, using them in loadConfig().
This commit is contained in:
parent
5608790231
commit
2d5fdc488f
172
loader.cc
172
loader.cc
@ -16,73 +16,19 @@ void Loader::loadConfig(Application* application) {
|
||||
exit(-1);
|
||||
}
|
||||
XMLElement* resolution = config->FirstChildElement("resolution");
|
||||
errorCheck(resolution->FirstChildElement("width")->QueryIntText(&windowWidth));
|
||||
errorCheck(resolution->FirstChildElement("height")->QueryIntText(&windowHeight));
|
||||
errorCheck(config->FirstChildElement("shadowCubeSize")->QueryIntText(&shadowCubeSize));
|
||||
errorCheck(config->FirstChildElement("farPlane")->QueryFloatText(&farPlane));
|
||||
errorCheck(config->FirstChildElement("maxShadowRenderCount")->QueryIntText(&maxShadowRenderCount));
|
||||
|
||||
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->setShadowCubeSize(shadowCubeSize);
|
||||
application->setFarPlane(farPlane);
|
||||
application->setMaxShadowRenderCount(maxShadowRenderCount);
|
||||
application->setCompositionsPath(compositionsPath);
|
||||
application->setShaderPath(shaderPath);
|
||||
application->setGeometryPath(geometryPath);
|
||||
application->setTexturePath(texturePath);
|
||||
application->setScriptPath(scriptPath);
|
||||
application->setHeightmapPath(heightmapPath);
|
||||
application->setLevelXmlPath(levelXmlPath);
|
||||
application->setWindowWidth(queryInt(resolution, "width"));
|
||||
application->setWindowHeight(queryInt(resolution, "height"));
|
||||
application->setShadowCubeSize(queryInt(config, "shadowCubeSize"));
|
||||
application->setFarPlane(queryFloat(config, "farPlane"));
|
||||
application->setMaxShadowRenderCount(queryInt(config, "maxShadowRenderCount"));
|
||||
application->setCompositionsPath(queryString(config, "compositionsPath"));
|
||||
application->setShaderPath(queryString(config, "shaderPath"));
|
||||
application->setGeometryPath(queryString(config, "geometryPath"));
|
||||
application->setTexturePath(queryString(config, "texturePath"));
|
||||
application->setScriptPath(queryString(config, "scriptPath"));
|
||||
application->setHeightmapPath(queryString(config, "heightmapPath"));
|
||||
application->setLevelXmlPath(queryString(config, "levelXmlPath"));
|
||||
}
|
||||
|
||||
void Loader::load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath) {
|
||||
@ -551,7 +497,101 @@ glm::vec3 Loader::reloadPlayerPosition(std::string filePath, Level* level){
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
float Loader::queryFloat(XMLElement* element, const char* attribute){
|
||||
XMLElement* attributeElement = element->FirstChildElement(attribute);
|
||||
if (attributeElement == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
float ret;
|
||||
errorCheck(attributeElement->QueryFloatText(&ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
float Loader::queryFloat(XMLDocument*& element, const char* attribute){
|
||||
XMLElement* attributeElement = element->FirstChildElement(attribute);
|
||||
if (attributeElement == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
float ret;
|
||||
errorCheck(attributeElement->QueryFloatText(&ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Loader::queryInt(XMLElement* element, const char* attribute){
|
||||
XMLElement* attributeElement = element->FirstChildElement(attribute);
|
||||
if (attributeElement == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
int ret;
|
||||
errorCheck(attributeElement->QueryIntText(&ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Loader::queryInt(XMLDocument*& element, const char* attribute){
|
||||
XMLElement* attributeElement = element->FirstChildElement(attribute);
|
||||
if (attributeElement == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
int ret;
|
||||
errorCheck(attributeElement->QueryIntText(&ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Loader::queryBool(XMLElement* element, const char* attribute){
|
||||
XMLElement* attributeElement = element->FirstChildElement(attribute);
|
||||
if (attributeElement == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
bool ret;
|
||||
errorCheck(attributeElement->QueryBoolText(&ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Loader::queryBool(XMLDocument*& element, const char* attribute){
|
||||
XMLElement* attributeElement = element->FirstChildElement(attribute);
|
||||
if (attributeElement == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
bool ret;
|
||||
errorCheck(attributeElement->QueryBoolText(&ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string Loader::queryString(XMLElement* element, const char* attribute){
|
||||
XMLElement* attributeElement = element->FirstChildElement(attribute);
|
||||
if (attributeElement == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
const char* charRet = attributeElement->GetText();
|
||||
if(charRet == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " could not be loaded." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
std::string ret = charRet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string Loader::queryString(XMLDocument*& element, const char* attribute){
|
||||
XMLElement* attributeElement = element->FirstChildElement(attribute);
|
||||
if (attributeElement == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
const char* charRet = attributeElement->GetText();
|
||||
if(charRet == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " could not be loaded." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
std::string ret = charRet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Loader::errorCheck(XMLError error){
|
||||
if (error) {
|
||||
|
10
loader.hh
10
loader.hh
@ -4,6 +4,8 @@
|
||||
#include "level.hh"
|
||||
#include "tinyxml2.hh"
|
||||
|
||||
using namespace tinyxml2;
|
||||
|
||||
class Loader {
|
||||
public:
|
||||
Loader();
|
||||
@ -11,5 +13,13 @@ class Loader {
|
||||
void load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath);
|
||||
glm::vec3 reloadPlayerPosition(std::string filePath, Level* level);
|
||||
private:
|
||||
float queryFloat(XMLElement* element, const char* attribute);
|
||||
float queryFloat(XMLDocument*& element, const char* attribute);
|
||||
int queryInt(XMLElement* element, const char* attribute);
|
||||
int queryInt(XMLDocument*& element, const char* attribute);
|
||||
bool queryBool(XMLElement* element, const char* attribute);
|
||||
bool queryBool(XMLDocument*& element, const char* attribute);
|
||||
std::string queryString(XMLElement* element, const char* attribute);
|
||||
std::string queryString(XMLDocument*& element, const char* attribute);
|
||||
void errorCheck(tinyxml2::XMLError error);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user