Flatbuffers Schema:联合向量

Flatbuffers Schema: Vectors of unions

我在尝试并集向量时遇到此错误

error: Vectors of unions are not yet supported in all the specified 
programming languages.

显然 flatbuffers 不支持并集向量。所以我需要另一种数据类型来解决我的问题。这是我的案例:

使用模型实体组件系统 (ECS),我有 3 个实体和 3 个组件,这是结构

EntityA            EntityB            EntityC
    component1        component1        component3
    component3        component2

如果我可以使用并集向量,架构如下所示

union Components { Component1, Component2, Component3 }

table Update {
    component:[Components];
}

其中 Component[N] 是表格。实际上我有一个没有联合向量的解决方案

table Update {
    component1:[Component1];
    component2:[Component2];
    component3:[Component3];
}

但是当组件列表增加时,它变得难以管理。

抱歉,我正在使用 ECS,这实际上是用于游戏开发的。但这不是关于游戏的,所以我认为这是问这种问题的正确地方。

如何在没有联合向量的情况下解决这个问题并且比上面的解决方案更好?

是的,联合向量是一项新功能(几周前才添加),目前仅在 C++ 中可用。

传统的方法是创建一个 table Component { c:Components; } 来包装联合值,然后从中创建一个 [Component]

如果组件数量很多,使用多个向量确实可能会变得低效。