diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-08 08:31:56 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-08 08:34:05 +0100 |
commit | ae1e2f97ad37b335f210d49dab97502bc468da6e (patch) | |
tree | 925abe235001b79710114483165550f7c8a1729f /loader/atlas.cpp | |
parent | 577a4f6648e5cc2f145c5b9a81c2a540b9d94096 (diff) |
minor cleanup
Diffstat (limited to 'loader/atlas.cpp')
-rw-r--r-- | loader/atlas.cpp | 107 |
1 files changed, 11 insertions, 96 deletions
diff --git a/loader/atlas.cpp b/loader/atlas.cpp index b39bc8f5..a4c38264 100644 --- a/loader/atlas.cpp +++ b/loader/atlas.cpp @@ -1,18 +1,15 @@ #include "impl.hpp" -#include "compat/assert.hpp" +//#include "compat/assert.hpp" #include "compat/exception.hpp" -#include "src/emplacer.hpp" -#include "src/anim-atlas.hpp" -#include <cstdio> -#include <algorithm> -#include <Corrade/Containers/ArrayView.h> -#include <Corrade/Containers/Pair.h> -#include <Corrade/Containers/StridedArrayView.h> -#include <Corrade/Containers/String.h> -#include <Corrade/Utility/Path.h> -#include <Magnum/Trade/ImageData.h> - -// todo rename file to 'scenery.cpp' +//#include "src/emplacer.hpp" +//#include "src/anim-atlas.hpp" +#include <cstring> +//#include <cstdio> +//#include <Corrade/Containers/ArrayView.h> +//#include <Corrade/Containers/Pair.h> +//#include <Corrade/Containers/StridedArrayView.h> +//#include <Corrade/Containers/String.h> +//#include <Magnum/Trade/ImageData.h> namespace floormat { @@ -32,7 +29,7 @@ bool loader_::check_atlas_name(StringView str) noexcept { constexpr auto first_char = "@_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"_s; - if (str == "<invalid>"_s) + if (str == loader.INVALID) return true; if (!str || !first_char.find(str[0])) return false; @@ -42,86 +39,4 @@ bool loader_::check_atlas_name(StringView str) noexcept return true; } -std::shared_ptr<class anim_atlas> -loader_::get_anim_atlas(StringView path) noexcept(false) -{ - - auto anim_info = deserialize_anim_def(path + ".json"); - - for (anim_group& group : anim_info.groups) - { - if (!group.mirror_from.isEmpty()) - { - auto it = std::find_if(anim_info.groups.cbegin(), anim_info.groups.cend(), - [&](const anim_group& x) { return x.name == group.mirror_from; }); - if (it == anim_info.groups.cend()) - fm_throw("can't find group '{}' to mirror from '{}'"_cf, group.mirror_from, group.name); - group.frames = array(arrayView(it->frames)); - for (anim_frame& f : group.frames) - f.ground = Vector2i((Int)f.size[0] - f.ground[0], f.ground[1]); - } - } - - auto tex = texture(""_s, path); - - fm_soft_assert(!anim_info.object_name.isEmpty()); - fm_soft_assert(anim_info.pixel_size.product() > 0); - fm_soft_assert(!anim_info.groups.isEmpty()); - fm_soft_assert(anim_info.nframes > 0); - fm_soft_assert(anim_info.nframes == 1 || anim_info.fps > 0); - const auto size = tex.pixels().size(); - const auto width = size[1], height = size[0]; - fm_soft_assert(anim_info.pixel_size[0] == width && anim_info.pixel_size[1] == height); - - auto atlas = std::make_shared<class anim_atlas>(path, tex, std::move(anim_info)); - return atlas; -} - } // namespace floormat - - - -namespace floormat::loader_detail { - -ArrayView<const String> loader_impl::anim_atlas_list() -{ - if (anim_atlases.empty()) - get_anim_atlas_list(); - fm_assert(!anim_atlases.empty()); - return { anim_atlases.data(), anim_atlases.size() }; -} - -std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name, StringView dir) noexcept(false) -{ - fm_soft_assert(check_atlas_name(name)); - fm_soft_assert(!dir || dir[dir.size()-1] == '/'); - char buf[FILENAME_MAX]; - auto path = make_atlas_path(buf, dir, name); - - if (auto it = anim_atlas_map.find(path); it != anim_atlas_map.end()) - return it->second; - else - { - auto atlas = get_anim_atlas(path); - return anim_atlas_map[atlas->name()] = atlas; - } -} - -void loader_impl::get_anim_atlas_list() -{ - anim_atlases.clear(); - using f = Path::ListFlag; - constexpr auto flags = f::SkipDirectories | f::SkipDotAndDotDot | f::SkipSpecial | f::SortAscending; - if (const auto list = Path::list(ANIM_PATH, flags); list) - { - anim_atlases.reserve(list->size()); - constexpr auto suffix = ".json"_s; - for (StringView str : *list) - if (str.hasSuffix(suffix)) - anim_atlases.emplace_back(str.exceptSuffix(suffix.size())); - } - anim_atlases.shrink_to_fit(); - fm_assert(!anim_atlases.empty()); -} - -} // namespace floormat::loader_detail |