Description
Currently I'm using some wrapper components that hold another component "as" their base type, since I can't use views templating on the base class (e.g. registry.view<BaseClass>().each([](auto ent, auto& component){...});
(#78))
Consider SFML's sf::Text
and sf::Sprite
:
Both inherit sf::Drawable
, and I create
struct IDrawable {
sf::Drawable& drawable;
};
and emplace it on construction of either sf::Sprite
or sf::Text
components. Now I can registry.view<IDrawable>().each(...);
and I've iterated both text and sprite components
(See example: minimal.cpp.txt)
It... works. I guess. Feels like I'm overthinking it and turning it into something more complex than it needs to be.
I -can- just have two separate views on sf::Text
and sf::Sprite
components, but I want to understand what the common idiom for this kind of situation is, since my expected approach[0] is currently floating in the pull request void.[1]
TL;DR: I want to iterate distinct components that satisfy a common interface. What is the typical approach?
Thanks for any input!
[0] Issue #859 and PR #871): Component polymorphism support
[1] I -could- just merge that into the entt instance we use, but maybe someone can point out something super simple that I've completely ignored here.
Related(??): Poly (Getting beyond my understanding of templates at that point)
Related: #983 (the common interface iteration mentioned but not addressed)