diff --git a/build/vs2010/Lol.Core.Rules.props b/build/vs2010/Lol.Core.Rules.props
index 48ce91ec..395ebff3 100644
--- a/build/vs2010/Lol.Core.Rules.props
+++ b/build/vs2010/Lol.Core.Rules.props
@@ -13,6 +13,8 @@
$(GlIncludes);$(SdlIncludes);$(D3d9Includes);$(XinputIncludes);%(AdditionalIncludeDirectories)
$(GlIncludes);$(SdlIncludes);$(D3d9Includes);$(XinputIncludes);%(AdditionalIncludeDirectories)
NOMINMAX;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
+ LOL_CONFIG_PROJECTDIR="$(ProjectDir.Replace('\',"\\"))";%(PreprocessorDefinitions)
+ LOL_CONFIG_SOLUTIONDIR="$(SolutionDir.Replace('\',"\\"))";%(PreprocessorDefinitions)
WIN32;$(Win32Defines);%(PreprocessorDefinitions)
WIN32;$(Win32Defines);%(PreprocessorDefinitions)
_XBOX;$(XboxDefines);%(PreprocessorDefinitions)
diff --git a/src/image/codec/gdiplus-image.cpp b/src/image/codec/gdiplus-image.cpp
index a47f792e..30e7aa2d 100644
--- a/src/image/codec/gdiplus-image.cpp
+++ b/src/image/codec/gdiplus-image.cpp
@@ -85,7 +85,8 @@ bool GdiPlusImageData::Open(char const *path)
{
#if !LOL_RELEASE
if (status != Gdiplus::InvalidParameter)
- Log::Error("error %d loading %s\n", status, path);
+ Log::Error("error %d loading %s\n",
+ status, &fullpath[0]);
#endif
delete bitmap;
bitmap = NULL;
diff --git a/src/lol/sys/init.h b/src/lol/sys/init.h
index 77846326..27ab6808 100644
--- a/src/lol/sys/init.h
+++ b/src/lol/sys/init.h
@@ -21,22 +21,28 @@
namespace lol
{
-namespace System
-{
+/*
+ * Module-specific macros. These can be overridden by the build process,
+ * typically with compiler command-line flags.
+ */
-extern void Init(Array &args);
-extern void SetDataDir(char const *dir);
-extern char const *GetDataDir();
+#if !defined LOL_CONFIG_PROJECTDIR
+# define LOL_CONFIG_PROJECTDIR ""
+#endif
-static inline void Init(int argc, char *argv[])
+#if !defined LOL_CONFIG_SOLUTIONDIR
+# define LOL_CONFIG_SOLUTIONDIR ""
+#endif
+
+namespace System
{
- Array args;
- for (int i = 0; i < argc; i++)
- args << argv[i];
+extern void Init(int argc, char *argv[],
+ char const *projectdir = LOL_CONFIG_PROJECTDIR,
+ char const *solutiondir = LOL_CONFIG_SOLUTIONDIR);
- Init(args);
-}
+extern void SetDataDir(char const *dir);
+extern char const *GetDataDir();
} /* namespace System */
diff --git a/src/sys/init.cpp b/src/sys/init.cpp
index d74a4eed..1e1cd856 100644
--- a/src/sys/init.cpp
+++ b/src/sys/init.cpp
@@ -20,25 +20,47 @@ namespace lol
namespace System
{
-void Init(Array &args)
-{
- /* Try to guess the data directory from the executable location. */
- if (args.Count() > 0)
- {
#if defined _WIN32
# define SEPARATOR '\\'
#else
# define SEPARATOR '/'
#endif
- char const *last_slash = strrchr(args[0], SEPARATOR);
- if (last_slash)
+void Init(int argc, char *argv[],
+ char const *projectdir, char const *solutiondir)
+{
+ bool got_rootdir = false;
+
+ /* Find the common prefix between project dir and solution dir. */
+ for (int i = 0; ; i++)
+ {
+ if (projectdir[i] != solutiondir[i] || projectdir[i] == '\0')
{
- String dir;
- dir.Resize(last_slash - args[0] + 1);
- memcpy(&dir[0], args[0], last_slash - args[0] + 1);
+ /* FIXME: at this point we should check whether the binary
+ * was launched from this subdirectory; from now we just
+ * assume it was. */
+ if (i)
+ {
+ String rootdir = projectdir;
+ if (rootdir.Last() != SEPARATOR)
+ rootdir += SEPARATOR;
+ SetDataDir(&rootdir[0]);
+ got_rootdir = true;
+ }
+ break;
+ }
+ }
+ /* Try to guess the data directory from the executable location. */
+ if (!got_rootdir && argc > 0)
+ {
+ char const *last_slash = strrchr(argv[0], SEPARATOR);
+
+ if (last_slash)
+ {
+ String dir(argv[0], last_slash - argv[0] + 1);
SetDataDir(&dir[0]);
+ got_rootdir = true;
}
}
}
diff --git a/test/BtPhysTest.cpp b/test/BtPhysTest.cpp
index f5f2a471..ea9aaaad 100644
--- a/test/BtPhysTest.cpp
+++ b/test/BtPhysTest.cpp
@@ -9,10 +9,6 @@
# include "config.h"
#endif
-#if defined _WIN32
-# include
-#endif
-
#if defined _XBOX
# define _USE_MATH_DEFINES /* for M_PI */
# include
@@ -479,12 +475,6 @@ int main(int argc, char **argv)
Application app("BtPhysTest", ivec2(1280, 720), 60.0f);
-#if defined _MSC_VER && !defined _XBOX
- _chdir("..");
-#elif defined _WIN32 && !defined _XBOX
- _chdir("../..");
-#endif
-
new BtPhysTest(argc > 1);
app.ShowPointer(false);
diff --git a/tutorial/01_triangle.cpp b/tutorial/01_triangle.cpp
index d2311bb3..538d790b 100644
--- a/tutorial/01_triangle.cpp
+++ b/tutorial/01_triangle.cpp
@@ -18,10 +18,6 @@
using namespace std;
using namespace lol;
-#if defined _WIN32
-# include
-#endif
-
extern char const *lolfx_01_triangle;
class Triangle : public WorldEntity
@@ -78,12 +74,6 @@ int main(int argc, char **argv)
Application app("Tutorial 1: Triangle", ivec2(640, 480), 60.0f);
-#if defined _MSC_VER && !defined _XBOX
- _chdir("..");
-#elif defined _WIN32 && !defined _XBOX
- _chdir("../..");
-#endif
-
new DebugFps(5, 5);
new Triangle();
diff --git a/tutorial/02_cube.cpp b/tutorial/02_cube.cpp
index 4adaa56b..8d38bd1a 100644
--- a/tutorial/02_cube.cpp
+++ b/tutorial/02_cube.cpp
@@ -18,10 +18,6 @@
using namespace std;
using namespace lol;
-#if defined _WIN32
-# include
-#endif
-
extern char const *lolfx_02_cube;
class Cube : public WorldEntity
@@ -139,12 +135,6 @@ int main(int argc, char **argv)
Application app("Tutorial 2: Cube", ivec2(640, 480), 60.0f);
-#if defined _MSC_VER && !defined _XBOX
- _chdir("..");
-#elif defined _WIN32 && !defined _XBOX
- _chdir("../..");
-#endif
-
new DebugFps(5, 5);
new Cube();
diff --git a/tutorial/03_noise.cpp b/tutorial/03_noise.cpp
index 06986d03..21c6e913 100644
--- a/tutorial/03_noise.cpp
+++ b/tutorial/03_noise.cpp
@@ -18,10 +18,6 @@
using namespace std;
using namespace lol;
-#if defined _WIN32
-# include
-#endif
-
extern char const *lolfx_03_noise;
class NoiseDemo : public WorldEntity
@@ -89,12 +85,6 @@ int main(int argc, char **argv)
Application app("Tutorial 3: Noise", ivec2(1280, 720), 60.0f);
-#if defined _MSC_VER && !defined _XBOX
- _chdir("..");
-#elif defined _WIN32 && !defined _XBOX
- _chdir("../..");
-#endif
-
new NoiseDemo();
app.Run();
diff --git a/tutorial/08_fbo.cpp b/tutorial/08_fbo.cpp
index 43cf84f7..683e50cd 100644
--- a/tutorial/08_fbo.cpp
+++ b/tutorial/08_fbo.cpp
@@ -18,10 +18,6 @@
using namespace std;
using namespace lol;
-#if defined _WIN32
-# include
-#endif
-
extern char const *lolfx_08_fbo;
class FBO : public WorldEntity
@@ -142,12 +138,6 @@ int main(int argc, char **argv)
Application app("Tutorial 08: Framebuffer Object", ivec2(640, 480), 60.0f);
-#if defined _MSC_VER && !defined _XBOX
- _chdir("..");
-#elif defined _WIN32 && !defined _XBOX
- _chdir("../..");
-#endif
-
new FBO();
app.Run();
diff --git a/tutorial/11_fractal.cpp b/tutorial/11_fractal.cpp
index 53f42b29..c90dc313 100644
--- a/tutorial/11_fractal.cpp
+++ b/tutorial/11_fractal.cpp
@@ -18,10 +18,6 @@
#include "core.h"
#include "loldebug.h"
-#if defined _WIN32
-# include
-#endif
-
using namespace lol;
extern char const *lolfx_11_fractal;
@@ -556,12 +552,6 @@ int main(int argc, char **argv)
System::Init(argc, argv);
Application app("Tutorial 3: Fractal", window_size, 60.0f);
-#if defined _MSC_VER && !defined _XBOX
- _chdir("..");
-#elif defined _WIN32 && !defined _XBOX
- _chdir("../..");
-#endif
-
new DebugFps(5, 5);
new Fractal(window_size);
//new DebugRecord("fractalol.ogm", 60.0f);