Creating a view from elements with respect to their assigned type id #1282
Replies: 5 comments
-
|
This is my initial approach to this problem, having an overload for registry::view that takes in index sequence should do the job for me: template<typename ... ComponentTypes>
auto CreateView()
{
return CreateViewImpl<ComponentTypes...>(std::make_index_sequence<sizeof...(ComponentTypes)>{});
}
template<typename ... ComponentTypes>
auto CreateView() const
{
return CreateViewImpl<ComponentTypes...>(std::make_index_sequence<sizeof...(ComponentTypes)>{});
}
template<typename ... ComponentTypes, size_t... Is>
auto CreateViewImpl(std::index_sequence<Is...>)
{
return mRegistry.view<ComponentTypes...>(GetStorageId<ComponentTypes>()...);
}
template<typename ... ComponentTypes, size_t... Is>
auto CreateViewImpl(std::index_sequence<Is...>) const
{
return mRegistry.view<ComponentTypes...>(GetStorageId<ComponentTypes>()...);
}
template<typename T>
auto GetStorageId() const
{
if constexpr (Reflection::Traits::IsReflected<T>::value)
{
const auto& classDesc = Reflection::GetClass<T>();
return classDesc.TypeHash();
}
else
{
return entt::type_id<T>().hash();
}
} |
Beta Was this translation helpful? Give feedback.
-
I must admit that I don't get exactly what you are trying to do/achieve. Sorry. Do you want to construct a view at runtime without providing the types at compile-time? Can you be more specific on the what I want rather than what I tried? Thanks. 🙏 |
Beta Was this translation helpful? Give feedback.
-
|
Sorry for the delay. No, I want the same behaviour and API to create views except that instead of using entt::type_hash for retrieving underlying storage, i want it to use my own reflection system's type hash. I will provide types in compile time but type hashes are provided in the runtime but i guess we can agree that a runtime version should do the job for me, where it takes only the type hashes for storages |
Beta Was this translation helpful? Give feedback.
-
Well, you have a few options here. One it to attach the EnTT hash to your meta types and use it anyway. Otherwise, you can override the way EnTT generate hashes, as long as you can define them at compile time. In this case, you can use your own and EnTT won't complain. This is a fully customizable part in the library actually. The idea is exactly to make it easy to bridge EnTT with other existing libraries that aren't part of this repo. 👍 |
Beta Was this translation helpful? Give feedback.
-
|
Side note: turning this into a discussion, since technically speaking it's not an issue. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to iterate over a view of components where their storage has a unique assigned ID from my custom reflection system. Is there a built-in functionality to achieve this? If not, how to implement one myself, here is my simple abstraction to iterate set of components without using the reflection system's type id:
and here is an example where i use the reflection system's type id:
Beta Was this translation helpful? Give feedback.
All reactions