Skip to content

Commit ce6b224

Browse files
committed
- SIMD优化的SoA布局,提供最佳的数据并行处理性能,使用密集存储和TypedArray来最大化缓存效率和SIMD指令利用率
1 parent 45eb8c6 commit ce6b224

File tree

13 files changed

+1003
-246
lines changed

13 files changed

+1003
-246
lines changed

src/ECS/Core/ArchetypeSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class ArchetypeSystem {
187187
* 获取实体的组件类型列表
188188
*/
189189
private getEntityComponentTypes(entity: Entity): ComponentType[] {
190-
return entity.components.map(component => component.constructor as ComponentType);
190+
return Array.from(entity.componentTypes);
191191
}
192192

193193
/**

src/ECS/Core/ComponentIndex.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,9 @@ export class HashComponentIndex implements IComponentIndex {
6868
private _lastUpdated = Date.now();
6969

7070
public addEntity(entity: Entity): void {
71-
const components = entity.components;
72-
const componentTypes = new Set<ComponentType>();
73-
74-
for (const component of components) {
75-
const componentType = component.constructor as ComponentType;
76-
componentTypes.add(componentType);
71+
const componentTypes = entity.componentTypes;
72+
73+
for (const componentType of componentTypes) {
7774

7875
let entities = this._componentToEntities.get(componentType);
7976
if (!entities) {
@@ -83,7 +80,7 @@ export class HashComponentIndex implements IComponentIndex {
8380
entities.add(entity);
8481
}
8582

86-
this._entityToComponents.set(entity, componentTypes);
83+
this._entityToComponents.set(entity, new Set(componentTypes));
8784
this._lastUpdated = Date.now();
8885
}
8986

@@ -229,9 +226,8 @@ export class BitmapComponentIndex implements IComponentIndex {
229226

230227
public addEntity(entity: Entity): void {
231228
let bitmap = 0;
232-
233-
for (const component of entity.components) {
234-
const componentType = component.constructor as ComponentType;
229+
230+
for (const componentType of entity.componentTypes) {
235231
let bit = this._componentTypeToBit.get(componentType);
236232

237233
if (bit === undefined) {

0 commit comments

Comments
 (0)