From ccc6b7fcb08f5a5713c2ac74a28113814b4c70b4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 6 Oct 2022 20:32:24 +0200 Subject: a --- compat/assert.hpp | 1 + main/loader-impl.cpp | 34 +++++++++++++++++++++------------- serialize/tile.hpp | 14 ++++++++++++++ test/json.cpp | 4 ++-- 4 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 serialize/tile.hpp diff --git a/compat/assert.hpp b/compat/assert.hpp index 9c55c5b3..81d5d4ab 100644 --- a/compat/assert.hpp +++ b/compat/assert.hpp @@ -12,6 +12,7 @@ constexpr inline void abort(const char (&fmt)[N], Xs... xs) if (std::is_constant_evaluated()) throw "aborting"; else { + std::fputs("fatal: ", stderr); std::fprintf(stderr, fmt, xs...); std::putc('\n', stderr); std::fflush(stderr); diff --git a/main/loader-impl.cpp b/main/loader-impl.cpp index bbf077e1..aeefd081 100644 --- a/main/loader-impl.cpp +++ b/main/loader-impl.cpp @@ -18,19 +18,6 @@ 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; @@ -48,6 +35,8 @@ struct loader_impl final : loader_ Trade::ImageData2D tile_texture(Containers::StringView filename) override; std::shared_ptr tile_atlas(Containers::StringView filename, Vector2ui size) override; + static void set_application_working_directory(); + explicit loader_impl(); ~loader_impl() override; }; @@ -93,6 +82,25 @@ void loader_::destroy() new (&loader) loader_impl(); } +void loader_impl::set_application_working_directory() +{ + static bool once = false; + if (once) + return; + once = true; + const auto location = Utility::Path::executableLocation(); + if (!location) + return; + std::filesystem::path path((std::string)*location); + path.replace_filename(".."); + std::error_code error; + std::filesystem::current_path(path, error); + if (error.value()) { + WARN("failed to change working directory to '%s' (%s)", + path.string().data(), error.message().data()); + } +} + loader_impl::loader_impl() { set_application_working_directory(); diff --git a/serialize/tile.hpp b/serialize/tile.hpp new file mode 100644 index 00000000..4224fa54 --- /dev/null +++ b/serialize/tile.hpp @@ -0,0 +1,14 @@ +#pragma once +#include + +namespace Magnum::Examples { + + + +} // namespace Magnum::Examples + +namespace nlohmann { + + + +} // namespace nlohmann diff --git a/test/json.cpp b/test/json.cpp index a47f08ac..d237c674 100644 --- a/test/json.cpp +++ b/test/json.cpp @@ -1,6 +1,7 @@ #include "app.hpp" #include "serialize/tile-atlas.hpp" #include "serialize/magnum-vector.hpp" +#include "serialize/tile.hpp" #include "serialize/json-helper.hpp" #include "compat/assert.hpp" #include "tile-atlas.hpp" @@ -23,8 +24,7 @@ bool app::test_json() // NOLINT(readability-convert-member-functions-to-static) ret &= json_helper::to_json(v2i_1, output_dir/"vec2i_1.json"); ret &= json_helper::to_json(v2i_2, output_dir/"vec2i_2.json"); } - ASSERT(ret); - return 0; + return ret; } } // namespace Magnum::Examples -- cgit v1.2.3