-
Heyo, I have a general question: is there a standard "best practice" way to handle referencing components in data structures that you use alongside the registry? For example, how would you handle something like an array of dirty entities, or an octree? Should you store just the entt::entity identifier and later use that with a group or view's get()? Or should you store structs that contain direct references to the components that you need? Is there any likelihood of benefitting from sorting a group and maintaining a sorting on the other data structure? I'm sure there's a lot of nuance to this, but I'm just trying to get a sense of what kind of solutions are typical. Edit: Semi-related question while I'm at it: if I have a single entity and I have to get a reference to 2-3 of its components, and I don't already have the relevant group in scope, is it faster to call get() on the registry, or to get the group first and call get() on that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You should store |
Beta Was this translation helpful? Give feedback.
-
I don't think that there is a one-fits-all solution for that. It depends on the goal and the actual problem.
Though, you can also put dirty entities in an array and iterate it as:
In both cases, you can use their iterators with the range functionalities of a registry, like:
As for an octree instead, you can use entity identifiers as elements in it. Otherwise, you can use a custom pool to register with the registry and have an octree implemented directly within the pool itself.
For a single entity, it doesn't really matter. For multiple entities, it's better to use a view, mainly because it storeas aside the pointers to its pools, so you avoid the lookup for them. |
Beta Was this translation helpful? Give feedback.
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:
Though, you can also put dirty entities in an array and iterate it as: