From c929fb0a915dd88c9e9d8ce4f2650c34ae205d40 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 18 Mar 2023 21:07:01 +0100 Subject: loader: fix anim_atlas cache --- loader/atlas.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/loader/atlas.cpp b/loader/atlas.cpp index bda6a46b..9057746f 100644 --- a/loader/atlas.cpp +++ b/loader/atlas.cpp @@ -43,12 +43,21 @@ ArrayView loader_impl::anim_atlas_list() std::shared_ptr loader_impl::anim_atlas(StringView name, StringView dir) noexcept(false) { - if (auto it = anim_atlas_map.find(name); it != anim_atlas_map.end()) + constexpr std::size_t bufsiz = PATH_MAX; + char path_buf[PATH_MAX]; + name = Path::splitExtension(name).first(); + fm_assert(dir.size() + name.size() + 1 < bufsiz); + std::memcpy(path_buf, dir.data(), dir.size()); + path_buf[dir.size()] = '/'; + std::memcpy(&path_buf[dir.size() + 1], name.data(), name.size()); + path_buf[dir.size() + 1 + name.size()] = '\0'; + const StringView path = path_buf; + + if (auto it = anim_atlas_map.find(path); it != anim_atlas_map.end()) return it->second; else { fm_soft_assert(check_atlas_name(name)); - const auto path = Path::join(dir, Path::splitExtension(name).first()); auto anim_info = deserialize_anim(path + ".json"); for (anim_group& group : anim_info.groups) @@ -65,7 +74,7 @@ std::shared_ptr loader_impl::anim_atlas(StringView name, StringView } } - auto tex = texture("", path); + auto tex = texture(""_s, path); fm_soft_assert(!anim_info.object_name.isEmpty()); fm_soft_assert(anim_info.pixel_size.product() > 0); -- cgit v1.2.3