diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index dfb756c..8b8d267 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,5 +1,8 @@
+
+
+
@@ -13,25 +16,22 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -44,23 +44,11 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -68,11 +56,11 @@
-
+
-
-
+
+
@@ -80,11 +68,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -92,13 +101,25 @@
-
-
+
+
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -107,8 +128,8 @@
-
-
+
+
@@ -120,8 +141,6 @@
- XMapWindow
- VOFLAG_W
_window3
_window
WinID
@@ -150,6 +169,8 @@
device
getAb
Compiled shader output for
+ getFileSystem
+ string
@@ -158,7 +179,6 @@
@@ -225,7 +246,7 @@
-
+
@@ -240,6 +261,11 @@
+
+
+
+
+
@@ -296,7 +322,7 @@
-
+
@@ -318,12 +344,12 @@
-
+
-
+
@@ -379,68 +405,20 @@
- file://$PROJECT_DIR$/wallpaperengine/shaders/compiler.cpp
- 357
-
+ file://$PROJECT_DIR$/nier_test.cpp
+ 136
+
- file://$PROJECT_DIR$/nier_test.cpp
- 147
-
-
-
- file://$PROJECT_DIR$/nier_test.cpp
- 163
-
-
-
- file://$PROJECT_DIR$/nier_test.cpp
- 169
-
-
-
- file://$PROJECT_DIR$/nier_test.cpp
- 175
-
-
-
- file://$PROJECT_DIR$/nier_test.cpp
- 179
-
-
-
- file://$PROJECT_DIR$/nier_test.cpp
- 186
-
+ file://$PROJECT_DIR$/wallpaperengine/project.cpp
+ 15
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -570,93 +548,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -688,16 +579,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -760,23 +641,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -787,20 +651,182 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -809,23 +835,13 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/main.cpp b/main.cpp
index 54f72eb..9d817c6 100644
--- a/main.cpp
+++ b/main.cpp
@@ -2,6 +2,7 @@
#include
#include
#include
+#include
#include "nier_test.h"
#include "wallpaperengine/irrlicht.h"
@@ -64,6 +65,8 @@ void preconfigure_wallpaper_engine ()
wp::config::path::base = wp::irrlicht::device->getFileSystem ()->getAbsolutePath ("../");
wp::config::path::resources = wp::config::path::base + "/res";
wp::config::path::shaders = wp::config::path::resources + "/shaders";
+
+ wp::fs::resolver.changeWorkingDirectory(wp::config::path::base);
}
int game_test_main ()
diff --git a/nier_test.cpp b/nier_test.cpp
index f69bafa..9eeba20 100644
--- a/nier_test.cpp
+++ b/nier_test.cpp
@@ -1,6 +1,7 @@
#include
#include
#include
+#include
#include "common.h"
#include "wallpaperengine/shaders/compiler.h"
@@ -133,11 +134,8 @@ int nier_test ()
// set our working directory
wp::fs::resolver.changeWorkingDirectory (_wp_engine_folder);
- // also append base folder for resources
- wp::fs::resolver.appendEnvironment ("");
-
wp::project* wp_project = new wp::project (_wp_engine_folder);
- wp::fs::resolver.changeWorkingDirectory ("../res");
+ wp::fs::resolver.changeWorkingDirectory (wp::config::path::resources);
irr::io::path _water_example = wp::fs::resolver.resolve ("materials/water-intact.png");
irr::io::path _mud_example = wp::fs::resolver.resolve ("materials/plant-on-water.png");
diff --git a/wallpaperengine/config.cpp b/wallpaperengine/config.cpp
index 5a2dae3..b4cc2b0 100644
--- a/wallpaperengine/config.cpp
+++ b/wallpaperengine/config.cpp
@@ -8,8 +8,8 @@ namespace wp
{
namespace config
{
- static irr::io::path path::resources;
- static irr::io::path path::base;
- static irr::io::path path::shaders;
+ irr::io::path path::resources;
+ irr::io::path path::base;
+ irr::io::path path::shaders;
}
}
\ No newline at end of file
diff --git a/wallpaperengine/effect.cpp b/wallpaperengine/effect.cpp
index 57671aa..3e52e0c 100644
--- a/wallpaperengine/effect.cpp
+++ b/wallpaperengine/effect.cpp
@@ -1,17 +1,16 @@
+#include
#include "effect.h"
namespace wp
{
- effect::effect (json json_data, irr::io::path basepath)
+ effect::effect (json json_data)
{
json::const_iterator file = json_data.find ("file");
json::const_iterator pass = json_data.find ("passes");
if (file != json_data.end () && (*file).is_string () == true)
{
- std::string file_s = *file;
-
- this->m_file = basepath + "/" + file_s.c_str ();
+ this->m_file = wp::fs::resolver.resolve (*file);
}
}
};
\ No newline at end of file
diff --git a/wallpaperengine/effect.h b/wallpaperengine/effect.h
index e97d958..b5ba63c 100644
--- a/wallpaperengine/effect.h
+++ b/wallpaperengine/effect.h
@@ -11,7 +11,7 @@ namespace wp
class effect
{
public:
- effect (json json_data, irr::io::path basepath);
+ effect (json json_data);
private:
irr::io::path m_file;
diff --git a/wallpaperengine/fs/fileResolver.cpp b/wallpaperengine/fs/fileResolver.cpp
index f944dae..644fc8d 100644
--- a/wallpaperengine/fs/fileResolver.cpp
+++ b/wallpaperengine/fs/fileResolver.cpp
@@ -4,83 +4,120 @@
namespace wp
{
- namespace fs
+ fs::fileResolver::fileResolver ()
{
- fileResolver::fileResolver ()
- {
- this->m_environment.push_back (".");
- }
+ this->m_environment.push_back (".");
+ }
- fileResolver::fileResolver (std::vector environment)
- {
- this->m_environment.push_back (".");
- this->m_environment.insert (this->m_environment.end (), environment.begin (), environment.end ());
- }
- void fileResolver::appendEnvironment (irr::io::path path)
- {
- this->m_environment.push_back (wp::irrlicht::device->getFileSystem ()->getAbsolutePath (path));
- }
+ fs::fileResolver::fileResolver (std::vector environment)
+ {
+ this->m_environment.push_back (".");
+ this->m_environment.insert (this->m_environment.end (), environment.begin (), environment.end ());
+ }
+ void fs::fileResolver::appendEnvironment (irr::io::path path)
+ {
+ this->m_environment.push_back (wp::irrlicht::device->getFileSystem ()->getAbsolutePath (path));
+ }
- void fileResolver::removeEnvironment(irr::io::path path)
- {
- std::vector::const_iterator cur = this->m_environment.begin ();
- std::vector::const_iterator end = this->m_environment.end ();
- irr::io::path absolute = wp::irrlicht::device->getFileSystem ()->getAbsolutePath (path);
+ void fs::fileResolver::removeEnvironment(irr::io::path path)
+ {
+ std::vector::const_iterator cur = this->m_environment.begin ();
+ std::vector::const_iterator end = this->m_environment.end ();
+ irr::io::path absolute = wp::irrlicht::device->getFileSystem ()->getAbsolutePath (path);
- for (; cur != end; cur ++)
+ for (; cur != end; cur ++)
+ {
+ if (*cur == path)
{
- if (*cur == path)
- {
- this->m_environment.erase (cur);
- return;
- }
+ this->m_environment.erase (cur);
+ return;
}
}
-
- void fileResolver::prependEnvironment (irr::io::path path)
- {
- this->m_environment.insert (
- this->m_environment.begin (),
- wp::irrlicht::device->getFileSystem ()->getAbsolutePath (path)
- );
- }
-
- void fileResolver::changeWorkingDirectory (irr::io::path newpath)
- {
- this->m_environment.erase (this->m_environment.begin ());
- this->prependEnvironment (newpath);
- }
-
- fileResolver fileResolver::clone ()
- {
- return fileResolver (this->m_environment);
- }
-
- irr::io::path fileResolver::resolve (irr::io::path name)
- {
- std::vector::const_iterator cur = this->m_environment.begin ();
- std::vector::const_iterator end = this->m_environment.end ();
- irr::io::path tmp = "";
-
- // try to resolve the path
- for (; cur != end; cur ++)
- {
- tmp = *cur;
- tmp += "/";
- tmp += name;
-
- struct stat buffer;
-
- if (stat (tmp.c_str (), &buffer) == 0)
- {
- wp::irrlicht::device->getLogger ()->log ("Resolved file to", tmp.c_str ());
- return tmp;
- }
- }
-
- wp::irrlicht::device->getLogger ()->log ("Failed resolving file ", name.c_str ());
-
- return "";
- }
}
+
+ void fs::fileResolver::prependEnvironment (irr::io::path path)
+ {
+ this->m_environment.insert (
+ this->m_environment.begin (),
+ wp::irrlicht::device->getFileSystem ()->getAbsolutePath (path)
+ );
+ }
+
+ void fs::fileResolver::changeWorkingDirectory (irr::io::path newpath)
+ {
+ this->m_environment.erase (this->m_environment.begin ());
+ this->prependEnvironment (newpath);
+ }
+
+ irr::io::path fs::fileResolver::getWorkingDirectory ()
+ {
+ return *this->m_environment.begin ();
+ }
+
+ fs::fileResolver fs::fileResolver::clone ()
+ {
+ return fileResolver (this->m_environment);
+ }
+
+ irr::io::path fs::fileResolver::resolve (irr::io::path name)
+ {
+ std::vector::const_iterator cur = this->m_environment.begin ();
+ std::vector::const_iterator end = this->m_environment.end ();
+ irr::io::path tmp = "";
+
+ // try to resolve the path
+ for (; cur != end; cur ++)
+ {
+ tmp = *cur;
+ tmp += "/";
+ tmp += name;
+
+ if (wp::irrlicht::device->getFileSystem ()->existFile (tmp) == true)
+ {
+ wp::irrlicht::device->getLogger ()->log ("Resolved file to", tmp.c_str ());
+ return tmp;
+ }
+ }
+
+ wp::irrlicht::device->getLogger ()->log ("Failed resolving file ", name.c_str (), irr::ELL_ERROR);
+
+ return "";
+ }
+
+ irr::io::path fs::fileResolver::resolveOnWorkingDirectory (irr::io::path name)
+ {
+ irr::io::path file = *this->m_environment.begin () + "/" + name;
+
+ if (wp::irrlicht::device->getFileSystem ()->existFile (file) == true)
+ {
+ wp::irrlicht::device->getLogger ()->log ("Resolved file in working directory to", file.c_str ());
+ return file;
+ }
+
+ return "";
+ }
+
+ irr::io::path fs::fileResolver::resolve (json name)
+ {
+ std::string tmp = name;
+ return this->resolve (tmp.c_str ());
+ }
+
+ irr::io::path fs::fileResolver::resolveOnWorkingDirectory (json name)
+ {
+ std::string tmp = name;
+ return this->resolveOnWorkingDirectory (tmp.c_str ());
+ }
+
+ irr::io::path fs::fileResolver::resolve (const char* name)
+ {
+ return this->resolve (irr::io::path(name));
+ }
+
+ irr::io::path fs::fileResolver::resolveOnWorkingDirectory (const char* name)
+ {
+ return this->resolveOnWorkingDirectory(irr::io::path (name));
+ }
+
+ fs::fileResolver fs::resolver;
}
\ No newline at end of file
diff --git a/wallpaperengine/fs/fileResolver.h b/wallpaperengine/fs/fileResolver.h
index c551ad6..3df3649 100644
--- a/wallpaperengine/fs/fileResolver.h
+++ b/wallpaperengine/fs/fileResolver.h
@@ -4,11 +4,14 @@
#include
#include
#include
+#include
namespace wp
{
- namespace fs
+ using json = nlohmann::json;
+ class fs
{
+ public:
class fileResolver
{
public:
@@ -18,8 +21,14 @@ namespace wp
void appendEnvironment (irr::io::path path);
void removeEnvironment (irr::io::path path);
void changeWorkingDirectory (irr::io::path newpath);
+ irr::io::path getWorkingDirectory ();
fileResolver clone ();
irr::io::path resolve (irr::io::path name);
+ irr::io::path resolveOnWorkingDirectory (irr::io::path name);
+ irr::io::path resolve (json name);
+ irr::io::path resolveOnWorkingDirectory (json name);
+ irr::io::path resolve (const char* name);
+ irr::io::path resolveOnWorkingDirectory (const char* name);
protected:
void prependEnvironment (irr::io::path path);
@@ -29,7 +38,7 @@ namespace wp
};
static fileResolver resolver;
- }
+ };
}
diff --git a/wallpaperengine/image.cpp b/wallpaperengine/image.cpp
index 942afdf..d637eac 100644
--- a/wallpaperengine/image.cpp
+++ b/wallpaperengine/image.cpp
@@ -1,10 +1,11 @@
#include
+#include
#include "object3d.h"
#include "image.h"
namespace wp
{
- image::image (json json_data, irr::io::path basepath) : object3d (object3d::Type::Type_Image)
+ image::image (json json_data) : object3d (object3d::Type::Type_Image)
{
json::const_iterator visible = json_data.find ("visible");
json::const_iterator file = json_data.find ("image");
@@ -16,9 +17,7 @@ namespace wp
if (file != json_data.end () && (*file).is_string () == true)
{
- std::string file_s = *file;
-
- this->m_file = basepath + "/" + file_s.c_str ();
+ this->m_file = wp::fs::resolver.resolve (*file);
}
}
}
\ No newline at end of file
diff --git a/wallpaperengine/image.h b/wallpaperengine/image.h
index cc38ef6..a6c552c 100644
--- a/wallpaperengine/image.h
+++ b/wallpaperengine/image.h
@@ -11,7 +11,7 @@ namespace wp
class image : public object3d
{
public:
- image(json json_data, irr::io::path basepath);
+ image(json json_data);
private:
bool m_visible;
diff --git a/wallpaperengine/object.cpp b/wallpaperengine/object.cpp
index 1fcf6cd..2223f6e 100644
--- a/wallpaperengine/object.cpp
+++ b/wallpaperengine/object.cpp
@@ -12,7 +12,7 @@ namespace wp
{
using json = nlohmann::json;
- object::object (json json_data, irr::io::path basepath)
+ object::object (json json_data)
{
json::const_iterator size = json_data.find ("size");
json::const_iterator scale = json_data.find ("scale");
@@ -84,7 +84,7 @@ namespace wp
switch (_type)
{
case object3d::Type::Type_Image:
- this->m_object3d = new wp::image (json_data, basepath);
+ this->m_object3d = new wp::image (json_data);
break;
case object3d::Type::Type_Model:
@@ -103,7 +103,7 @@ namespace wp
for (; cur != end; cur ++)
{
- this->m_effects.push_back (new effect (*cur, basepath));
+ this->m_effects.push_back (new effect (*cur));
}
}
}
diff --git a/wallpaperengine/object.h b/wallpaperengine/object.h
index fc68c4e..7cdf5ca 100644
--- a/wallpaperengine/object.h
+++ b/wallpaperengine/object.h
@@ -15,7 +15,7 @@ namespace wp
{
public:
- object (json json_data, irr::io::path basepath);
+ object (json json_data);
~object ();
private:
diff --git a/wallpaperengine/project.cpp b/wallpaperengine/project.cpp
index 5eed103..6bfb1cc 100644
--- a/wallpaperengine/project.cpp
+++ b/wallpaperengine/project.cpp
@@ -2,13 +2,16 @@
#include
#include
+#include "fs/fileResolver.h"
+
#include "project.h"
+#include "irrlicht.h"
namespace wp
{
project::project (irr::io::path baseDirectory)
{
- irr::io::path projectFile = baseDirectory + "/project.json";
+ irr::io::path projectFile = wp::fs::resolver.resolveOnWorkingDirectory ("project.json");
std::ifstream _in (projectFile.c_str ());
this->m_content = "";
@@ -22,11 +25,8 @@ namespace wp
if (file_it != this->m_projectFile.end ())
{
// load scene file
- this->m_file = file_it.value ();
- this->m_file = baseDirectory.c_str ();
- this->m_file += "/";
- this->m_file += this->m_projectFile ["file"];
- this->m_scene = new scene (this->m_file.c_str (), baseDirectory);
+ this->m_file = wp::fs::resolver.resolveOnWorkingDirectory (*file_it);
+ this->m_scene = new scene (this->m_file.c_str ());
}
if (type_it != this->m_projectFile.end ())
diff --git a/wallpaperengine/project.h b/wallpaperengine/project.h
index e86f617..e5d1d6d 100644
--- a/wallpaperengine/project.h
+++ b/wallpaperengine/project.h
@@ -20,7 +20,7 @@ namespace wp
std::string m_title;
std::string m_type;
- std::string m_file;
+ irr::io::path m_file;
scene* m_scene;
};
};
diff --git a/wallpaperengine/scene.cpp b/wallpaperengine/scene.cpp
index f658d1c..d676d79 100644
--- a/wallpaperengine/scene.cpp
+++ b/wallpaperengine/scene.cpp
@@ -9,7 +9,7 @@ namespace wp
{
using json = nlohmann::json;
- scene::scene (irr::io::path file, irr::io::path basepath)
+ scene::scene (irr::io::path file)
{
std::ifstream _in (file.c_str ());
this->m_content = "";
@@ -33,7 +33,7 @@ namespace wp
for (; cur != end; cur ++)
{
- this->m_objects.push_back (new object (*cur, basepath));
+ this->m_objects.push_back (new object (*cur));
}
}
}
diff --git a/wallpaperengine/scene.h b/wallpaperengine/scene.h
index a6b79e8..dea5e29 100644
--- a/wallpaperengine/scene.h
+++ b/wallpaperengine/scene.h
@@ -14,7 +14,7 @@ namespace wp
class scene
{
public:
- scene (irr::io::path file, irr::io::path basepath);
+ scene (irr::io::path file);
~scene ();
private: