Skip to content

How to efficiently reference entities/components in helper data structures #621

Answered by skypjack
Net5F asked this question in Q&A
Discussion options

You must be logged in to vote

For example, how would you handle something like an array of dirty entities, or an octree?

I don't think that there is a one-fits-all solution for that. It depends on the goal and the actual problem.
For example, for dirty entities, you can use a dedicated component and assign it to entities, then clear the pool at the end of the tick. It's easier to work with probably, especially with views and view packs:

// a single view
for(auto [entt, tc, uc]: registry.view<dirty, T, U>().each()) { ... }

// a view pack
auto pack = registry.view<dirty>() | registry.view<T, U>();
for(auto [entt, tc, uc]: pack.each()) { ... }

Though, you can also put dirty entities in an array and iterate it as:

aut…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Net5F
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants