44
55## 特性
66
7- - 🚀 高性能:基于原型的组件存储和高效的查询系统
7+ - 🚀 高性能:基于 Archetype 的组件存储和高效的查询系统
88- 🔧 类型安全:完整的 TypeScript 支持
99- 🏗️ 模块化:清晰的架构,支持自定义系统和组件
1010- 📦 轻量级:零依赖,易于集成
11+ - ⚡ 内存高效:连续内存布局,优化的迭代性能
1112
1213## 安装
1314
@@ -44,6 +45,7 @@ world.flushCommands();
4445
4546// 创建查询并更新
4647const query = world .createQuery ([PositionId , VelocityId ]);
48+ const deltaTime = 1.0 / 60.0 ; // 假设60FPS
4749query .forEach ([PositionId , VelocityId ], (entity , position , velocity ) => {
4850 position .x += velocity .x * deltaTime ;
4951 position .y += velocity .y * deltaTime ;
@@ -79,6 +81,12 @@ world.flushCommands(); // 钩子在这里被调用
7981
8082### 运行示例
8183
84+ ``` bash
85+ bun run demo
86+ ```
87+
88+ 或者直接运行:
89+
8290``` bash
8391bun run examples/simple/demo.ts
8492```
@@ -104,6 +112,8 @@ bun run examples/simple/demo.ts
104112### Query
105113
106114- ` forEach(componentIds, callback) ` : 遍历匹配的实体
115+ - ` getEntities() ` : 获取所有匹配实体的ID列表
116+ - ` getEntitiesWithComponents(componentIds) ` : 获取实体及其组件数据
107117
108118### System
109119
@@ -117,6 +127,13 @@ class MySystem implements System {
117127}
118128```
119129
130+ ## 性能特点
131+
132+ - ** Archetype 系统** :实体按组件组合分组,实现连续内存访问
133+ - ** 缓存查询** :查询结果自动缓存,减少重复计算
134+ - ** 命令缓冲区** :延迟执行组件添加/移除,提高批处理效率
135+ - ** 类型安全** :编译时类型检查,无运行时开销
136+
120137## 开发
121138
122139### 运行测试
@@ -135,20 +152,28 @@ bunx tsc --noEmit
135152
136153```
137154src/
138- ├── index.ts # 入口文件
139- ├── entity.ts # 实体和组件管理
140- ├── world.ts # 世界管理
141- ├── archetype.ts # 原型系统
142- ├── query.ts # 查询系统
143- ├── system.ts # 系统接口
144- ├── command-buffer.ts # 命令缓冲区
145- ├── types.ts # 类型定义
146- └── utils.ts # 工具函数
155+ ├── index.ts # 入口文件
156+ ├── entity.ts # 实体和组件管理
157+ ├── world.ts # 世界管理
158+ ├── archetype.ts # Archetype 系统(高效组件存储)
159+ ├── query.ts # 查询系统
160+ ├── query-filter.ts # 查询过滤器
161+ ├── system.ts # 系统接口
162+ ├── command-buffer.ts # 命令缓冲区
163+ ├── types.ts # 类型定义
164+ ├── utils.ts # 工具函数
165+ ├── *.test.ts # 单元测试
166+ ├── query.example.ts # 查询示例
167+ └── *.perf.test.ts # 性能测试
147168
148169examples/
149170└── simple/
150- ├── demo.ts # 基本示例
151- └── README.md # 示例说明
171+ ├── demo.ts # 基本示例
172+ └── README.md # 示例说明
173+
174+ scripts/
175+ ├── build.ts # 构建脚本
176+ └── release.ts # 发布脚本
152177```
153178
154179## 许可证
0 commit comments