From b644c89c81d89f60a0d82fe208fc76ce1c278a4c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 19 Oct 2022 11:07:44 +0300 Subject: [PATCH] Make the parent handle in Owned templated It may be useful for some components designed to be used with certain entity types. --- source/game/owned.h | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/source/game/owned.h b/source/game/owned.h index 19daa7e..e20ff77 100644 --- a/source/game/owned.h +++ b/source/game/owned.h @@ -16,11 +16,11 @@ class Owned: public Handle public: Owned() = default; - template - Owned(Handle, Args &&...); + template + Owned(Handle

, Args &&...); - template - Owned(Entity &parent, Args &&... args): Owned(Handle::from_object(&parent), std::forward(args)...) { } + template + Owned(P &parent, Args &&... args): Owned(Handle

::from_object(&parent), std::forward(args)...) { } Owned(Owned &&other): Handle(other) { other.ptr = nullptr; } Owned &operator=(Owned &&other); @@ -35,21 +35,18 @@ private: template -template -Owned::Owned(Handle parent, Args &&... args) +template +Owned::Owned(Handle

parent, Args &&... args) { if(!parent) throw std::invalid_argument("Owned::Owned"); - using DependentEntity = std::conditional_t; - Handle dparent = parent; - - Pool &pool = get_stage(*dparent).get_pools().template get_pool(); + Pool &pool = get_stage(*parent).get_pools().template get_pool(); this->ptr = pool.create(parent, std::forward(args)...); if constexpr(std::is_base_of_v) - dparent->add_component(*this); + parent->add_component(*this); else - dparent->add_child(*this); + parent->add_child(*this); } template -- 2.43.0