Open Masstronaut opened 6 years ago
Open question: What happens to children when their parent is destroyed?
ComponentHandle
It should have a slot_map ID and a world pointer. The component type is known from the handle type.
ComponentPools will need to know if their component type has a Parent member and fail to compile if it isn't of the right type. They need to provide a generic interface for setting the parent handle on components which takes an EntityRef to the parent.
When a component is added to an entity, it needs to check if there is a parent handle member and if there is and the entity has a parent, the handle needs to be set.
T::ComponentHandle<T> Parent
constexpr ComponentPoolBase::HasParentHandle()
!std::is_same_v<T, Component>
should fail to compileGood progress! One answer to your open question: All children in this case will be unable to have valid handles to their former parent, so these handles should be cleared or safely marked as invalid in some way. There will be cases where we want the children also deleted, and cases where we don't. Allow the client the optional ability to destroy all children when destroying an object. In the case where the children don't destroy, simply clearing the former parent pointers should be sufficient. Providing that all parent objects have child pointers, we can simply navigate to each of these objects and clear the parent pointers before actually destroying the parent object.
To resolve #34, entity hierarchies need to be implemented. This should be done in the form:
EntityRef parent;
EntityRef child;
child.SetParent(parent);
Behind the scenes:
child
added to a vector of childrenparent
handle set to its new parentComponentHandle<T> Parent;
on the child should have theParent
member set to the parent's component of that type, if it has one.Parent
member where!std::is_same_v<T, Component>
should result in a compile time error