diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-12-08 12:41:49 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-12-08 12:41:49 +0100 |
commit | 821ef6e0965db31fe110e9659ab7a5dd4b538f15 (patch) | |
tree | 0c2ca2eddd3155c377e3f062ea9fbfb07b645e9e /loader | |
parent | 9acf4738b15738cb2b9646481b75ba0c05a01e78 (diff) |
loader: use StringView as keys
Diffstat (limited to 'loader')
-rw-r--r-- | loader/atlas.cpp | 12 | ||||
-rw-r--r-- | loader/impl.hpp | 4 |
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; |