ecs-framework
ecs-framework copied to clipboard
QuerySystem 缓存策略优化
- 每次实体变更都清空全部缓存
- 缓存粒度过粗
需要优化为:
class QuerySystem {
// 精细化缓存失效
invalidateCache(entity: Entity) {
const archetype = this.getArchetype(entity);
// 只失效相关的查询缓存
this.invalidateArchetypeQueries(archetype);
}
// 增量更新
updateEntityCache(entity: Entity, oldMask: BitMask, newMask: BitMask) {
// 计算差异
const added = BitMask.xor(oldMask, newMask);
// 只更新受影响的查询
}
}