perf(core): 优化 EntitySystem 迭代性能,添加 CommandBuffer 延迟命令 (#281)
* perf(core): 优化 EntitySystem 迭代性能,添加 CommandBuffer 延迟命令 ReactiveQuery 快照优化: - 添加快照机制,避免每帧拷贝数组 - 只在实体列表变化时创建新快照 - 静态场景下多个系统共享同一快照 CommandBuffer 延迟命令系统: - 支持延迟添加/移除组件、销毁实体、设置实体激活状态 - 每个系统拥有独立的 commands 属性 - 命令在帧末统一执行,避免迭代过程中修改实体列表 Scene 更新: - 在 lateUpdate 后自动刷新所有系统的命令缓冲区 文档: - 更新系统文档,添加 CommandBuffer 使用说明 * fix(ci): upgrade first-interaction action to v1.3.0 Fix Docker build failure in welcome workflow. * fix(ci): upgrade pnpm/action-setup to v4 and fix unused import - Upgrade pnpm/action-setup@v2 to v4 in all workflow files - Remove unused CommandType import in CommandBuffer.test.ts * fix(ci): remove duplicate pnpm version specification
This commit is contained in:
@@ -483,6 +483,10 @@ export class Scene implements IScene {
|
||||
} finally {
|
||||
ProfilerSDK.endSample(lateUpdateHandle);
|
||||
}
|
||||
|
||||
// 执行所有系统的延迟命令
|
||||
// Flush all systems' deferred commands
|
||||
this.flushCommandBuffers(systems);
|
||||
} finally {
|
||||
ProfilerSDK.endSample(frameHandle);
|
||||
// 结束性能采样帧
|
||||
@@ -490,6 +494,28 @@ export class Scene implements IScene {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行所有系统的延迟命令
|
||||
* Flush all systems' deferred commands
|
||||
*
|
||||
* 在帧末统一执行所有通过 CommandBuffer 提交的延迟操作。
|
||||
* Execute all deferred operations submitted via CommandBuffer at end of frame.
|
||||
*/
|
||||
private flushCommandBuffers(systems: readonly EntitySystem[]): void {
|
||||
const flushHandle = ProfilerSDK.beginSample('Scene.flushCommandBuffers', ProfileCategory.ECS);
|
||||
try {
|
||||
for (const system of systems) {
|
||||
try {
|
||||
system.flushCommands();
|
||||
} catch (error) {
|
||||
this.logger.error(`Error flushing commands for system ${system.systemName}:`, error);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ProfilerSDK.endSample(flushHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理系统执行错误
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user