diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/loader-impl.cpp | 30 | ||||
-rw-r--r-- | main/main.cpp | 10 |
2 files changed, 29 insertions, 11 deletions
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 <filesystem> +#include <unordered_map> +#include <utility> +#include <optional> #include <Corrade/Containers/Optional.h> -#include <Corrade/Containers/StringView.h> +#include <Corrade/Containers/Pair.h> +#include <Corrade/Containers/StringStlView.h> #include <Corrade/PluginManager/PluginManager.h> #include <Corrade/Utility/Resource.h> +#include <Corrade/Utility/Path.h> #include <Magnum/ImageView.h> #include <Magnum/Trade/AbstractImporter.h> #include <Magnum/Trade/ImageData.h> #include <Magnum/Trade/AbstractImageConverter.h> -#include <unordered_map> -#include <utility> -#include <optional> 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<Utility::Resource> 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 <bitset> - #include <Magnum/Magnum.h> #include <Magnum/Math/Vector.h> #include <Magnum/GL/DefaultFramebuffer.h> @@ -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; |