Skip to content

Home > @esengine/ecs-framework-monorepo > ComponentSparseSet

ComponentSparseSet class

组件稀疏集合实现

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

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

Signature:

typescript
export declare class ComponentSparseSet

Constructors

Constructor

Modifiers

Description

(constructor)()

Constructs a new instance of the ComponentSparseSet class

Properties

Property

Modifiers

Type

Description

isEmpty

readonly

boolean

检查是否为空

size

readonly

number

获取实体数量

Methods

Method

Modifiers

Description

addEntity(entity)

添加实体到组件索引

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

clear()

清空所有数据

forEach(callback)

遍历所有实体

getAllEntities()

获取所有实体

getEntityMask(entity)

获取实体的组件位掩码

getMemoryStats()

获取内存使用统计

hasComponent(entity, componentType)

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

queryByComponent(componentType)

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

queryMultipleAnd(componentTypes)

多组件查询(AND操作)

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

queryMultipleOr(componentTypes)

多组件查询(OR操作)

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

removeEntity(entity)

从组件索引中移除实体

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

validate()

验证数据结构完整性

基于 MIT 许可证发布