[Components] dependencies
Component dependencies is a tricky part - where we want to handle pathological cases w/o hurting performances.
Dependencies are here for two main reasons:
- Check if a component is needed by others before destroying it - as as
shared_ptr
would do. - Force delete all parent components if a component is removed.
The second case is non standard, and I really wonder if we want to handle that. The alternative is that parents are responsible for cleaning their children at deletion if nobody uses them.
I slightly prefer not allowing for the second bullet. Then we would remove the removeComponent
function from the component manager and we handle component lifetimes through special shared_ptr
.
This also makes the storage of multiple dependent children a lot easier, and optional dependencies will be handled directly by the component manager: getComponentOptional("name", "fallback")
or even better, a chain of options:
getComponentOptional("name", getComponentOptional("fallback", getComponent("fallback_fallback")));
We can also think of type related optionals: unless specified, if a getComponent
fails on a texture, then a dummy hard coded texture is returned instead?
I would also suggest that get getComponent
returns a null shared pointer on failure, and let the user handle it. I still wonder what we should do with components that receive an invalid argument on init ... Maybe we should defer the call of init
to ComponentMgr::create
. init
returns false on failure, in which case the component is delete and create
returns nullptr.