优化querysystem系统(减少数组拷贝)

移除dirtytracksystem
This commit is contained in:
YHH
2025-09-28 09:40:36 +08:00
parent 6da1585b6b
commit 4f651eb42e
4 changed files with 157 additions and 210 deletions

View File

@@ -538,7 +538,7 @@ describe('QuerySystem - 查询系统测试', () => {
// 修改查询结果不应该影响原始数据
const originalLength = result.entities.length;
result.entities.push(entities[2]); // 尝试修改结果
// readonly 数组不可修改,这是预期的行为
const newResult = querySystem.queryAll(PositionComponent);
expect(newResult.entities.length).toBe(originalLength);
@@ -819,48 +819,23 @@ describe('QuerySystem - 查询系统测试', () => {
expect(stats.entityCount).toBe(12);
});
test('应该能够批量更新组件', () => {
entities[0].addComponent(new PositionComponent(10, 20));
entities[1].addComponent(new VelocityComponent(1, 1));
const updates = [
{ entityId: entities[0].id, componentMask: BigInt(0b1011) },
{ entityId: entities[1].id, componentMask: BigInt(0b1101) }
];
expect(() => {
querySystem.batchUpdateComponents(updates);
}).not.toThrow();
});
test('应该能够清理查询缓存', () => {
// 先进行一次查询建立缓存
querySystem.queryAll(PositionComponent);
test('应该能够标记实体为脏', () => {
entities[0].addComponent(new PositionComponent(10, 20));
expect(() => {
querySystem.markEntityDirty(entities[0], [PositionComponent]);
querySystem.clearCache();
}).not.toThrow();
});
});
describe('性能优化和配置', () => {
test('应该能够手动触发性能优化', () => {
test('应该能够配置查询缓存', () => {
expect(() => {
querySystem.optimizePerformance();
querySystem.clearCache();
}).not.toThrow();
});
test('应该能够配置脏标记系统', () => {
expect(() => {
querySystem.configureDirtyTracking(10, 16);
}).not.toThrow();
});
test('应该能够管理帧生命周期', () => {
expect(() => {
querySystem.beginFrame();
querySystem.endFrame();
}).not.toThrow();
});
test('应该能够获取实体的原型信息', () => {
entities[0].addComponent(new PositionComponent(10, 20));