Changeset 2237 for trunk/src


Ignore:
Timestamp:
Jan 21, 2013, 12:28:22 AM (8 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/src
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • 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();
Note: See TracChangeset for help on using the changeset viewer.