我正在编写一个简单的实体组件系统框架,我想在其中使用可变参数模板来获得更灵活的接口。对于每个组件,我都有偏移量(从块内存的开始)存储在std::array. 在我的 'update()' 方法中,我想从这个数组中读取偏移量,将它添加到块的指针并将指针(指向特定组件)作为参数直接传递给 lambda。我尝试使用std::index_sequence,但无法同时使用此索引作为元组和数组的索引。预先感谢您的帮助。
template<typename ...Cn>
class SystemGroup {
public:
using OffsetArray = std::array<uint16_t, sizeof...(Cn)>;
static constexpr size_t kMaxGroups = 16;
static constexpr GroupIndex kInvalidIndex = -1;
struct Group {
static constexpr uint8_t kNumComponents = sizeof...(Cn);
OffsetArray componentOffsets;
Chunk *pFirstChunk;
};
};
template<typename ...Cn>
void SystemGroup<Cn...>::update() {
for (auto group : m_groups) {
// iterate over archetype's chunks
ecs::Chunk *pChunk = group.pFirstChunk;
do {
// get component data
std::tuple<Cn*...> pointers;
// Here is the problem. …Run Code Online (Sandbox Code Playgroud) c++ template-meta-programming variadic-templates stdtuple c++20