-
-
Notifications
You must be signed in to change notification settings - Fork 892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Iterating through components with common base class or via ducktype #995
Comments
In my opinion, the approach that is most in line with the data-oriented philosophy of ECS would be be to have a different component for each final type, and store the component by value and not by pointer or reference. Struct TextDrawable { struct SpriteDrawable { and you simple iterate them separately: registry.view().each([&renderTarget](const TextDrawable& rDrawable){ registry.view().each([&renderTarget](const SpriteDrawable& rDrawable){ There are several reasons for this:
Dynamic polymorphism kind of beats the purpose of DOD/ECS, so I would advice against it. |
Yeah, I agree with @DaedieGit when it comes to asking should I do it or not?. |
Thank you both so much for the (quick!) input. I understand the situation a lot more clearly now; I knew something was up with my approach! :) |
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
andsf::Sprite
:Both inherit
sf::Drawable
, and I createand emplace it on construction of either
sf::Sprite
orsf::Text
components. Now I canregistry.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
andsf::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)
The text was updated successfully, but these errors were encountered: