diff options
-rw-r--r-- | anim-crop-tool/atlas.cpp | 4 | ||||
-rw-r--r-- | anim-crop-tool/atlas.hpp | 4 | ||||
-rw-r--r-- | anim-crop-tool/main.cpp | 45 | ||||
-rw-r--r-- | compat/prelude.hpp | 2 | ||||
-rw-r--r-- | editor/editor.cpp | 1 | ||||
-rw-r--r-- | editor/save.cpp | 5 | ||||
-rw-r--r-- | editor/tile-editor.cpp | 5 | ||||
m--------- | external/corrade | 0 | ||||
m--------- | external/magnum | 0 | ||||
-rw-r--r-- | loader/loader-impl.cpp | 9 | ||||
-rw-r--r-- | main/draw.cpp | 2 | ||||
-rw-r--r-- | serialize/json-helper.cpp | 15 | ||||
-rw-r--r-- | serialize/json-helper.hpp | 15 | ||||
-rw-r--r-- | src/anim-atlas.cpp | 4 | ||||
-rw-r--r-- | src/precomp.hpp | 1 | ||||
-rw-r--r-- | test/json.cpp | 12 |
16 files changed, 59 insertions, 65 deletions
diff --git a/anim-crop-tool/atlas.cpp b/anim-crop-tool/atlas.cpp index d088e733..613792e7 100644 --- a/anim-crop-tool/atlas.cpp +++ b/anim-crop-tool/atlas.cpp @@ -44,7 +44,7 @@ Magnum::Vector2ui anim_atlas::size() const noexcept return {std::max(maxx, row.xpos), ypos + row.max_height}; } -bool anim_atlas::dump(const std::filesystem::path& filename) const +bool anim_atlas::dump(StringView filename) const { auto sz = size(); cv::Mat4b mat((int)sz[1], (int)sz[0]); @@ -59,5 +59,5 @@ bool anim_atlas::dump(const std::filesystem::path& filename) const x.mat.copyTo(mat(roi)); } - return cv::imwrite(filename.string(), mat); + return cv::imwrite(filename.data(), mat); } diff --git a/anim-crop-tool/atlas.hpp b/anim-crop-tool/atlas.hpp index 21e1eff1..6b5f7b95 100644 --- a/anim-crop-tool/atlas.hpp +++ b/anim-crop-tool/atlas.hpp @@ -1,6 +1,6 @@ #pragma once #include <vector> -#include <filesystem> +#include <Corrade/Containers/StringView.h> #include <Magnum/Magnum.h> #include <Magnum/Math/Vector2.h> #include <opencv2/core/mat.hpp> @@ -33,7 +33,7 @@ public: void advance_row(); Magnum::Vector2ui offset() const noexcept; Magnum::Vector2ui size() const noexcept; - [[nodiscard]] bool dump(const std::filesystem::path& filename) const; + [[nodiscard]] bool dump(StringView filename) const; }; } // namespace floormat::Serialize diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp index ad92780f..012710a9 100644 --- a/anim-crop-tool/main.cpp +++ b/anim-crop-tool/main.cpp @@ -14,9 +14,14 @@ #include <string_view> #include <filesystem> +#include <Corrade/Containers/Pair.h> +#include <Corrade/Containers/StringView.h> +#include <Corrade/Containers/String.h> + #include <Corrade/Utility/Arguments.h> #include <Corrade/Utility/Debug.h> #include <Corrade/Utility/DebugStl.h> +#include <Corrade/Utility/Path.h> #include <opencv2/core/mat.hpp> #include <opencv2/imgcodecs/imgcodecs.hpp> @@ -24,20 +29,16 @@ #include "compat/assert.hpp" -using Corrade::Utility::Error; -using Corrade::Utility::Debug; - -using std::filesystem::path; - +using namespace floormat; using namespace floormat::Serialize; -using Magnum::Vector2i; -using Magnum::Vector2ui; +using Corrade::Utility::Error; +using Corrade::Utility::Debug; struct options { double scale = 0; - path input_dir, input_file, output_dir; + String input_dir, input_file, output_dir; std::size_t width = 0, height = 0, nframes = 0; }; @@ -67,10 +68,10 @@ static std::tuple<cv::Vec2i, cv::Vec2i, bool> find_image_bounds(const cv::Mat4b& } [[nodiscard]] -static bool load_file(anim_group& group, options& opts, anim_atlas& atlas, const path& filename) +static bool load_file(anim_group& group, options& opts, anim_atlas& atlas, StringView filename) { auto mat = fm_begin( - cv::Mat mat = cv::imread(filename.string(), cv::IMREAD_UNCHANGED); + cv::Mat mat = cv::imread(filename, cv::IMREAD_UNCHANGED); if (mat.empty() || mat.type() != CV_8UC4) { Error{} << "error: failed to load" << filename << "as RGBA32 image"; @@ -131,11 +132,11 @@ static bool load_file(anim_group& group, options& opts, anim_atlas& atlas, const [[nodiscard]] static bool load_directory(anim_group& group, options& opts, anim_atlas& atlas) { - const auto input_dir = opts.input_dir/std::string_view{group.name.cbegin(), group.name.cend()}; + const auto input_dir = Path::join(opts.input_dir, group.name); - if (std::error_code ec; !std::filesystem::exists(input_dir/".", ec)) + if (!Path::exists(Path::join(input_dir, "."))) { - Error{} << "error: can't open directory" << input_dir << ":" << ec.message(); + Error{} << "error: can't open directory" << input_dir; return false; } @@ -144,7 +145,7 @@ static bool load_directory(anim_group& group, options& opts, anim_atlas& atlas) { char filename[9]; sprintf(filename, "%04d.png", max); - if (std::error_code ec; !std::filesystem::exists(input_dir/filename, ec)) + if (!Path::exists(Path::join(input_dir, filename))) break; } @@ -172,7 +173,7 @@ static bool load_directory(anim_group& group, options& opts, anim_atlas& atlas) { char filename[9]; sprintf(filename, "%04d.png", i); - if (!load_file(group, opts, atlas, input_dir/filename)) + if (!load_file(group, opts, atlas, Path::join(input_dir, filename))) return false; } @@ -214,9 +215,9 @@ static std::tuple<options, Arguments, bool> parse_cmdline(int argc, const char* opts.height = h; opts.output_dir = args.value<std::string>("output"); opts.input_file = args.value<std::string>("input"); - opts.input_dir = opts.input_file.parent_path(); + opts.input_dir = Path::split(opts.input_file).first(); - if (opts.output_dir.empty()) + if (opts.output_dir.isEmpty()) opts.output_dir = opts.input_dir; return { std::move(opts), std::move(args), true }; @@ -283,22 +284,22 @@ int main(int argc, char** argv) if (!load_directory(group, opts, atlas)) return EX_DATAERR; - if (std::error_code ec{}; !std::filesystem::exists(opts.output_dir/".", ec) && - !std::filesystem::create_directory(opts.output_dir, ec)) { + if (std::error_code ec{}; !Path::exists(Path::join(opts.output_dir, ".")) && + !std::filesystem::create_directory(opts.output_dir.data(), ec)) { Error{} << "error: failed to create output directory" << opts.output_dir << ":" << ec.message(); return EX_CANTCREAT; } - const std::string base_name = anim_info.object_name + "_" + anim_info.anim_name; + const String base_name = anim_info.object_name + "_" + anim_info.anim_name; - if (auto pathname = opts.output_dir/(base_name + ".png"); !atlas.dump(pathname)) { + if (auto pathname = Path::join(opts.output_dir, (base_name + ".png")); !atlas.dump(pathname)) { Error{} << "error: failed writing image to" << pathname << ":" << std::strerror(errno); // NOLINT(concurrency-mt-unsafe) return EX_CANTCREAT; } anim_info.pixel_size = Vector2ui(atlas.size()); - floormat::json_helper::to_json<anim>(anim_info, opts.output_dir/(base_name + ".json")); + floormat::json_helper::to_json<anim>(anim_info, Path::join(opts.output_dir, (base_name + ".json"))); return 0; } diff --git a/compat/prelude.hpp b/compat/prelude.hpp index c0c3a40c..97ec3c6c 100644 --- a/compat/prelude.hpp +++ b/compat/prelude.hpp @@ -2,9 +2,11 @@ namespace Corrade::Containers::Literals {} namespace Corrade::Containers {} +namespace Corrade::Utility::Path {} namespace Magnum {} namespace floormat { using namespace ::Magnum; using namespace ::Corrade::Containers; using namespace ::Corrade::Containers::Literals; + namespace Path = Corrade::Utility::Path; // NOLINT(misc-unused-alias-decls) } // namespace floormat diff --git a/editor/editor.cpp b/editor/editor.cpp index 1bba44d6..67d9f344 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -8,7 +8,6 @@ #include <vector> #include <algorithm> -#include <filesystem> namespace floormat { diff --git a/editor/save.cpp b/editor/save.cpp index 35cdf9e7..e3d917fa 100644 --- a/editor/save.cpp +++ b/editor/save.cpp @@ -1,8 +1,6 @@ #include "app.hpp" #include "floormat/main.hpp" #include "src/world.hpp" - -#include <filesystem> #include <Corrade/Utility/Path.h> namespace floormat { @@ -11,9 +9,6 @@ namespace floormat { #define quicksave_file save_dir "/" "quicksave.dat" #define quicksave_tmp save_dir "/" "quicksave.tmp" -namespace Path = Corrade::Utility::Path; -using std::filesystem::path; - static bool ensure_save_directory() { if (Path::make(save_dir)) diff --git a/editor/tile-editor.cpp b/editor/tile-editor.cpp index 965245a9..2a0e9abc 100644 --- a/editor/tile-editor.cpp +++ b/editor/tile-editor.cpp @@ -7,6 +7,7 @@ #include "serialize/json-helper.hpp" #include "serialize/tile-atlas.hpp" #include <Corrade/Containers/StringStl.h> +#include <Corrade/Utility/Path.h> namespace floormat { @@ -17,10 +18,10 @@ tile_editor::tile_editor(editor_mode mode, StringView name) : _name{ name}, _mod void tile_editor::load_atlases() { - static const std::filesystem::path image_path{FM_IMAGE_PATH, std::filesystem::path::generic_format}; + const StringView image_path = FM_IMAGE_PATH; using atlas_array = std::vector<std::shared_ptr<tile_atlas>>; const auto filename = _name + ".json"; - for (auto& atlas : json_helper::from_json<atlas_array>(image_path/filename)) + for (auto& atlas : json_helper::from_json<atlas_array>(Path::join(image_path, filename))) { StringView name = atlas->name(); if (auto x = name.findLast('.'); x) diff --git a/external/corrade b/external/corrade -Subproject 0d75aab1a5d96e39ce75784c4386dc398c9f8e7 +Subproject 1a8f5b2454f863d392db02102f12b0217e3aa6b diff --git a/external/magnum b/external/magnum -Subproject 61bd58c82d649ac168742681f2df1130b9e73a1 +Subproject 6b535a37437155f2b90c2be571a3e8271e3f155 diff --git a/loader/loader-impl.cpp b/loader/loader-impl.cpp index 6b2fe986..03144f30 100644 --- a/loader/loader-impl.cpp +++ b/loader/loader-impl.cpp @@ -5,10 +5,10 @@ #include "src/anim-atlas.hpp" #include "serialize/json-helper.hpp" #include "serialize/anim.hpp" -#include <filesystem> #include <unordered_map> #include <utility> #include <optional> +#include <Corrade/Containers/Pair.h> #include <Corrade/Containers/ArrayViewStl.h> #include <Corrade/Containers/StringView.h> #include <Corrade/Containers/StringStlHash.h> @@ -137,10 +137,7 @@ std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name) else { const auto path = Path::join(FM_ANIM_PATH, name); - std::filesystem::path p = std::string_view{path}; - p.replace_extension("json"); - auto anim_info = json_helper::from_json<Serialize::anim>(p); - p.replace_extension({}); + auto anim_info = json_helper::from_json<Serialize::anim>(Path::splitExtension(path).first() + ".json"); auto tex = texture("", path); fm_assert(!anim_info.anim_name.empty() && !anim_info.object_name.empty()); @@ -149,7 +146,7 @@ std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name) fm_assert(anim_info.nframes > 0); fm_assert(anim_info.nframes == 1 || anim_info.fps > 0); - auto atlas = std::make_shared<struct anim_atlas>(p.string(), tex, std::move(anim_info)); + auto atlas = std::make_shared<struct anim_atlas>(Path::splitExtension(path).first(), tex, std::move(anim_info)); return anim_atlas_map[atlas->name()] = atlas; } } diff --git a/main/draw.cpp b/main/draw.cpp index 5af954dc..abd65f7d 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -183,6 +183,8 @@ void main_impl::drawEvent() } app.draw(); + GL::Renderer::flush(); + do_update(); swapBuffers(); diff --git a/serialize/json-helper.cpp b/serialize/json-helper.cpp index dae3ad96..538bcdcb 100644 --- a/serialize/json-helper.cpp +++ b/serialize/json-helper.cpp @@ -1,28 +1,27 @@ #include "json-helper.hpp" #include <fstream> -#include <filesystem> namespace floormat { -template<typename T, typename P, std::ios_base::openmode open_mode> -static T open_stream(const std::remove_cvref_t<P>& filename) +template<typename T, std::ios_base::openmode mode> +static T open_stream(StringView filename) { T s; s.exceptions(s.exceptions() | std::ios::failbit | std::ios::badbit); - s.open(filename, open_mode); + s.open(filename, mode); return s; } -auto json_helper::from_json_(const fspath& pathname) -> json +auto json_helper::from_json_(StringView filename) -> json { json j; - open_stream<std::ifstream, fspath, std::ios_base::in>(pathname) >> j; + open_stream<std::ifstream, std::ios_base::in>(filename) >> j; return j; } -void json_helper::to_json_(const json& j, const fspath& pathname, int indent) +void json_helper::to_json_(const json& j, StringView filename, int indent) { - (open_stream<std::ofstream, fspath, std::ios_base::out>(pathname) << j.dump(indent, '\t') << '\n').flush(); + (open_stream<std::ofstream, std::ios_base::out>(filename) << j.dump(indent, '\t') << '\n').flush(); } } // namespace floormat diff --git a/serialize/json-helper.hpp b/serialize/json-helper.hpp index e0e2c0ca..90ce2e9a 100644 --- a/serialize/json-helper.hpp +++ b/serialize/json-helper.hpp @@ -1,20 +1,19 @@ #pragma once #include <nlohmann/json.hpp> -#include <filesystem> +#include <Corrade/Containers/StringView.h> namespace floormat { struct json_helper final { using json = nlohmann::json; - using fspath = std::filesystem::path; - template<typename T> static T from_json(const fspath& pathname); - template<typename T> static void to_json(const T& self, const fspath& pathname, int indent = 1); - static json from_json_(const fspath& pathname); - static void to_json_(const json& j, const fspath& pathname, int indent); + template<typename T> static T from_json(StringView pathname); + template<typename T> static void to_json(const T& self, StringView pathname, int indent = 1); + static json from_json_(StringView pathname); + static void to_json_(const json& j, StringView pathname, int indent); }; -template<typename T> T json_helper::from_json(const fspath& pathname) { return from_json_(pathname); } -template<typename T> void json_helper::to_json(const T& self, const fspath& pathname, int indent) { to_json_(json(self), pathname, indent); } +template<typename T> T json_helper::from_json(StringView pathname) { return from_json_(pathname); } +template<typename T> void json_helper::to_json(const T& self, StringView pathname, int indent) { to_json_(json(self), pathname, indent); } } // namespace floormat diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp index 2005526b..47490246 100644 --- a/src/anim-atlas.cpp +++ b/src/anim-atlas.cpp @@ -7,9 +7,7 @@ namespace floormat { -static constexpr std::array<char[3], (std::size_t)rotation::COUNT> name_array = { - "n", "ne", "e", "se", "s", "sw", "w", "nw", -}; +static constexpr const char* name_array[] = { "n", "ne", "e", "se", "s", "sw", "w", "nw", }; std::uint8_t anim_atlas::rotation_to_index(const anim_info& info, rotation r) noexcept { diff --git a/src/precomp.hpp b/src/precomp.hpp index 856d45fe..5d46092e 100644 --- a/src/precomp.hpp +++ b/src/precomp.hpp @@ -23,7 +23,6 @@ #include <algorithm> #include <utility> -#include <filesystem> #include <tuple> #include <array> diff --git a/test/json.cpp b/test/json.cpp index 0cb65278..a7c9e84c 100644 --- a/test/json.cpp +++ b/test/json.cpp @@ -8,6 +8,8 @@ #include "tile.hpp" #include "chunk.hpp" #include "loader.hpp" +#include <Corrade/Containers/StringView.h> +#include <Corrade/Utility/Path.h> namespace floormat { @@ -32,21 +34,21 @@ static chunk make_test_chunk() bool floormat::test_json() // NOLINT(readability-convert-member-functions-to-static) { - const std::filesystem::path output_dir = "../test/."; + constexpr StringView output_dir = "../test/."; { auto atlas = loader.tile_atlas("metal1", {2, 2}); - json_helper::to_json(atlas, output_dir/"atlas.json"); + json_helper::to_json(atlas, Path::join(output_dir, "atlas.json")); } { Magnum::Math::Vector<2, int> v2i_1{1, 2}; Vector2i v2i_2{2, 3}; - json_helper::to_json(v2i_1, output_dir/"vec2i_1.json"); - json_helper::to_json(v2i_2, output_dir/"vec2i_2.json"); + json_helper::to_json(v2i_1, Path::join(output_dir, "vec2i_1.json")); + json_helper::to_json(v2i_2, Path::join(output_dir, "vec2i_2.json")); } { volatile float zero = 0; Magnum::Math::Vector3 vec{0.f/zero, -1.f/zero, 123.f}; - json_helper::to_json(vec, output_dir/"vec3_inf.json"); + json_helper::to_json(vec, Path::join(output_dir, "vec3_inf.json")); } return true; |