![]() |
UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
|
#include <MeshAttributeArray.h>
Public Member Functions | |
| template<typename... T> | |
| constexpr | TJumpTable (T... Ts) |
Public Attributes | |
| FnType * | Fns [Size] |
We need a mechanism by which we can iterate all items in the attribute map and perform an arbitrary operation on each. We require polymorphic behavior, as attribute arrays are templated on their attribute type, and derived from a generic base class. However, we cannot have a virtual templated method, so we use a different approach.
Effectively, we wish to cast the attribute array depending on the type member of the base class as we iterate through the map. This might look something like this:
template <typename FuncType> void ForEach(FuncType Func) { for (const auto& MapEntry : Map) { const uint32 Type = MapEntry.Value->GetType(); switch (Type) { case 0: Func(static_cast<TMeshAttributeArraySet<FVector3f>*>(MapEntry.Value.Get()); break; case 1: Func(static_cast<TMeshAttributeArraySet<FVector4f>*>(MapEntry.Value.Get()); break; case 2: Func(static_cast<TMeshAttributeArraySet<FVector2f>*>(MapEntry.Value.Get()); break; case 3: Func(static_cast<TMeshAttributeArraySet<float>*>(MapEntry.Value.Get()); break; .... } } }
(The hope is that the compiler would optimize the switch into a jump table so we get O(1) dispatch even as the number of attribute types increases.)
The approach taken here is to generate a jump table at compile time, one entry per possible attribute type. The function Dispatch(...) is the actual function which gets called. MakeJumpTable() is the constexpr function which creates a static jump table at compile time. Class which implements a function jump table to be automatically generated at compile time. This is used by TAttributesSet to provide O(1) dispatch by attribute type at runtime.
|
inlineexplicitconstexpr |