From dd0afd1978b98167a7705c8247a3dae4b73f8f18 Mon Sep 17 00:00:00 2001 From: Steffen Date: Tue, 3 Mar 2015 17:37:03 +0100 Subject: [PATCH 1/2] Changed array initialization because it did not compile under windows. --- graphics.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics.cc b/graphics.cc index e526e4e..b53ea3b 100644 --- a/graphics.cc +++ b/graphics.cc @@ -315,7 +315,7 @@ void Graphics::updateLights() { lightingShader->setUniform("directionalIntensity", level->getDirectionalLight()->getIntensity()); } - float flameData[closestLights.size() * 6] = {}; + float* flameData = new float[closestLights.size() * 6]; int flameIndex = 0; for (unsigned int i = 0; i Date: Tue, 3 Mar 2015 18:45:02 +0100 Subject: [PATCH 2/2] Added checks and error messages in case files do not exist. --- application.cc | 2 +- loader.cc | 30 ++++++++++++++++++++++++++++-- loader.hh | 2 +- trigger.cc | 6 ++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/application.cc b/application.cc index 42175c0..0dafbd3 100644 --- a/application.cc +++ b/application.cc @@ -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 diff --git a/loader.cc b/loader.cc index 806f733..3c1e386 100644 --- a/loader.cc +++ b/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"); diff --git a/loader.hh b/loader.hh index b032d95..8e97c89 100644 --- a/loader.hh +++ b/loader.hh @@ -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); diff --git a/trigger.cc b/trigger.cc index 1ad30cb..dbea382 100644 --- a/trigger.cc +++ b/trigger.cc @@ -1,4 +1,5 @@ #include "trigger.hh" +#include 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");