Natural way to iterate duplicate components on an entity? #1051
Unanswered
roboticsgeek
asked this question in
Q&A
Replies: 2 comments 1 reply
-
Here is my example code/question: struct A {
int a;
};
world.component<A>();
struct B {
int b;
};
world.component<B>();
A AA;
auto e1 = world.entity("E1");
e1.set(AA);
auto e2 = world.entity("E2");
e2.set(AA);
auto e3 = world.entity("E3");
e3.set(AA);
auto e10 = world.entity("E10");
B BB;
e10.set(e1,BB);
e10.set(e2,BB);
e10.set(e3,BB);
auto eq = world.query_builder()
.term<B>().second(flecs::Wildcard)
.build();
std::cerr << "ITER X?:" << std::endl;
eq.iter([](flecs::iter& it) {
// Why does this run > 1x per entity with it.count() always == 1?
// This gets called 3x in a row.
std::cerr << it.entity(0).name() << "Table [" << it.table().str() << "]"
<< std::endl;
std::cerr << "Entities: " << it.count() << std::endl;
});
std::cerr << "EACH X?:" << std::endl;
eq.each([](flecs::entity e) {
// Why does this run > 1x per entity?
// This gets called 3x with the same entity each time...
std::cerr << e.name() << " .Table [" << e.type().str() << "]" << std::endl;
}); |
Beta Was this translation helpful? Give feedback.
1 reply
-
When you specify |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to be able to store a set of pairs on an entity. Let's say Entity "A" has components B that are pairs that reference other entities, so I have:
A has (B,C), (B,D), (B,E)
I am attempting to write a query that will allow me to iterate over entity A and other entities like it where each entity is iterated once and there is an inner loop for going over the B components. I have tried everything I can and no matter what I do I end up getting a separate, different iter/each call for each component B for the same entity A. I'm working with the latest release in C++. What am I doing wrong?
What I would like is some query/model arrangement where my iteration function gets called once for each entity and I can use the inner loop over the "B"s that are on my entity so I have a variable number of B's for each A. The underlying reason is that I'm accumulating information about the B's as part of the query operation and could do it all in a local variable and set some outputs in a very clean way if I could control this behavior.
I feel like I must be misunderstanding something fundamental somewhere, but I've managed to get a lot of things working really well, but this has me stumped.
Beta Was this translation helpful? Give feedback.
All reactions