From 27dd8b268fbe37fa6eed0c0fc0f013134e5e2dc9 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 18 Mar 2023 16:44:39 +0100 Subject: editor/app: don't duplicate characters on load --- src/world.hpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/world.hpp b/src/world.hpp index f29a83e2..29d5a8dd 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -77,7 +77,7 @@ public: return ret; } - template std::shared_ptr find_entity(std::uint64_t id); + template std::shared_ptr find_entity(std::uint64_t id); bool is_teardown() const { return _teardown; } std::uint64_t entity_counter() const { return _entity_counter; } @@ -98,15 +98,21 @@ world::world(std::unordered_map&& chunks operator[](coord) = std::move(c); } -template +template std::shared_ptr world::find_entity(std::uint64_t id) { static_assert(std::is_base_of_v); - std::shared_ptr ptr = find_entity_(id); - if (!ptr) - return nullptr; - fm_assert(ptr->type == entity_type_::value); - return std::static_pointer_cast(ptr); + // make it a dependent name so that including "src/entity.hpp" isn't needed + using U = std::conditional_t, T, entity>; + if (std::shared_ptr ptr = find_entity_(id); !ptr) + return {}; + else if constexpr(std::is_same_v) + return ptr; + else + { + fm_assert(ptr->type == entity_type_::value); + return std::static_pointer_cast(std::move(ptr)); + } } } // namespace floormat -- cgit v1.2.3