Setting the current working directory to the actual module directory for each module

This commit is contained in:
Alexander Bock
2015-03-03 14:28:30 +01:00
parent 7da514b7cd
commit 07a26fa1e9
2 changed files with 21 additions and 11 deletions

View File

@@ -66,16 +66,16 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
ghoul_assert(success,
"RenderablePlanet need the '" <<constants::scenegraphnode::keyName<<"' be specified");
std::string path;
success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
ghoul_assert(success,
"RenderablePlanet need the '"<<constants::scenegraph::keyPathModule<<"' be specified");
//std::string path;
//success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
//ghoul_assert(success,
// "RenderablePlanet need the '"<<constants::scenegraph::keyPathModule<<"' be specified");
ghoul::Dictionary geometryDictionary;
success = dictionary.getValue(keyGeometry, geometryDictionary);
if (success) {
geometryDictionary.setValue(constants::scenegraphnode::keyName, name);
geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
//geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
_geometry = planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary);
}
@@ -88,8 +88,9 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
// as the requirements are fixed (ab)
std::string texturePath = "";
success = dictionary.getValue("Textures.Color", texturePath);
if (success)
_colorTexturePath = path + "/" + texturePath;
_colorTexturePath = absPath(texturePath);
//if (success)
//_colorTexturePath = path + "/" + texturePath;
addPropertySubOwner(_geometry);
@@ -195,14 +196,13 @@ void RenderablePlanet::update(const UpdateData& data){
_time = data.time;
}
void RenderablePlanet::loadTexture()
{
void RenderablePlanet::loadTexture() {
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
_texture = ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath);
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
LDEBUG("Loaded texture from '" << _colorTexturePath << "'");
_texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear

View File

@@ -567,6 +567,9 @@ void SceneGraph::loadModule(LoadMaps& m,const std::string& modulePath, lua_State
std::string fullModule = modulePath + modulePath.substr(pos) + _moduleExtension;
LDEBUG("Loading nodes from: " << fullModule);
ghoul::filesystem::Directory oldDirectory = FileSys.currentDirectory();
FileSys.setCurrentDirectory(modulePath);
ghoul::Dictionary moduleDictionary;
ghoul::lua::loadDictionaryFromFile(fullModule, moduleDictionary, state);
std::vector<std::string> keys = moduleDictionary.keys();
@@ -590,6 +593,8 @@ void SceneGraph::loadModule(LoadMaps& m,const std::string& modulePath, lua_State
m.nodes[nodeName] = element;
m.dependencies.emplace(parentName,nodeName);
}
FileSys.setCurrentDirectory(oldDirectory);
}
void SceneGraph::loadNodes(const std::string& parentName, LoadMaps& m) {
@@ -621,6 +626,9 @@ void SceneGraph::loadModule(const std::string& modulePath)
std::string fullModule = modulePath + modulePath.substr(pos) + _moduleExtension;
LDEBUG("Loading modules from: " << fullModule);
ghoul::filesystem::Directory oldDirectory = FileSys.currentDirectory();
FileSys.setCurrentDirectory(modulePath);
ghoul::Dictionary moduleDictionary;
ghoul::lua::loadDictionaryFromFile(fullModule, moduleDictionary);
std::vector<std::string> keys = moduleDictionary.keys();
@@ -643,6 +651,8 @@ void SceneGraph::loadModule(const std::string& modulePath)
_nodes.push_back(node);
}
FileSys.setCurrentDirectory(oldDirectory);
// Print the tree
//printTree(_root);
}