From 84df6ca83bc41e4e0e420e126f56ad566e3e233f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 9 Apr 2024 23:33:36 +0200 Subject: move template away from header Now uses explicit instantiation. --- src/world.cpp | 25 +++++++++++++++++++++++++ src/world.hpp | 27 +-------------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/world.cpp b/src/world.cpp index d1c5dd43..edab80b6 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -2,6 +2,8 @@ #include "chunk.hpp" #include "object.hpp" #include "critter.hpp" +#include "scenery.hpp" +#include "light.hpp" #include "compat/shared-ptr-wrapper.hpp" #include "compat/int-hash.hpp" #include "compat/exception.hpp" @@ -263,4 +265,27 @@ shared_ptr_wrapper world::ensure_player_character(object_id& id_, critt return ret; } +template +std::shared_ptr world::find_object(object_id id) +{ + static_assert(std::is_base_of_v); + // make it a dependent name so that including "src/object.hpp" isn't needed + using U = std::conditional_t, T, object>; + if (std::shared_ptr ptr = find_object_(id); !ptr) + return {}; + else if constexpr(std::is_same_v) + return ptr; + else + { + if (!(ptr->type() == object_type_::value)) [[unlikely]] + throw_on_wrong_object_type(id, ptr->type(), object_type_::value); + return static_pointer_cast(move(ptr)); + } +} + +template std::shared_ptr world::find_object(object_id id); +template std::shared_ptr world::find_object(object_id id); +template std::shared_ptr world::find_object(object_id id); +template std::shared_ptr world::find_object(object_id id); + } // namespace floormat diff --git a/src/world.hpp b/src/world.hpp index 0a15cb03..e805ae1f 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -44,6 +44,7 @@ private: explicit world(size_t capacity); + void do_make_object(const std::shared_ptr& e, global_coords pos, bool sorted); // todo! replace 2nd arg with chunk& void do_kill_object(object_id id); std::shared_ptr find_object_(object_id id); @@ -86,14 +87,6 @@ public: do_make_object(std::static_pointer_cast(ret), pos, sorted); return ret; } - void do_make_object(const std::shared_ptr& e, global_coords pos, bool sorted); // todo! replace 2nd arg with chunk& - -#if 0 - template std::shared_ptr make_unconnected_object(Xs&&... xs) - { - return std::shared_ptr(new T{0, operator[](chunk_coords_{}), {}, forward(xs)...}); - } -#endif template std::shared_ptr find_object(object_id id); @@ -116,22 +109,4 @@ public: world(world&& w) noexcept; }; -template -std::shared_ptr world::find_object(object_id id) -{ - static_assert(std::is_base_of_v); - // make it a dependent name so that including "src/object.hpp" isn't needed - using U = std::conditional_t, T, object>; - if (std::shared_ptr ptr = find_object_(id); !ptr) - return {}; - else if constexpr(std::is_same_v) - return ptr; - else - { - if (!(ptr->type() == object_type_::value)) [[unlikely]] - throw_on_wrong_object_type(id, ptr->type(), object_type_::value); - return static_pointer_cast(move(ptr)); - } -} - } // namespace floormat -- cgit v1.2.3