entt
entt copied to clipboard
Working with multiple storages for the same type and preparing a view for each of the storages
There a couple of different posts that are similar to this. I apologize if this seems like a duplicate but I am not clear on how to achieve the following:
I have a component UserDefinedStruct that I would like to add to an Entity multiple times where the component is differentiated by an index that is generated at runtime.
Pool<UserDefinedStruct>(0)
Pool<UserDefinedStruct>(1)
Pool<UserDefinedStruct>(2)
...
Which then allows an entity to have the component UserDefinedStruct multiple times as long as they have a different index.
I would then like to view each pool such that I get UserDefinedStruct& and the entity that the component is associated with.
I realize this is not a valid call in entt, but something like:
const int runtime_id_from_somewhere = Get_RuntimeId();
reg.view<UserDefinedStruct>(runtime_id_from_somewhere).each(...)
I think it's more similar to:
auto &storage = registry.storage<UserDefinedStruct>(id);
storage.emplace(entity, args...);
For when you want to emplace/erase entities for example, while you can do this for the view:
entt::basic_view ud_view{registry.storage<UserDefinedStruct>(id));
for(auto [entt, my_t, my_ud]: (registry.view<T>() | ud_view)) { ... }
Is this on the line of what you're looking for? Not sure I got your request. 😅
@skypjack thanks, this is pretty much exactly what I was looking for. I'll try this out and update here.
I'm marking this issue as solved. Feel free to continue the discussion here if it is not. 👍