EnTT: 排序

记录 EnTT 组件池排序、实体顺序排序和存储顺序同步的基本接口。

排序

在 EnTT 中, 可以对 组件池 采取不需要申请任何内存的 就地排序

主要有几种方式

组件顺序

可以根据某组件的可比较顺序进行直接排序

// renderable 组件池的稠密数组会根据组件中 z 属性的大小排列
registry.sort<renderable>([](const renderable &lhs, const renderable &rhs) {
    return lhs.z < rhs.z;
});

或者通过访问他们的实体标识符顺序进行排序

// renderable 组件池的稠密数组会按照实体 ID 的顺序排列
registry.sort<renderable>([](const entt::entity lhs, const entt::entity rhs) {
    return entt::registry::entity(lhs) < entt::registry::entity(rhs);
});

又或是根据其他组件的顺序来排序

// movement 组件的顺序将与 physics 对齐, 这将在对他们两一起进行迭代时获得最小化对 cache miss
registry.sort<movement, physics>();

注意, 使用 将失去 组件排序 的功能