Generic & ID-based API

Arche provides two different APIs:

A generic API that is often the most convenient. But perhaps more importantly, it is type safe. It is the recommended way of usage for most users.

An ID-based API that is slightly faster than the generic one in some places. Further, it is more flexible and may be more appropriate for tasks like automated serialization.

Both APIs can be mixed as needed.

Tip

In this user guide, most code examples will be presented with two tabs, one for each API:

 1world := ecs.NewWorld()
 2
 3filter := generic.NewFilter2[Position, Velocity]()
 4
 5query := filter.Query(&world)
 6for query.Next() {
 7	pos, vel := query.Get()
 8	pos.X += vel.X
 9	pos.Y += vel.Y
10}
 1world := ecs.NewWorld()
 2
 3posID := ecs.ComponentID[Position](&world)
 4velID := ecs.ComponentID[Velocity](&world)
 5filter := ecs.All(posID, velID)
 6
 7query := world.Query(filter)
 8for query.Next() {
 9	pos := (*Position)(query.Get(posID))
10	vel := (*Velocity)(query.Get(posID))
11	pos.X += vel.X
12	pos.Y += vel.Y
13}