Explorar el Código

core: pass the project directory to the binary build and get rid of

that 2-year old "temporary Win32 hack".
legacy
Sam Hocevar sam hace 12 años
padre
commit
bbf72e1a64
Se han modificado 10 ficheros con 53 adiciones y 82 borrados
  1. +2
    -0
      build/vs2010/Lol.Core.Rules.props
  2. +2
    -1
      src/image/codec/gdiplus-image.cpp
  3. +17
    -11
      src/lol/sys/init.h
  4. +32
    -10
      src/sys/init.cpp
  5. +0
    -10
      test/BtPhysTest.cpp
  6. +0
    -10
      tutorial/01_triangle.cpp
  7. +0
    -10
      tutorial/02_cube.cpp
  8. +0
    -10
      tutorial/03_noise.cpp
  9. +0
    -10
      tutorial/08_fbo.cpp
  10. +0
    -10
      tutorial/11_fractal.cpp

+ 2
- 0
build/vs2010/Lol.Core.Rules.props Ver fichero

@@ -13,6 +13,8 @@
<AdditionalIncludeDirectories Condition="'$(Platform)'=='Win32'">$(GlIncludes);$(SdlIncludes);$(D3d9Includes);$(XinputIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Platform)'=='x64'">$(GlIncludes);$(SdlIncludes);$(D3d9Includes);$(XinputIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NOMINMAX;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>LOL_CONFIG_PROJECTDIR="$(ProjectDir.Replace('\',"\\"))";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>LOL_CONFIG_SOLUTIONDIR="$(SolutionDir.Replace('\',"\\"))";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Platform)'=='Win32'">WIN32;$(Win32Defines);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Platform)'=='x64'">WIN32;$(Win32Defines);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Platform)'=='Xbox 360'">_XBOX;$(XboxDefines);%(PreprocessorDefinitions)</PreprocessorDefinitions>


+ 2
- 1
src/image/codec/gdiplus-image.cpp Ver fichero

@@ -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;


+ 17
- 11
src/lol/sys/init.h Ver fichero

@@ -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<char const *> &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<char const *> 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 */



+ 32
- 10
src/sys/init.cpp Ver fichero

@@ -20,25 +20,47 @@ namespace lol
namespace System
{

void Init(Array<char const *> &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;
}
}
}


+ 0
- 10
test/BtPhysTest.cpp Ver fichero

@@ -9,10 +9,6 @@
# include "config.h"
#endif

#if defined _WIN32
# include <direct.h>
#endif

#if defined _XBOX
# define _USE_MATH_DEFINES /* for M_PI */
# include <xtl.h>
@@ -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);



+ 0
- 10
tutorial/01_triangle.cpp Ver fichero

@@ -18,10 +18,6 @@
using namespace std;
using namespace lol;

#if defined _WIN32
# include <direct.h>
#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();



+ 0
- 10
tutorial/02_cube.cpp Ver fichero

@@ -18,10 +18,6 @@
using namespace std;
using namespace lol;

#if defined _WIN32
# include <direct.h>
#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();



+ 0
- 10
tutorial/03_noise.cpp Ver fichero

@@ -18,10 +18,6 @@
using namespace std;
using namespace lol;

#if defined _WIN32
# include <direct.h>
#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();


+ 0
- 10
tutorial/08_fbo.cpp Ver fichero

@@ -18,10 +18,6 @@
using namespace std;
using namespace lol;

#if defined _WIN32
# include <direct.h>
#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();


+ 0
- 10
tutorial/11_fractal.cpp Ver fichero

@@ -18,10 +18,6 @@
#include "core.h"
#include "loldebug.h"

#if defined _WIN32
# include <direct.h>
#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);


Cargando…
Cancelar
Guardar