summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--loader/atlas.cpp12
-rw-r--r--loader/impl.hpp4
2 files changed, 8 insertions, 8 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");
diff --git a/loader/impl.hpp b/loader/impl.hpp
index 673460aa..e1d6d649 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -21,8 +21,8 @@ struct loader_impl final : loader_
Containers::Pointer<Trade::AbstractImporter> image_importer;
Containers::Pointer<Trade::AbstractImporter> tga_importer;
- std::unordered_map<String, std::shared_ptr<struct tile_atlas>> tile_atlas_map;
- std::unordered_map<String, std::shared_ptr<struct anim_atlas>> anim_atlas_map;
+ std::unordered_map<StringView, std::shared_ptr<struct tile_atlas>> tile_atlas_map;
+ std::unordered_map<StringView, std::shared_ptr<struct anim_atlas>> anim_atlas_map;
std::vector<String> anim_atlases;
std::vector<serialized_scenery> sceneries_array;