X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fowned.h;h=e20ff775b61ed557201f4af40bb9244912d8452e;hb=6a93721ab67315e916f6c649b1f7bc5447d611a4;hp=df3cd94f2fde19079742f1a317be059b576e672d;hpb=248d62f7240d342982ade65a510be912b867fe49;p=libs%2Fgame.git diff --git a/source/game/owned.h b/source/game/owned.h index df3cd94..e20ff77 100644 --- a/source/game/owned.h +++ b/source/game/owned.h @@ -3,13 +3,12 @@ #include #include "handle.h" +#include "stage.h" namespace Msp::Game { class Component; class Entity; -class Root; -class Stage; template class Owned: public Handle @@ -17,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); @@ -36,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 @@ -68,13 +64,10 @@ template template Stage &Owned::get_stage(O &obj) { - using DependentRoot = std::conditional_t; if constexpr(std::is_base_of_v) return get_stage(*obj.get_entity()); - else if constexpr(std::is_base_of_v) - return dynamic_cast(*obj.get_root()).get_stage(); else - return obj; + return obj.get_stage(); } template