废弃core.scene更改为setscene方法

This commit is contained in:
YHH
2025-08-12 11:08:27 +08:00
parent 86cb70a94f
commit 56dd18b983
13 changed files with 96 additions and 85 deletions

View File

@@ -142,6 +142,27 @@ describe('Scene - 场景管理系统测试', () => {
expect(scene.entities.count).toBe(0);
expect(scene.entityProcessors.count).toBe(0);
});
test('应该能够使用配置创建场景', () => {
const configScene = new Scene({ name: "ConfigScene" });
expect(configScene.name).toBe("ConfigScene");
});
test('应该能够获取调试信息', () => {
scene.name = "DebugScene";
scene.createEntity("TestEntity");
scene.addEntityProcessor(new MovementSystem());
const debugInfo = scene.getDebugInfo();
expect(debugInfo.name).toBe("Scene");
expect(debugInfo.entityCount).toBe(1);
expect(debugInfo.processorCount).toBe(1);
expect(debugInfo.isRunning).toBe(false);
expect(debugInfo.entities).toBeDefined();
expect(debugInfo.processors).toBeDefined();
expect(debugInfo.componentStats).toBeDefined();
});
});
describe('实体管理', () => {
@@ -446,6 +467,19 @@ describe('Scene - 场景管理系统测试', () => {
expect(stats.queryStats.totalQueries).toBeGreaterThan(0);
expect(parseFloat(stats.cacheStats.hitRate)).toBeGreaterThanOrEqual(0);
});
test('应该能够压缩组件存储', () => {
// 创建一些实体和组件
const entities = scene.createEntities(10, "Entity");
entities.forEach(entity => {
entity.addComponent(new PositionComponent(Math.random() * 100, Math.random() * 100));
});
// 压缩组件存储应该不抛出异常
expect(() => {
scene.compactComponentStorage();
}).not.toThrow();
});
});
describe('内存管理和性能', () => {