fix(tests): 更新测试以使用 GlobalComponentRegistry 实例
修复多个测试文件以适配 ComponentRegistry 从静态类变为实例类的变更: - ComponentStorage.test.ts: 使用 GlobalComponentRegistry.reset() - EntitySerializer.test.ts: 使用 GlobalComponentRegistry 实例 - IncrementalSerialization.test.ts: 使用 GlobalComponentRegistry 实例 - SceneSerializer.test.ts: 使用 GlobalComponentRegistry 实例 - ComponentRegistry.extended.test.ts: 使用 GlobalComponentRegistry,同时注册到 scene.componentRegistry - SystemTypes.test.ts: 在 Scene 创建前注册组件 - QuerySystem.test.ts: mockScene 添加 componentRegistry
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { Component } from '../../../src/ECS/Component';
|
||||
import { ComponentRegistry } from '../../../src/ECS/Core/ComponentStorage/ComponentRegistry';
|
||||
import { GlobalComponentRegistry } from '../../../src/ECS/Core/ComponentStorage/ComponentRegistry';
|
||||
import { Entity } from '../../../src/ECS/Entity';
|
||||
import { Scene } from '../../../src/ECS/Scene';
|
||||
|
||||
describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
// 组件类缓存
|
||||
// 组件类缓存 | Component class cache
|
||||
const componentClassCache = new Map<number, any>();
|
||||
|
||||
beforeEach(() => {
|
||||
ComponentRegistry.reset();
|
||||
GlobalComponentRegistry.reset();
|
||||
componentClassCache.clear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
ComponentRegistry.reset();
|
||||
GlobalComponentRegistry.reset();
|
||||
componentClassCache.clear();
|
||||
});
|
||||
|
||||
@@ -39,11 +39,11 @@ describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
// 注册 100 个组件类型
|
||||
for (let i = 0; i < 100; i++) {
|
||||
const ComponentClass = createTestComponent(i);
|
||||
const bitIndex = ComponentRegistry.register(ComponentClass);
|
||||
const bitIndex = GlobalComponentRegistry.register(ComponentClass);
|
||||
componentTypes.push(ComponentClass);
|
||||
|
||||
expect(bitIndex).toBe(i);
|
||||
expect(ComponentRegistry.isRegistered(ComponentClass)).toBe(true);
|
||||
expect(GlobalComponentRegistry.isRegistered(ComponentClass)).toBe(true);
|
||||
}
|
||||
|
||||
expect(componentTypes.length).toBe(100);
|
||||
@@ -53,14 +53,14 @@ describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
// 注册 80 个组件
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const ComponentClass = createTestComponent(i);
|
||||
ComponentRegistry.register(ComponentClass);
|
||||
GlobalComponentRegistry.register(ComponentClass);
|
||||
}
|
||||
|
||||
// 验证第 70 个组件的位掩码
|
||||
const Component70 = createTestComponent(70);
|
||||
ComponentRegistry.register(Component70);
|
||||
GlobalComponentRegistry.register(Component70);
|
||||
|
||||
const bitMask = ComponentRegistry.getBitMask(Component70);
|
||||
const bitMask = GlobalComponentRegistry.getBitMask(Component70);
|
||||
expect(bitMask).toBeDefined();
|
||||
expect(bitMask.segments).toBeDefined(); // 应该有扩展段
|
||||
expect(bitMask.segments!.length).toBeGreaterThan(0);
|
||||
@@ -70,11 +70,11 @@ describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
// 注册 1500 个组件验证无限制
|
||||
for (let i = 0; i < 1500; i++) {
|
||||
const ComponentClass = createTestComponent(i);
|
||||
const bitIndex = ComponentRegistry.register(ComponentClass);
|
||||
const bitIndex = GlobalComponentRegistry.register(ComponentClass);
|
||||
expect(bitIndex).toBe(i);
|
||||
}
|
||||
|
||||
expect(ComponentRegistry.getRegisteredCount()).toBe(1500);
|
||||
expect(GlobalComponentRegistry.getRegisteredCount()).toBe(1500);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -92,10 +92,13 @@ describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
const componentTypes: any[] = [];
|
||||
const components: any[] = [];
|
||||
|
||||
// 添加 80 个组件
|
||||
// 添加 80 个组件 | Add 80 components
|
||||
// 需要同时注册到 GlobalComponentRegistry(ArchetypeSystem 使用)和 Scene registry
|
||||
// Need to register to both GlobalComponentRegistry (used by ArchetypeSystem) and Scene registry
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const ComponentClass = createTestComponent(i);
|
||||
ComponentRegistry.register(ComponentClass);
|
||||
GlobalComponentRegistry.register(ComponentClass);
|
||||
scene.componentRegistry.register(ComponentClass);
|
||||
componentTypes.push(ComponentClass);
|
||||
|
||||
const component = new ComponentClass();
|
||||
@@ -115,32 +118,35 @@ describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
});
|
||||
|
||||
it('应该能够正确检查超过 64 个组件的存在性', () => {
|
||||
// 添加组件 0-79
|
||||
// 添加组件 0-79 | Add components 0-79
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const ComponentClass = createTestComponent(i);
|
||||
ComponentRegistry.register(ComponentClass);
|
||||
GlobalComponentRegistry.register(ComponentClass);
|
||||
scene.componentRegistry.register(ComponentClass);
|
||||
entity.addComponent(new ComponentClass());
|
||||
}
|
||||
|
||||
// 验证 hasComponent 对所有组件都工作
|
||||
// 验证 hasComponent 对所有组件都工作 | Verify hasComponent works for all
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const ComponentClass = createTestComponent(i);
|
||||
expect(entity.hasComponent(ComponentClass)).toBe(true);
|
||||
}
|
||||
|
||||
// 验证不存在的组件
|
||||
// 验证不存在的组件 | Verify non-existent component
|
||||
const NonExistentComponent = createTestComponent(999);
|
||||
ComponentRegistry.register(NonExistentComponent);
|
||||
GlobalComponentRegistry.register(NonExistentComponent);
|
||||
scene.componentRegistry.register(NonExistentComponent);
|
||||
expect(entity.hasComponent(NonExistentComponent)).toBe(false);
|
||||
});
|
||||
|
||||
it('应该能够移除超过 64 索引的组件', () => {
|
||||
const componentTypes: any[] = [];
|
||||
|
||||
// 添加 80 个组件
|
||||
// 添加 80 个组件 | Add 80 components
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const ComponentClass = createTestComponent(i);
|
||||
ComponentRegistry.register(ComponentClass);
|
||||
GlobalComponentRegistry.register(ComponentClass);
|
||||
scene.componentRegistry.register(ComponentClass);
|
||||
componentTypes.push(ComponentClass);
|
||||
entity.addComponent(new ComponentClass());
|
||||
}
|
||||
@@ -162,10 +168,11 @@ describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
});
|
||||
|
||||
it('应该能够正确遍历超过 64 个组件', () => {
|
||||
// 添加 80 个组件
|
||||
// 添加 80 个组件 | Add 80 components
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const ComponentClass = createTestComponent(i);
|
||||
ComponentRegistry.register(ComponentClass);
|
||||
GlobalComponentRegistry.register(ComponentClass);
|
||||
scene.componentRegistry.register(ComponentClass);
|
||||
entity.addComponent(new ComponentClass());
|
||||
}
|
||||
|
||||
@@ -182,29 +189,29 @@ describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
|
||||
describe('热更新模式', () => {
|
||||
it('默认应该禁用热更新模式', () => {
|
||||
expect(ComponentRegistry.isHotReloadEnabled()).toBe(false);
|
||||
expect(GlobalComponentRegistry.isHotReloadEnabled()).toBe(false);
|
||||
});
|
||||
|
||||
it('应该能够启用和禁用热更新模式', () => {
|
||||
expect(ComponentRegistry.isHotReloadEnabled()).toBe(false);
|
||||
expect(GlobalComponentRegistry.isHotReloadEnabled()).toBe(false);
|
||||
|
||||
ComponentRegistry.enableHotReload();
|
||||
expect(ComponentRegistry.isHotReloadEnabled()).toBe(true);
|
||||
GlobalComponentRegistry.enableHotReload();
|
||||
expect(GlobalComponentRegistry.isHotReloadEnabled()).toBe(true);
|
||||
|
||||
ComponentRegistry.disableHotReload();
|
||||
expect(ComponentRegistry.isHotReloadEnabled()).toBe(false);
|
||||
GlobalComponentRegistry.disableHotReload();
|
||||
expect(GlobalComponentRegistry.isHotReloadEnabled()).toBe(false);
|
||||
});
|
||||
|
||||
it('reset 应该重置热更新模式为禁用', () => {
|
||||
ComponentRegistry.enableHotReload();
|
||||
expect(ComponentRegistry.isHotReloadEnabled()).toBe(true);
|
||||
GlobalComponentRegistry.enableHotReload();
|
||||
expect(GlobalComponentRegistry.isHotReloadEnabled()).toBe(true);
|
||||
|
||||
ComponentRegistry.reset();
|
||||
expect(ComponentRegistry.isHotReloadEnabled()).toBe(false);
|
||||
GlobalComponentRegistry.reset();
|
||||
expect(GlobalComponentRegistry.isHotReloadEnabled()).toBe(false);
|
||||
});
|
||||
|
||||
it('启用热更新时应该替换同名组件类', () => {
|
||||
ComponentRegistry.enableHotReload();
|
||||
GlobalComponentRegistry.enableHotReload();
|
||||
|
||||
// 模拟热更新场景:两个不同的类但有相同的 constructor.name
|
||||
// Simulate hot reload: two different classes with same constructor.name
|
||||
@@ -229,20 +236,20 @@ describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
expect(TestComponentV1.name).toBe(TestComponentV2.name);
|
||||
expect(TestComponentV1).not.toBe(TestComponentV2);
|
||||
|
||||
const index1 = ComponentRegistry.register(TestComponentV1);
|
||||
const index2 = ComponentRegistry.register(TestComponentV2);
|
||||
const index1 = GlobalComponentRegistry.register(TestComponentV1);
|
||||
const index2 = GlobalComponentRegistry.register(TestComponentV2);
|
||||
|
||||
// 应该复用相同的 bitIndex
|
||||
expect(index1).toBe(index2);
|
||||
|
||||
// 新类应该替换旧类
|
||||
expect(ComponentRegistry.isRegistered(TestComponentV2)).toBe(true);
|
||||
expect(ComponentRegistry.isRegistered(TestComponentV1)).toBe(false);
|
||||
expect(GlobalComponentRegistry.isRegistered(TestComponentV2)).toBe(true);
|
||||
expect(GlobalComponentRegistry.isRegistered(TestComponentV1)).toBe(false);
|
||||
});
|
||||
|
||||
it('禁用热更新时不应该替换同名组件类', () => {
|
||||
// 确保热更新被禁用
|
||||
ComponentRegistry.disableHotReload();
|
||||
GlobalComponentRegistry.disableHotReload();
|
||||
|
||||
// 创建两个同名组件
|
||||
// Create two classes with same constructor.name
|
||||
@@ -265,15 +272,15 @@ describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
expect(TestCompA.name).toBe(TestCompB.name);
|
||||
expect(TestCompA).not.toBe(TestCompB);
|
||||
|
||||
const index1 = ComponentRegistry.register(TestCompA);
|
||||
const index2 = ComponentRegistry.register(TestCompB);
|
||||
const index1 = GlobalComponentRegistry.register(TestCompA);
|
||||
const index2 = GlobalComponentRegistry.register(TestCompB);
|
||||
|
||||
// 应该分配不同的 bitIndex(因为热更新被禁用)
|
||||
expect(index2).toBe(index1 + 1);
|
||||
|
||||
// 两个类都应该被注册
|
||||
expect(ComponentRegistry.isRegistered(TestCompA)).toBe(true);
|
||||
expect(ComponentRegistry.isRegistered(TestCompB)).toBe(true);
|
||||
expect(GlobalComponentRegistry.isRegistered(TestCompA)).toBe(true);
|
||||
expect(GlobalComponentRegistry.isRegistered(TestCompB)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -282,14 +289,15 @@ describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
const scene = new Scene();
|
||||
const entity = scene.createEntity('TestEntity');
|
||||
|
||||
// 注册 65 个组件(跨越 64 位边界)
|
||||
// 注册 65 个组件(跨越 64 位边界)| Register 65 components (crossing 64-bit boundary)
|
||||
for (let i = 0; i < 65; i++) {
|
||||
const ComponentClass = createTestComponent(i);
|
||||
ComponentRegistry.register(ComponentClass);
|
||||
GlobalComponentRegistry.register(ComponentClass);
|
||||
scene.componentRegistry.register(ComponentClass);
|
||||
entity.addComponent(new ComponentClass());
|
||||
}
|
||||
|
||||
// 验证第 63, 64, 65 个组件
|
||||
// 验证第 63, 64, 65 个组件 | Verify components 63, 64
|
||||
const Component63 = createTestComponent(63);
|
||||
const Component64 = createTestComponent(64);
|
||||
|
||||
@@ -301,25 +309,27 @@ describe('ComponentRegistry Extended - 64+ 组件支持', () => {
|
||||
const scene = new Scene();
|
||||
const entity = scene.createEntity('TestEntity');
|
||||
|
||||
// 添加 80 个组件
|
||||
// 添加 80 个组件 | Add 80 components
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const ComponentClass = createTestComponent(i);
|
||||
ComponentRegistry.register(ComponentClass);
|
||||
GlobalComponentRegistry.register(ComponentClass);
|
||||
scene.componentRegistry.register(ComponentClass);
|
||||
entity.addComponent(new ComponentClass());
|
||||
}
|
||||
|
||||
// 强制重建缓存(通过访问 components)
|
||||
// 强制重建缓存(通过访问 components)| Force cache rebuild
|
||||
const components1 = entity.components;
|
||||
expect(components1.length).toBe(80);
|
||||
|
||||
// 添加更多组件
|
||||
// 添加更多组件 | Add more components
|
||||
for (let i = 80; i < 90; i++) {
|
||||
const ComponentClass = createTestComponent(i);
|
||||
ComponentRegistry.register(ComponentClass);
|
||||
GlobalComponentRegistry.register(ComponentClass);
|
||||
scene.componentRegistry.register(ComponentClass);
|
||||
entity.addComponent(new ComponentClass());
|
||||
}
|
||||
|
||||
// 重新获取组件数组(应该重建缓存)
|
||||
// 重新获取组件数组(应该重建缓存)| Re-get component array (should rebuild cache)
|
||||
const components2 = entity.components;
|
||||
expect(components2.length).toBe(90);
|
||||
});
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { ComponentRegistry, ComponentStorage, ComponentStorageManager } from '../../../src/ECS/Core/ComponentStorage';
|
||||
import { ComponentRegistry, GlobalComponentRegistry, ComponentStorage, ComponentStorageManager } from '../../../src/ECS/Core/ComponentStorage';
|
||||
import { Component } from '../../../src/ECS/Component';
|
||||
import { BitMask64Utils } from '../../../src/ECS/Utils/BigIntCompatibility';
|
||||
|
||||
// 为测试创建独立的注册表实例 | Create isolated registry instance for tests
|
||||
let testRegistry: ComponentRegistry;
|
||||
|
||||
// 测试组件类(默认使用原始存储)
|
||||
class TestComponent extends Component {
|
||||
public value: number;
|
||||
@@ -51,89 +54,88 @@ class HealthComponent extends Component {
|
||||
|
||||
describe('ComponentRegistry - 组件注册表测试', () => {
|
||||
beforeEach(() => {
|
||||
// 重置注册表状态
|
||||
(ComponentRegistry as any).componentTypes = new Map<Function, number>();
|
||||
(ComponentRegistry as any).nextBitIndex = 0;
|
||||
// 每个测试创建新的注册表实例 | Create new registry instance for each test
|
||||
testRegistry = new ComponentRegistry();
|
||||
});
|
||||
|
||||
describe('组件注册功能', () => {
|
||||
test('应该能够注册组件类型', () => {
|
||||
const bitIndex = ComponentRegistry.register(TestComponent);
|
||||
|
||||
const bitIndex = testRegistry.register(TestComponent);
|
||||
|
||||
expect(bitIndex).toBe(0);
|
||||
expect(ComponentRegistry.isRegistered(TestComponent)).toBe(true);
|
||||
expect(testRegistry.isRegistered(TestComponent)).toBe(true);
|
||||
});
|
||||
|
||||
test('重复注册相同组件应该返回相同的位索引', () => {
|
||||
const bitIndex1 = ComponentRegistry.register(TestComponent);
|
||||
const bitIndex2 = ComponentRegistry.register(TestComponent);
|
||||
|
||||
const bitIndex1 = testRegistry.register(TestComponent);
|
||||
const bitIndex2 = testRegistry.register(TestComponent);
|
||||
|
||||
expect(bitIndex1).toBe(bitIndex2);
|
||||
expect(bitIndex1).toBe(0);
|
||||
});
|
||||
|
||||
test('应该能够注册多个组件类型', () => {
|
||||
const bitIndex1 = ComponentRegistry.register(TestComponent);
|
||||
const bitIndex2 = ComponentRegistry.register(PositionComponent);
|
||||
const bitIndex3 = ComponentRegistry.register(VelocityComponent);
|
||||
|
||||
const bitIndex1 = testRegistry.register(TestComponent);
|
||||
const bitIndex2 = testRegistry.register(PositionComponent);
|
||||
const bitIndex3 = testRegistry.register(VelocityComponent);
|
||||
|
||||
expect(bitIndex1).toBe(0);
|
||||
expect(bitIndex2).toBe(1);
|
||||
expect(bitIndex3).toBe(2);
|
||||
});
|
||||
|
||||
test('应该能够检查组件是否已注册', () => {
|
||||
expect(ComponentRegistry.isRegistered(TestComponent)).toBe(false);
|
||||
|
||||
ComponentRegistry.register(TestComponent);
|
||||
expect(ComponentRegistry.isRegistered(TestComponent)).toBe(true);
|
||||
expect(testRegistry.isRegistered(TestComponent)).toBe(false);
|
||||
|
||||
testRegistry.register(TestComponent);
|
||||
expect(testRegistry.isRegistered(TestComponent)).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('位掩码功能', () => {
|
||||
test('应该能够获取组件的位掩码', () => {
|
||||
ComponentRegistry.register(TestComponent);
|
||||
ComponentRegistry.register(PositionComponent);
|
||||
|
||||
const mask1 = ComponentRegistry.getBitMask(TestComponent);
|
||||
const mask2 = ComponentRegistry.getBitMask(PositionComponent);
|
||||
|
||||
testRegistry.register(TestComponent);
|
||||
testRegistry.register(PositionComponent);
|
||||
|
||||
const mask1 = testRegistry.getBitMask(TestComponent);
|
||||
const mask2 = testRegistry.getBitMask(PositionComponent);
|
||||
|
||||
expect(BitMask64Utils.getBit(mask1,0)).toBe(true); // 2^0
|
||||
expect(BitMask64Utils.getBit(mask2,1)).toBe(true); // 2^1
|
||||
});
|
||||
|
||||
test('应该能够获取组件的位索引', () => {
|
||||
ComponentRegistry.register(TestComponent);
|
||||
ComponentRegistry.register(PositionComponent);
|
||||
|
||||
const index1 = ComponentRegistry.getBitIndex(TestComponent);
|
||||
const index2 = ComponentRegistry.getBitIndex(PositionComponent);
|
||||
|
||||
testRegistry.register(TestComponent);
|
||||
testRegistry.register(PositionComponent);
|
||||
|
||||
const index1 = testRegistry.getBitIndex(TestComponent);
|
||||
const index2 = testRegistry.getBitIndex(PositionComponent);
|
||||
|
||||
expect(index1).toBe(0);
|
||||
expect(index2).toBe(1);
|
||||
});
|
||||
|
||||
test('获取未注册组件的位掩码应该抛出错误', () => {
|
||||
expect(() => {
|
||||
ComponentRegistry.getBitMask(TestComponent);
|
||||
testRegistry.getBitMask(TestComponent);
|
||||
}).toThrow('Component type TestComponent is not registered');
|
||||
});
|
||||
|
||||
test('获取未注册组件的位索引应该抛出错误', () => {
|
||||
expect(() => {
|
||||
ComponentRegistry.getBitIndex(TestComponent);
|
||||
testRegistry.getBitIndex(TestComponent);
|
||||
}).toThrow('Component type TestComponent is not registered');
|
||||
});
|
||||
});
|
||||
|
||||
describe('注册表管理', () => {
|
||||
test('应该能够获取所有已注册的组件类型', () => {
|
||||
ComponentRegistry.register(TestComponent);
|
||||
ComponentRegistry.register(PositionComponent);
|
||||
|
||||
const allTypes = ComponentRegistry.getAllRegisteredTypes();
|
||||
|
||||
testRegistry.register(TestComponent);
|
||||
testRegistry.register(PositionComponent);
|
||||
|
||||
const allTypes = testRegistry.getAllRegisteredTypes();
|
||||
|
||||
expect(allTypes.size).toBe(2);
|
||||
expect(allTypes.has(TestComponent)).toBe(true);
|
||||
expect(allTypes.has(PositionComponent)).toBe(true);
|
||||
@@ -142,12 +144,12 @@ describe('ComponentRegistry - 组件注册表测试', () => {
|
||||
});
|
||||
|
||||
test('返回的注册表副本不应该影响原始数据', () => {
|
||||
ComponentRegistry.register(TestComponent);
|
||||
|
||||
const allTypes = ComponentRegistry.getAllRegisteredTypes();
|
||||
testRegistry.register(TestComponent);
|
||||
|
||||
const allTypes = testRegistry.getAllRegisteredTypes();
|
||||
allTypes.set(PositionComponent, 999);
|
||||
|
||||
expect(ComponentRegistry.isRegistered(PositionComponent)).toBe(false);
|
||||
|
||||
expect(testRegistry.isRegistered(PositionComponent)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -156,10 +158,9 @@ describe('ComponentStorage - 组件存储器测试', () => {
|
||||
let storage: ComponentStorage<TestComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
// 重置注册表
|
||||
(ComponentRegistry as any).componentTypes = new Map<Function, number>();
|
||||
(ComponentRegistry as any).nextBitIndex = 0;
|
||||
|
||||
// 每个测试创建新的注册表实例 | Create new registry instance for each test
|
||||
testRegistry = new ComponentRegistry();
|
||||
|
||||
storage = new ComponentStorage(TestComponent);
|
||||
});
|
||||
|
||||
@@ -358,10 +359,9 @@ describe('ComponentStorageManager - 组件存储管理器测试', () => {
|
||||
let manager: ComponentStorageManager;
|
||||
|
||||
beforeEach(() => {
|
||||
// 重置注册表
|
||||
(ComponentRegistry as any).componentTypes = new Map<Function, number>();
|
||||
(ComponentRegistry as any).nextBitIndex = 0;
|
||||
|
||||
// 重置全局注册表 | Reset global registry
|
||||
GlobalComponentRegistry.reset();
|
||||
|
||||
manager = new ComponentStorageManager();
|
||||
});
|
||||
|
||||
@@ -455,10 +455,10 @@ describe('ComponentStorageManager - 组件存储管理器测试', () => {
|
||||
|
||||
describe('位掩码功能', () => {
|
||||
test('应该能够获取实体的组件位掩码', () => {
|
||||
// 确保组件已注册
|
||||
ComponentRegistry.register(TestComponent);
|
||||
ComponentRegistry.register(PositionComponent);
|
||||
ComponentRegistry.register(VelocityComponent);
|
||||
// 确保组件已注册 | Ensure components are registered
|
||||
GlobalComponentRegistry.register(TestComponent);
|
||||
GlobalComponentRegistry.register(PositionComponent);
|
||||
GlobalComponentRegistry.register(VelocityComponent);
|
||||
|
||||
manager.addComponent(1, new TestComponent(100));
|
||||
manager.addComponent(1, new PositionComponent(10, 20));
|
||||
@@ -475,8 +475,8 @@ describe('ComponentStorageManager - 组件存储管理器测试', () => {
|
||||
});
|
||||
|
||||
test('添加和移除组件应该更新掩码', () => {
|
||||
ComponentRegistry.register(TestComponent);
|
||||
ComponentRegistry.register(PositionComponent);
|
||||
GlobalComponentRegistry.register(TestComponent);
|
||||
GlobalComponentRegistry.register(PositionComponent);
|
||||
|
||||
manager.addComponent(1, new TestComponent(100));
|
||||
let mask = manager.getComponentMask(1);
|
||||
|
||||
@@ -894,10 +894,12 @@ describe('QuerySystem - 查询系统测试', () => {
|
||||
const independentQuerySystem = new QuerySystem();
|
||||
const testEntity = scene.createEntity('ArchetypeTestEntity');
|
||||
|
||||
// 模拟Scene环境(保留componentStorageManager)
|
||||
// 模拟Scene环境(保留componentStorageManager和componentRegistry)
|
||||
// Mock Scene environment (keep componentStorageManager and componentRegistry)
|
||||
const mockScene = {
|
||||
querySystem: independentQuerySystem,
|
||||
componentStorageManager: scene.componentStorageManager,
|
||||
componentRegistry: scene.componentRegistry,
|
||||
clearSystemEntityCaches: jest.fn()
|
||||
};
|
||||
testEntity.scene = mockScene as any;
|
||||
@@ -938,10 +940,12 @@ describe('QuerySystem - 查询系统测试', () => {
|
||||
const independentQuerySystem = new QuerySystem();
|
||||
const testEntity = scene.createEntity('RemoveAllTestEntity');
|
||||
|
||||
// 模拟Scene环境(保留componentStorageManager)
|
||||
// 模拟Scene环境(保留componentStorageManager和componentRegistry)
|
||||
// Mock Scene environment (keep componentStorageManager and componentRegistry)
|
||||
const mockScene = {
|
||||
querySystem: independentQuerySystem,
|
||||
componentStorageManager: scene.componentStorageManager,
|
||||
componentRegistry: scene.componentRegistry,
|
||||
clearSystemEntityCaches: jest.fn()
|
||||
};
|
||||
testEntity.scene = mockScene as any;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Component } from '../../../src/ECS/Component';
|
||||
import { HierarchySystem } from '../../../src/ECS/Systems/HierarchySystem';
|
||||
import { HierarchyComponent } from '../../../src/ECS/Components/HierarchyComponent';
|
||||
import { ECSComponent } from '../../../src/ECS/Decorators';
|
||||
import { ComponentRegistry, ComponentType } from '../../../src/ECS/Core/ComponentStorage';
|
||||
import { GlobalComponentRegistry, ComponentType } from '../../../src/ECS/Core/ComponentStorage';
|
||||
import { Serializable, Serialize } from '../../../src/ECS/Serialization';
|
||||
|
||||
@ECSComponent('EntitySerTest_Position')
|
||||
@@ -40,16 +40,18 @@ describe('EntitySerializer', () => {
|
||||
let componentRegistry: Map<string, ComponentType>;
|
||||
|
||||
beforeEach(() => {
|
||||
ComponentRegistry.reset();
|
||||
ComponentRegistry.register(PositionComponent);
|
||||
ComponentRegistry.register(VelocityComponent);
|
||||
ComponentRegistry.register(HierarchyComponent);
|
||||
// 重置全局注册表 | Reset global registry
|
||||
GlobalComponentRegistry.reset();
|
||||
|
||||
GlobalComponentRegistry.register(PositionComponent);
|
||||
GlobalComponentRegistry.register(VelocityComponent);
|
||||
GlobalComponentRegistry.register(HierarchyComponent);
|
||||
|
||||
scene = new Scene({ name: 'EntitySerializerTestScene' });
|
||||
hierarchySystem = new HierarchySystem();
|
||||
scene.addSystem(hierarchySystem);
|
||||
|
||||
componentRegistry = ComponentRegistry.getAllComponentNames() as Map<string, ComponentType>;
|
||||
componentRegistry = GlobalComponentRegistry.getAllComponentNames() as Map<string, ComponentType>;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
ChangeOperation
|
||||
} from '../../../src/ECS/Serialization';
|
||||
import { ECSComponent } from '../../../src/ECS/Decorators';
|
||||
import { ComponentRegistry } from '../../../src/ECS/Core/ComponentStorage';
|
||||
import { GlobalComponentRegistry } from '../../../src/ECS/Core/ComponentStorage';
|
||||
|
||||
// 测试组件定义
|
||||
@ECSComponent('IncTest_Position')
|
||||
@@ -56,12 +56,14 @@ describe('Incremental Serialization System', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
IncrementalSerializer.resetVersion();
|
||||
ComponentRegistry.reset();
|
||||
|
||||
// 重新注册测试组件
|
||||
ComponentRegistry.register(PositionComponent);
|
||||
ComponentRegistry.register(VelocityComponent);
|
||||
ComponentRegistry.register(HealthComponent);
|
||||
// 重置全局注册表 | Reset global registry
|
||||
GlobalComponentRegistry.reset();
|
||||
|
||||
// 重新注册测试组件 | Re-register test components
|
||||
GlobalComponentRegistry.register(PositionComponent);
|
||||
GlobalComponentRegistry.register(VelocityComponent);
|
||||
GlobalComponentRegistry.register(HealthComponent);
|
||||
|
||||
scene = new Scene({ name: 'IncrementalTestScene' });
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Component } from '../../../src/ECS/Component';
|
||||
import { HierarchySystem } from '../../../src/ECS/Systems/HierarchySystem';
|
||||
import { HierarchyComponent } from '../../../src/ECS/Components/HierarchyComponent';
|
||||
import { ECSComponent } from '../../../src/ECS/Decorators';
|
||||
import { ComponentRegistry, ComponentType } from '../../../src/ECS/Core/ComponentStorage';
|
||||
import { GlobalComponentRegistry, ComponentType } from '../../../src/ECS/Core/ComponentStorage';
|
||||
import { Serializable, Serialize } from '../../../src/ECS/Serialization';
|
||||
|
||||
@ECSComponent('SceneSerTest_Position')
|
||||
@@ -40,7 +40,7 @@ describe('SceneSerializer', () => {
|
||||
beforeEach(() => {
|
||||
scene = new Scene({ name: 'SceneSerializerTestScene' });
|
||||
|
||||
componentRegistry = ComponentRegistry.getAllComponentNames() as Map<string, ComponentType>;
|
||||
componentRegistry = GlobalComponentRegistry.getAllComponentNames() as Map<string, ComponentType>;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { IntervalSystem } from '../../../src/ECS/Systems/IntervalSystem';
|
||||
import { ProcessingSystem } from '../../../src/ECS/Systems/ProcessingSystem';
|
||||
import { Entity } from '../../../src/ECS/Entity';
|
||||
import { Component } from '../../../src/ECS/Component';
|
||||
import { ComponentRegistry } from '../../../src/ECS/Core/ComponentStorage';
|
||||
import { GlobalComponentRegistry } from '../../../src/ECS/Core/ComponentStorage';
|
||||
import { Time } from '../../../src/Utils/Time';
|
||||
import { Matcher } from '../../../src/ECS/Utils/Matcher';
|
||||
import { Core } from '../../../src/Core';
|
||||
@@ -85,13 +85,15 @@ describe('System Types - 系统类型测试', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
Core.create();
|
||||
// 注册测试组件类型 | Register test component types
|
||||
// 必须在创建 Scene 之前注册,因为 Scene 会克隆 GlobalComponentRegistry
|
||||
// Must register before Scene creation, as Scene clones GlobalComponentRegistry
|
||||
GlobalComponentRegistry.register(TestComponent);
|
||||
GlobalComponentRegistry.register(AnotherComponent);
|
||||
scene = new Scene();
|
||||
entity = scene.createEntity('TestEntity');
|
||||
// 重置时间系统
|
||||
Time.update(0.016);
|
||||
// 注册测试组件类型
|
||||
ComponentRegistry.register(TestComponent);
|
||||
ComponentRegistry.register(AnotherComponent);
|
||||
});
|
||||
|
||||
describe('PassiveSystem - 被动系统', () => {
|
||||
|
||||
Reference in New Issue
Block a user