X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fowned.h;h=620c6aab54e2114a7e3c718256fb794a92593d47;hb=f93a0f0afe8aff4d0bbc8ee393918881cfdd9db8;hp=e20ff775b61ed557201f4af40bb9244912d8452e;hpb=6a93721ab67315e916f6c649b1f7bc5447d611a4;p=libs%2Fgame.git diff --git a/source/game/owned.h b/source/game/owned.h index e20ff77..620c6aa 100644 --- a/source/game/owned.h +++ b/source/game/owned.h @@ -2,6 +2,7 @@ #define MSP_GAME_OWNED_H_ #include +#include "events.h" #include "handle.h" #include "stage.h" @@ -41,12 +42,19 @@ Owned::Owned(Handle

parent, Args &&... args) if(!parent) throw std::invalid_argument("Owned::Owned"); - Pool &pool = get_stage(*parent).get_pools().template get_pool(); + Stage &stage = get_stage(*parent); + Pool &pool = stage.get_pools().template get_pool(); this->ptr = pool.create(parent, std::forward(args)...); if constexpr(std::is_base_of_v) + { parent->add_component(*this); + stage.get_event_source().emit(*this); + } else + { parent->add_child(*this); + stage.get_event_source().emit(*this); + } } template @@ -77,13 +85,20 @@ void Owned::destroy() if(!obj) return; - Pool &pool = get_stage(*obj).get_pools().template get_pool(); + Stage &stage = get_stage(*obj); if constexpr(std::is_base_of_v) + { + stage.get_event_source().emit(*this); obj->get_entity()->remove_component(*this); + } else if(auto parent = obj->get_parent().get()) + { + stage.get_event_source().emit(*this); parent->remove_child(*this); + } + Pool &pool = stage.get_pools().template get_pool(); pool.destroy(this->ptr); }