Added checks and error messages in case files do not exist.
This commit is contained in:
parent
dd0afd1978
commit
b28f4d3bef
@ -33,7 +33,7 @@ void Application::init()
|
||||
level.load();
|
||||
Loader loader = Loader();
|
||||
|
||||
loader.load(levelXmlFilePath, &level, compositionsPath, scriptPath);
|
||||
loader.load(levelXmlFilePath, &level, compositionsPath, scriptPath, geometryPath, texturePath);
|
||||
graphics.init(&level);
|
||||
|
||||
// just in case: check for errors
|
||||
|
30
loader.cc
30
loader.cc
@ -31,7 +31,7 @@ void Loader::loadConfig(Application* application) {
|
||||
application->setLevelXmlPath(queryString(config, "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, std::string globalGeometryPath, std::string globalTexturePath) {
|
||||
//Loading from xml:
|
||||
XMLDocument* doc = new XMLDocument();
|
||||
const char* xmlFile = filePath.c_str();
|
||||
@ -55,6 +55,12 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
||||
float terrainDiffuseFactor = queryFloat(terrainElement, "diffuseFactor");
|
||||
float terrainSpecularFactor = queryFloat(terrainElement, "specularFactor");
|
||||
float terrainShininess = queryFloat(terrainElement, "shininess");
|
||||
struct stat buf;
|
||||
std::string terrainTexturePath = "../" + globalTexturePath + terrainTexture;
|
||||
if(stat(terrainTexturePath.c_str(), &buf) != 0){
|
||||
std::cout << "The texture file " << terrainTexturePath << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
Material terrainMaterial = Material(terrainTexture, terrainAmbientFactor, terrainDiffuseFactor, terrainSpecularFactor, terrainShininess);
|
||||
Object* terrainObject = new Object(terrainModel, terrainMaterial,
|
||||
glm::vec3(-0.5*((float)level->getTerrain()->getHeightmapHeight()-1), 0.0f, -0.5f*((float)level->getTerrain()->getHeightmapWidth()-1)),
|
||||
@ -64,8 +70,18 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
||||
|
||||
//load the skydome
|
||||
XMLElement* skydomeElement = doc->FirstChildElement("skydome");
|
||||
std::string skydomeTexture = queryString(skydomeElement, "texture");;
|
||||
std::string skydomeTexture = queryString(skydomeElement, "texture");
|
||||
std::string skydomePath = "../" + globalGeometryPath + "skydome.obj";
|
||||
if(stat(skydomePath.c_str(), &buf) != 0){
|
||||
std::cout << "The object file " << skydomePath << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
Model skydomeModel = Model("skydome.obj", level->getSkydomeSize());
|
||||
std::string skydomeTexturePath = "../" + globalTexturePath + skydomeTexture;
|
||||
if(stat(skydomeTexturePath.c_str(), &buf) != 0){
|
||||
std::cout << "The texture file " << skydomeTexturePath << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
Material skydomeMaterial = Material(skydomeTexture, 0.7f, 0.0f, 0.0f, 0.0f);
|
||||
Object* skydomeObject = new Object(skydomeModel, skydomeMaterial, glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f), true);
|
||||
@ -139,7 +155,17 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
||||
float specularFactor = queryFloat(objectData, "specularFactor");
|
||||
float shininess = queryFloat(objectData, "shininess");
|
||||
std::string texturePath = queryString(objectData, "texturePath");
|
||||
std::string entireTexturePath = "../" + globalTexturePath + texturePath;
|
||||
if(stat(entireTexturePath.c_str(), &buf) != 0){
|
||||
std::cout << "The texture file " << entireTexturePath << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
material = Material(texturePath, ambientFactor, diffuseFactor, specularFactor, shininess);
|
||||
std::string entireModelPath = "../" + globalGeometryPath + modelPath;
|
||||
if(stat(entireModelPath.c_str(), &buf) != 0){
|
||||
std::cout << "The object file " << entireModelPath << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
model = Model(modelPath, objectScale * compScale);
|
||||
}
|
||||
float compXPos = queryFloat(thisComposition, "xPos");
|
||||
|
@ -10,7 +10,7 @@ class Loader {
|
||||
public:
|
||||
Loader();
|
||||
void loadConfig(Application* application);
|
||||
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, std::string geometryPath, std::string texturePath);
|
||||
glm::vec3 reloadPlayerPosition(std::string filePath, Level* level);
|
||||
private:
|
||||
float queryFloat(XMLElement* element, const char* attribute);
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "trigger.hh"
|
||||
#include <sys/stat.h>
|
||||
|
||||
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* luaState, int objectToChange, std::string scriptPath) {
|
||||
this->position=position;
|
||||
@ -6,6 +7,11 @@ Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* obje
|
||||
this->isBigger=isBigger;
|
||||
this->object=object;
|
||||
this->luaScript= scriptPath + luaScript;
|
||||
struct stat buf;
|
||||
if(stat(this->luaScript.c_str(), &buf) != 0){
|
||||
std::cout << "The lua file " << this->luaScript << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
this->luaState = luaState;
|
||||
if(luaState == nullptr){
|
||||
printf("The Lua state is NULL in trigger!\n");
|
||||
|
Loading…
Reference in New Issue
Block a user