From: Daniel Karbach Date: Tue, 22 Apr 2014 14:30:17 +0000 (+0200) Subject: resolve data path relative to executable X-Git-Url: http://git.localhorst.tv/?p=orbi.git;a=commitdiff_plain;h=79a34acdc1beff20213f03c326a4aa03c5d47c92 resolve data path relative to executable --- diff --git a/src/app/SDL.h b/src/app/SDL.h index ce116d5..c18f7c2 100644 --- a/src/app/SDL.h +++ b/src/app/SDL.h @@ -1,6 +1,8 @@ #ifndef ORBI_SDL_H_ #define ORBI_SDL_H_ +#include +#include #include @@ -15,6 +17,11 @@ public: SDL(const SDL &) = delete; SDL &operator =(const SDL &) = delete; + std::string GetBasePath() const { + std::unique_ptr base{SDL_GetBasePath(), &SDL_free}; + return std::string(base.get()); + } + }; } diff --git a/src/graphics/Canvas.h b/src/graphics/Canvas.h index f399b36..021bced 100644 --- a/src/graphics/Canvas.h +++ b/src/graphics/Canvas.h @@ -5,6 +5,7 @@ #include "Texture.h" #include "Vector.h" +#include #include @@ -30,6 +31,9 @@ public: Texture CreateStaticTexture(Vector size); Texture LoadTexture(const char *file); + Texture LoadTexture(const std::string &file) { + return LoadTexture(file.c_str()); + } void Copy(Texture &, Vector to); void Copy(Texture &, Rect clip, Vector to); diff --git a/src/orbi.cpp b/src/orbi.cpp index f410a40..42ee910 100644 --- a/src/orbi.cpp +++ b/src/orbi.cpp @@ -31,7 +31,7 @@ int main(int argc, const char *argv[]) { )); Tileset tiles( - canv.LoadTexture("/home/holy/projects/orbi/data/test-tile.png"), + canv.LoadTexture(sdl.GetBasePath() + "../../data/test-tile.png"), Vector(32, 32) );