【问题标题】:Flatbuffers Schema: Vectors of unionsFlatbuffers Schema:联合向量
【发布时间】:2017-04-28 04:39:19
【问题描述】:

我在尝试联合向量时遇到此错误

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,这实际上是用于游戏开发的。但这与游戏无关,所以我认为这是提出此类问题的正确地方。

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

【问题讨论】:

    标签: schema flatbuffers


    【解决方案1】:

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

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

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

    【讨论】:

    • 我明白了,所以表更新只包含包含所有组件的表向量,我可以省略一些字段。这是可以接受的答案,而不是使用多个向量。谢谢你
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 2013-08-08
    相关资源
    最近更新 更多