From 437dd5940bad6133561cb896cd558881fa5c8b44 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 6 Oct 2022 17:30:31 +0200 Subject: a --- main/loader-impl.cpp | 30 +++++++++++++++++++++++++----- main/main.cpp | 10 ++++------ 2 files changed, 29 insertions(+), 11 deletions(-) (limited to 'main') diff --git a/main/loader-impl.cpp b/main/loader-impl.cpp index 1ddb8cdb..77f96672 100644 --- a/main/loader-impl.cpp +++ b/main/loader-impl.cpp @@ -1,20 +1,36 @@ #include "loader.hpp" #include "tile-atlas.hpp" #include "compat/assert.hpp" +#include +#include +#include +#include #include -#include +#include +#include #include #include +#include #include #include #include #include -#include -#include -#include namespace Magnum::Examples { +static void set_application_working_directory() +{ + static bool once = false; + if (once) + return; + once = true; + const auto location = *Utility::Path::executableLocation(); + if (const auto dir = Utility::Path::split(location).first(); !dir.isEmpty()) { + const std::filesystem::path path(std::string{dir}); + std::filesystem::current_path(path/".."); + } +} + struct loader_impl final : loader_ { std::optional shader_res; @@ -74,7 +90,11 @@ void loader_::destroy() new (&loader) loader_impl(); } -loader_impl::loader_impl() = default; +loader_impl::loader_impl() +{ + set_application_working_directory(); +} + loader_impl::~loader_impl() = default; static loader_& make_default_loader() diff --git a/main/main.cpp b/main/main.cpp index 14828cad..22cec94f 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -6,9 +6,7 @@ #include "floor-mesh.hpp" #include "wall-mesh.hpp" #include "compat/defs.hpp" - #include - #include #include #include @@ -55,10 +53,10 @@ struct app final : Platform::Application chunk make_test_chunk(); tile_shader _shader; - tile_atlas_ floor1 = loader.tile_atlas("../share/game/images/metal1.tga", {2, 2}); - tile_atlas_ floor2 = loader.tile_atlas("../share/game/images/floor1.tga", {4, 4}); - tile_atlas_ wall1 = loader.tile_atlas("../share/game/images/wood2.tga", {2, 2}); - tile_atlas_ wall2 = loader.tile_atlas("../share/game/images/wood1.tga", {2, 2}); + tile_atlas_ floor1 = loader.tile_atlas("share/game/images/metal1.tga", {2, 2}); + tile_atlas_ floor2 = loader.tile_atlas("share/game/images/floor1.tga", {4, 4}); + tile_atlas_ wall1 = loader.tile_atlas("share/game/images/wood2.tga", {2, 2}); + tile_atlas_ wall2 = loader.tile_atlas("share/game/images/wood1.tga", {2, 2}); chunk _chunk = make_test_chunk(); floor_mesh _floor_mesh; wall_mesh _wall_mesh; -- cgit v1.2.3