特性
- 设计注重性能且高度优化。详见基准测试。
- 文档完善,类型安全的API,以及全面的用户指南。
- 将实体关系作为一等公民特性。
- 可扩展的事件系统,支持过滤和自定义事件类型。
- 快速的批量操作,用于大规模操作。
- 无系统概念。仅使用查询。使用你自己的结构(或工具)。
- 支持通过 ark-serde 进行世界的序列化与反序列化。
- 零依赖,100%测试覆盖率。
安装
要在 Go 项目中使用 Ark,请运行:
go get github.com/mlange-42/ark使用方法
下面是每个 ECS 文档中展示的经典位置/速度示例。
package mainimport (
"math/rand/v2"
"github.com/mlange-42/ark/ecs"
)
// Position component
type Position struct {
X, Y float64
}
// Velocity component
type Velocity struct {
DX, DY float64
}
func main() {
// Create a new World
world := ecs.NewWorld()
// Create a component mapper
// Save mappers permanently and re-use them for best performance
mapper := ecs.NewMap2Position, Velocity
// Create entities with components
for range 1000 {
_ = mapper.NewEntity(
&Position{X: rand.Float64() 100, Y: rand.Float64() 100},
&Velocity{DX: rand.NormFloat64(), DY: rand.NormFloat64()},
)
}
// Create a filter
// Save filters permanently and re-use them for best performance
filter := ecs.NewFilter2Position, Velocity
// Time loop
for range 5000 {
// Get a fresh query and iterate it
query := filter.Query()
for query.Next() {
// Component access through the Query
pos, vel := query.Get()
// Update component fields
pos.X += vel.DX
pos.Y += vel.DY
}
}
}
工具
- ark-serde 为 Ark 的世界提供 JSON 序列化和反序列化。
- ark-tools 提供系统、调度器及其他对 Ark 有用的功能。
- ark-pixel 通过 Pixel 游戏引擎提供 OpenGL 图形和实时绘图。
引用方式
Lange, M. & contributors (2025):Ark – 基于原型的 Go 语言实体组件系统。DOI:10.5281/zenodo.14994239,GitHub 仓库:https://github.com/mlange-42/ark
许可证
Ark 及其所有源代码和文档均根据 MIT 许可证 和 Apache 2.0 许可证 进行分发,供您选择。
--- Tranlated By Open Ai Tx | Last indexed: 2026-03-03 ---