X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fowned.h;h=a30f040d58269019cd3634159100e7d2f8a976c3;hb=f4ca190e869b9d03bf4f8b7b002c65af9f56c0ad;hp=fc2acab6ecb02ab0d4079630dae5f5fe5b8fc939;hpb=48051ee2bab13f65e48c371e453b9ea65920921e;p=libs%2Fgame.git
diff --git a/source/game/owned.h b/source/game/owned.h
index fc2acab..a30f040 100644
--- a/source/game/owned.h
+++ b/source/game/owned.h
@@ -22,17 +22,26 @@ public:
Owned(Handle
, Args &&...);
template
- Owned(Owned &p, Args &&... a): Owned(static_cast &>(p), std::forward(a)...) { }
-
- template
- requires(!std::is_const_v)
- Owned(P &parent, Args &&... args): Owned(Handle
::from_object(&parent), std::forward(args)...) { }
+ 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);
+
+ template
+ requires std::is_base_of_v
+ Owned(Owned &&other): Handle(other) { other.ptr = nullptr; }
+
+ Owned &operator=(Owned &&other) { assign(std::move(other)); return *this; }
+
+ template
+ requires std::is_base_of_v
+ Owned &operator=(Owned &&other) { assign(std::move(other)); return *this; }
+
~Owned() { destroy(); }
private:
+ template
+ void assign(Owned &&);
+
template
static Stage &get_stage(O &);
@@ -53,28 +62,32 @@ Owned::Owned(Handle parent, Args &&... args)
Stage &stage = get_stage(*parent);
Pool &pool = stage.get_pools().get_pool();
+ bool first_created = !pool.get_capacity();
this->ptr = pool.create(parent, std::forward(args)...);
if constexpr(std::is_base_of_v)
{
+ if(first_created)
+ stage.get_reflector().get_or_create_class().template set_polymorphic_base(**this);
parent->add_component(*this);
stage.get_event_source().emit(*this);
}
else
{
+ if(first_created)
+ stage.get_reflector().get_or_create_class().template set_polymorphic_base(**this);
parent->add_child(*this);
stage.get_event_source().emit(*this);
}
}
template
-Owned &Owned::operator=(Owned &&other)
+template
+void Owned::assign(Owned &&other)
{
destroy();
this->ptr = other.ptr;
other.ptr = nullptr;
-
- return *this;
}
template