Skip to content

ECS Framework API v2.1.50


ECS Framework API / ComponentSparseSet

Class: ComponentSparseSet

Defined in: ECS/Utils/ComponentSparseSet.ts:33

组件稀疏集合实现

结合通用稀疏集合和组件位掩码

存储结构:

  • 稀疏集合存储实体
  • 位掩码数组存储组件信息
  • 组件类型映射表

Constructors

Constructor

new ComponentSparseSet(): ComponentSparseSet

Defined in: ECS/Utils/ComponentSparseSet.ts:63

Returns

ComponentSparseSet

Accessors

size

Get Signature

get size(): number

Defined in: ECS/Utils/ComponentSparseSet.ts:286

获取实体数量

Returns

number


isEmpty

Get Signature

get isEmpty(): boolean

Defined in: ECS/Utils/ComponentSparseSet.ts:293

检查是否为空

Returns

boolean

Methods

addEntity()

addEntity(entity): void

Defined in: ECS/Utils/ComponentSparseSet.ts:74

添加实体到组件索引

分析实体的组件组成,生成位掩码,并更新所有相关索引。

Parameters

entity

Entity

要添加的实体

Returns

void


removeEntity()

removeEntity(entity): void

Defined in: ECS/Utils/ComponentSparseSet.ts:119

从组件索引中移除实体

清理实体相关的所有索引数据,保持数据结构的紧凑性。

Parameters

entity

Entity

要移除的实体

Returns

void


queryByComponent()

queryByComponent(componentType): Set<Entity>

Defined in: ECS/Utils/ComponentSparseSet.ts:149

查询包含指定组件的所有实体

Parameters

componentType

ComponentType

组件类型

Returns

Set<Entity>

包含该组件的实体集合


queryMultipleAnd()

queryMultipleAnd(componentTypes): Set<Entity>

Defined in: ECS/Utils/ComponentSparseSet.ts:162

多组件查询(AND操作)

查找同时包含所有指定组件的实体。

Parameters

componentTypes

ComponentType[]

组件类型数组

Returns

Set<Entity>

满足条件的实体集合


queryMultipleOr()

queryMultipleOr(componentTypes): Set<Entity>

Defined in: ECS/Utils/ComponentSparseSet.ts:202

多组件查询(OR操作)

查找包含任意一个指定组件的实体。

Parameters

componentTypes

ComponentType[]

组件类型数组

Returns

Set<Entity>

满足条件的实体集合


hasComponent()

hasComponent(entity, componentType): boolean

Defined in: ECS/Utils/ComponentSparseSet.ts:244

检查实体是否包含指定组件

Parameters

entity

Entity

实体

componentType

ComponentType

组件类型

Returns

boolean

是否包含该组件


getEntityMask()

getEntityMask(entity): undefined | BitMask64Data

Defined in: ECS/Utils/ComponentSparseSet.ts:266

获取实体的组件位掩码

Parameters

entity

Entity

实体

Returns

undefined | BitMask64Data

组件位掩码,如果实体不存在则返回undefined


getAllEntities()

getAllEntities(): Entity[]

Defined in: ECS/Utils/ComponentSparseSet.ts:279

获取所有实体

Returns

Entity[]

所有实体的数组


forEach()

forEach(callback): void

Defined in: ECS/Utils/ComponentSparseSet.ts:302

遍历所有实体

Parameters

callback

(entity, mask, index) => void

遍历回调函数

Returns

void


clear()

clear(): void

Defined in: ECS/Utils/ComponentSparseSet.ts:311

清空所有数据

Returns

void


getMemoryStats()

getMemoryStats(): object

Defined in: ECS/Utils/ComponentSparseSet.ts:325

获取内存使用统计

Returns

object

entitiesMemory

entitiesMemory: number

masksMemory

masksMemory: number

mappingsMemory

mappingsMemory: number

totalMemory

totalMemory: number


validate()

validate(): boolean

Defined in: ECS/Utils/ComponentSparseSet.ts:350

验证数据结构完整性

Returns

boolean

Released under the MIT License.