summaryrefslogtreecommitdiffhomepage
path: root/loader/atlas.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-12-08 12:41:49 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-12-08 12:41:49 +0100
commit821ef6e0965db31fe110e9659ab7a5dd4b538f15 (patch)
tree0c2ca2eddd3155c377e3f062ea9fbfb07b645e9e /loader/atlas.cpp
parent9acf4738b15738cb2b9646481b75ba0c05a01e78 (diff)
loader: use StringView as keys
Diffstat (limited to 'loader/atlas.cpp')
-rw-r--r--loader/atlas.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/loader/atlas.cpp b/loader/atlas.cpp
index d39a0c40..89b988e9 100644
--- a/loader/atlas.cpp
+++ b/loader/atlas.cpp
@@ -16,11 +16,12 @@ namespace floormat::loader_detail {
std::shared_ptr<tile_atlas> loader_impl::tile_atlas(StringView name, Vector2ub size, Optional<pass_mode> pass) noexcept(false)
{
- fm_soft_assert(check_atlas_name(name));
+ if (auto it = tile_atlas_map.find(name); it != tile_atlas_map.end())
+ return it->second;
- const emplacer e{[&] { return std::make_shared<struct tile_atlas>(name, texture(IMAGE_PATH, name), size, pass); }};
- auto atlas = tile_atlas_map.try_emplace(name, e).first->second;
- fm_soft_assert(!pass || pass == atlas->pass_mode());
+ fm_soft_assert(check_atlas_name(name));
+ auto atlas = std::make_shared<struct tile_atlas>(name, texture(IMAGE_PATH, name), size, pass);
+ tile_atlas_map[atlas->name()] = atlas;
return atlas;
}
@@ -42,12 +43,11 @@ ArrayView<String> loader_impl::anim_atlas_list()
std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name, StringView dir) noexcept(false)
{
- fm_soft_assert(check_atlas_name(name));
-
if (auto it = anim_atlas_map.find(name); 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");