From 312c6854324992572f4aa19976ca04d204705aad Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 27 Aug 2023 11:11:33 +0200 Subject: loader: add atlas path maker function --- loader/atlas.cpp | 16 ++++++++++++++++ loader/loader.hpp | 1 + 2 files changed, 17 insertions(+) diff --git a/loader/atlas.cpp b/loader/atlas.cpp index cf3d310e..50645579 100644 --- a/loader/atlas.cpp +++ b/loader/atlas.cpp @@ -13,6 +13,22 @@ #include #include +namespace floormat { + +StringView loader_::make_atlas_path(char(&buf)[FILENAME_MAX], StringView dir, StringView name) +{ + fm_soft_assert(!dir || dir[dir.size()-1] == '/'); + auto name_noext = Path::splitExtension(name).first(); + const auto dirsiz = dir.size(), namesiz = name_noext.size(); + fm_soft_assert(dirsiz + namesiz + 1 < FILENAME_MAX); + std::memcpy(buf, dir.data(), dirsiz); + std::memcpy(&buf[dirsiz], name_noext.data(), namesiz); + buf[dirsiz + namesiz] = '\0'; + return StringView{buf}; +} + +} // namespace floormat + namespace floormat::loader_detail { std::shared_ptr loader_impl::tile_atlas(StringView name, Vector2ub size, Optional pass) noexcept(false) diff --git a/loader/loader.hpp b/loader/loader.hpp index 3ed519e9..937ef828 100644 --- a/loader/loader.hpp +++ b/loader/loader.hpp @@ -35,6 +35,7 @@ struct loader_ static StringView strip_prefix(StringView name); virtual const vobj_info& vobj(StringView name) = 0; virtual ArrayView vobj_list() = 0; + static StringView make_atlas_path(char(&buf)[FILENAME_MAX], StringView dir, StringView name); loader_(const loader_&) = delete; loader_& operator=(const loader_&) = delete; -- cgit v1.2.3