Changeset 2237


Ignore:
Timestamp:
Jan 21, 2013, 12:28:22 AM (10 years ago)
Author:
sam
Message:

system: try to autodetect the data directory from the executable path;
currently works for images (SDL and GDI+ loaders) and sound samples.

Location:
trunk
Files:
4 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r2175 r2237  
    406406
    407407
    408 dnl Extra libraries we may need
     408dnl  Extra libraries we may need
    409409AC_SUBST(MATH_LIBS)
    410410AC_SUBST(PAM_LIBS)
    411411AC_SUBST(UTIL_LIBS)
    412412
    413 dnl How to use the Lol Engine inside this tree
    414 LOL_CFLAGS="$LOL_CFLAGS -I \$(top_srcdir)/src"
     413dnl  How to use the Lol Engine inside this tree
     414LOL_CFLAGS="$LOL_CFLAGS -I\$(top_srcdir)/src"
     415LOL_CFLAGS="$LOL_CFLAGS -DLOL_SOURCE_SUBDIR=\\\"\$(subdir)\\\""
    415416LOL_CFLAGS="$LOL_CFLAGS $SDL_CFLAGS $GL_CFLAGS $EGL_CFLAGS $LIBPNG_CFLAGS"
    416417LOL_LIBS="$LOL_LIBS $SDL_LIBS $GL_LIBS $EGL_LIBS $LIBPNG_LIBS $D3D_LIBS"
    417418
     419dnl  Extra flags
    418420AC_SUBST(LOL_CFLAGS)
    419421AC_SUBST(LOL_LIBS)
  • trunk/src/Makefile.am

    r2226 r2237  
    2323    lol/math/math.h \
    2424    lol/math/geometry.h \
     25    lol/sys/init.h \
    2526    lol/image/color.h \
    2627    \
     
    7273    \
    7374    mesh/mesh.cpp mesh/mesh.h \
     75    \
     76    sys/init.cpp \
    7477    \
    7578    image/image.cpp image/image.h image/image-private.h \
  • trunk/src/core.h

    r2226 r2237  
    8989#include <lol/math/geometry.h>
    9090
     91#include <lol/sys/init.h>
     92
    9193#include <lol/image/color.h>
    9294
  • trunk/src/image/codec/gdiplus-image.cpp

    r2183 r2237  
    22// Lol Engine
    33//
    4 // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
    55//   This program is free software; you can redistribute it and/or
    66//   modify it under the terms of the Do What The Fuck You Want To
     
    6363    }
    6464
     65    String fullpath = String(System::GetDataDir()) + String(path);
    6566    size_t len;
    66     len = mbstowcs(NULL, path, 0);
     67    len = mbstowcs(NULL, &fullpath[0], 0);
    6768    wchar_t *wpath = new wchar_t[len + 1];
    68     if (mbstowcs(wpath, path, len + 1) == (size_t)-1)
     69    if (mbstowcs(wpath, &fullpath[0], len + 1) == (size_t)-1)
    6970    {
    7071#if !LOL_RELEASE
    71         Log::Error("invalid image name %s\n", path);
     72        Log::Error("invalid image name %s\n", &fullpath[0]);
    7273#endif
    7374        delete[] wpath;
     
    7778    bitmap = NULL;
    7879    status = Gdiplus::Ok;
    79     for (wchar_t const *wname = wpath; *wname; wname++)
     80    bitmap = Gdiplus::Bitmap::FromFile(wpath, 0);
     81    if (bitmap)
    8082    {
    81         bitmap = Gdiplus::Bitmap::FromFile(wname, 0);
    82         if (bitmap)
     83        status = bitmap->GetLastStatus();
     84        if (status != Gdiplus::Ok)
    8385        {
    84             status = bitmap->GetLastStatus();
    85             if (status == Gdiplus::Ok)
    86                 break;
    8786#if !LOL_RELEASE
    8887            if (status != Gdiplus::InvalidParameter)
     
    9089#endif
    9190            delete bitmap;
     91            bitmap = NULL;
    9292        }
    9393    }
  • trunk/src/image/codec/sdl-image.cpp

    r2183 r2237  
    22// Lol Engine
    33//
    4 // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
    55//   This program is free software; you can redistribute it and/or
    66//   modify it under the terms of the Do What The Fuck You Want To
     
    4949
    5050private:
    51     SDL_Surface *img;
     51    SDL_Surface *m_img;
    5252};
    5353
     
    5858bool SdlImageData::Open(char const *path)
    5959{
    60     for (char const *name = path; *name; name++)
    61         if ((img = IMG_Load(name)))
    62             break;
    63 
    64     if (!img)
     60    String fullpath = String(System::GetDataDir()) + String(path);
     61    m_img = IMG_Load(&fullpath[0]);
     62    if (!m_img)
    6563    {
    6664#if !LOL_RELEASE
    67         Log::Error("could not load %s\n", path);
     65        Log::Error("could not load %s\n", &fullpath[0]);
    6866#endif
    6967        return false;
    7068    }
    7169
    72     size = ivec2(img->w, img->h);
     70    size = ivec2(m_img->w, m_img->h);
    7371
    74     if (img->format->BytesPerPixel != 4)
     72    if (m_img->format->BytesPerPixel != 4)
    7573    {
    7674        SDL_Surface *tmp = Create32BppSurface(size);
    77         SDL_BlitSurface(img, NULL, tmp, NULL);
    78         SDL_FreeSurface(img);
    79         img = tmp;
     75        SDL_BlitSurface(m_img, NULL, tmp, NULL);
     76        SDL_FreeSurface(m_img);
     77        m_img = tmp;
    8078    }
    8179
    82     format = img->format->Amask ? Image::FORMAT_RGBA : Image::FORMAT_RGB;
     80    format = m_img->format->Amask ? Image::FORMAT_RGBA : Image::FORMAT_RGB;
    8381
    8482    return true;
     
    8785bool SdlImageData::Close()
    8886{
    89     SDL_FreeSurface(img);
     87    SDL_FreeSurface(m_img);
    9088
    9189    return true;
     
    9492void * SdlImageData::GetData() const
    9593{
    96     return img->pixels;
     94    return m_img->pixels;
    9795}
    9896
  • trunk/src/sample.cpp

    r2216 r2237  
    6464
    6565#if defined USE_SDL_MIXER
    66     data->chunk = Mix_LoadWAV(path);
     66    String fullpath = String(System::GetDataDir()) + String(path);
     67    data->chunk = Mix_LoadWAV(&fullpath[0]);
    6768    if (!data->chunk)
    6869    {
    6970#if !LOL_RELEASE
    70         Log::Error("could not load %s\n", path);
     71        Log::Error("could not load %s\n", &fullpath[0]);
    7172#endif
    7273        SDL_Quit();
  • trunk/test/BtPhysTest.cpp

    r2216 r2237  
    33//
    44// Copyright: (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
    5 //            (c) 2012 Sam Hocevar <sam@hocevar.net>
     5//            (c) 2012-2013 Sam Hocevar <sam@hocevar.net>
    66//
    77
     
    476476int main(int argc, char **argv)
    477477{
     478    System::Init(argc, argv);
     479
    478480    Application app("BtPhysTest", ivec2(1280, 720), 60.0f);
    479481
  • trunk/tools/neercs/neercs.cpp

    r2000 r2237  
    22// Neercs
    33//
    4 // Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net>
    55//
    66
     
    7171int main(int argc, char **argv)
    7272{
     73    System::Init(argc, argv);
     74
    7375    Application app("Neercs", ivec2(800, 600), 60.0f);
    7476
  • trunk/tutorial/01_triangle.cpp

    r2183 r2237  
    22// Lol Engine - Triangle tutorial
    33//
    4 // Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net>
    55//   This program is free software; you can redistribute it and/or
    66//   modify it under the terms of the Do What The Fuck You Want To
     
    7575int main(int argc, char **argv)
    7676{
     77    System::Init(argc, argv);
     78
    7779    Application app("Tutorial 1: Triangle", ivec2(640, 480), 60.0f);
    7880
  • trunk/tutorial/02_cube.cpp

    r2216 r2237  
    136136int main(int argc, char **argv)
    137137{
     138    System::Init(argc, argv);
     139
    138140    Application app("Tutorial 2: Cube", ivec2(640, 480), 60.0f);
    139141
  • trunk/tutorial/03_noise.cpp

    r2183 r2237  
    22// Lol Engine - Noise tutorial
    33//
    4 // Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net>
    55//   This program is free software; you can redistribute it and/or
    66//   modify it under the terms of the Do What The Fuck You Want To
     
    8686int main(int argc, char **argv)
    8787{
     88    System::Init(argc, argv);
     89
    8890    Application app("Tutorial 3: Noise", ivec2(1280, 720), 60.0f);
    8991
  • trunk/tutorial/04_texture.cpp

    r2197 r2237  
    22// Lol Engine - Graphing tutorial
    33//
    4 // Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net>
    55//   This program is free software; you can redistribute it and/or
    66//   modify it under the terms of the Do What The Fuck You Want To
     
    116116int main(int argc, char **argv)
    117117{
     118    System::Init(argc, argv);
     119
    118120    Application app("Tutorial 4: Texture", ivec2(640, 480), 60.0f);
    119121
  • trunk/tutorial/05_easymesh.cpp

    r2226 r2237  
    3030        m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18);
    3131
    32         m_gears[0].m1.Compile("[sc#00f ab 8 1 8 ty -.25]\
    33                               [sc#f9f scb#f9f acg 12 10 5 5 20 20 5 5 0.1 0 s .1 .1 .1 ty -.1 csgu]\
    34                               [sc#fff scb#000 acg 12 10 10 10 20 20 5 5 0.1 0 s .05 .05 .05 tx -1.5 ty .3 csgu]\
    35                               [sc#00f ab 5 3 9 tx 2.5 csgs]\
    36                               [[ sc#fff ab 3   1.4 2   tx -2 tz -2 \
    37                                [sc#fff ab 2.1  .7 1.1 ty .5 tx -1.4 tz -1.4 csgs] mz] csgu] \
    38                               ");
     32        m_gears[0].m1.Compile("[sc#00f ab 8 1 8 ty -.25]"
     33                              "[sc#f9f scb#f9f acg 12 10 5 5 20 20 5 5 0.1 0 s .1 .1 .1 ty -.1 csgu]"
     34                              "[sc#fff scb#000 acg 12 10 10 10 20 20 5 5 0.1 0 s .05 .05 .05 tx -1.5 ty .3 csgu]"
     35                              "[sc#00f ab 5 3 9 tx 2.5 csgs]"
     36                              "[[ sc#fff ab 3   1.4 2   tx -2 tz -2 "
     37                              "[sc#fff ab 2.1  .7 1.1 ty .5 tx -1.4 tz -1.4 csgs] mz] csgu]");
    3938        //m_gears[0].m1.Compile("[sc#f9f scb#f9f acg 12 10 5 5 20 20 5 5 0.1 0 s .1 .1 .1 [sc#00f ab 3 1 2 ty .25 tx 1 csgs]]");
    4039        m_gears[1].m1.Compile("sc#ff9 scb#ff9 acg 54 10 95 95 90 90 -5 -5 0.1 0 s .1 .1 .1");
     
    122121int main(int argc, char **argv)
    123122{
     123    System::Init(argc, argv);
     124
    124125    Application app("Tutorial 5: EasyMesh", ivec2(960, 600), 60.0f);
    125126    new EasyMeshTutorial();
  • trunk/tutorial/08_fbo.cpp

    r2183 r2237  
    22// Lol Engine - Framebuffer Object tutorial
    33//
    4 // Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net>
    55//   This program is free software; you can redistribute it and/or
    66//   modify it under the terms of the Do What The Fuck You Want To
     
    139139int main(int argc, char **argv)
    140140{
     141    System::Init(argc, argv);
     142
    141143    Application app("Tutorial 08: Framebuffer Object", ivec2(640, 480), 60.0f);
    142144
  • trunk/tutorial/11_fractal.cpp

    r2216 r2237  
    554554    ivec2 window_size(640, 480);
    555555
     556    System::Init(argc, argv);
    556557    Application app("Tutorial 3: Fractal", window_size, 60.0f);
    557558
Note: See TracChangeset for help on using the changeset viewer.