Quickstart

This page shows how to install Arche, and gives a minimal usage example.

Finally, it points into possible directions to continue.

Installation

To use Arche in a Go project, run:

1go get github.com/mlange-42/arche

Usage example

Here is the classical Position/Velocity example that every ECS shows in the docs. It uses the type-safe generic API.

 1package main
 2
 3import (
 4	"math/rand"
 5
 6	"github.com/mlange-42/arche/ecs"
 7	"github.com/mlange-42/arche/generic"
 8)
 9
10// Position component
11type Position struct {
12	X float64
13	Y float64
14}
15
16// Velocity component
17type Velocity struct {
18	X float64
19	Y float64
20}
21
22func main() {
23	// Create a World.
24	world := ecs.NewWorld()
25
26	// Create a component mapper.
27	mapper := generic.NewMap2[Position, Velocity](&world)
28
29	// Create entities.
30	for i := 0; i < 1000; i++ {
31		// Create a new Entity with components.
32		entity := mapper.New()
33		// Get the components
34		pos, vel := mapper.Get(entity)
35		// Initialize component fields.
36		pos.X = rand.Float64() * 100
37		pos.Y = rand.Float64() * 100
38		vel.X = rand.NormFloat64()
39		vel.Y = rand.NormFloat64()
40	}
41
42	// Create a generic filter.
43	filter := generic.NewFilter2[Position, Velocity]()
44
45	// Time loop.
46	for t := 0; t < 1000; t++ {
47		// Get a fresh query.
48		query := filter.Query(&world)
49		// Iterate it
50		for query.Next() {
51			// Component access through the Query.
52			pos, vel := query.Get()
53			// Update component fields.
54			pos.X += vel.X
55			pos.Y += vel.Y
56		}
57	}
58}

What’s next?

If you ask “What is ECS?”, take a look at the great ECS FAQ by Sander Mertens, the author of the Flecs ECS.

To learn how to use Arche, read the User Guide, browse the API documentation, or take a look at the examples in the GitHub repository.

You can also read about Arche’s Design Philosophy and Architecture for more background information.

See the Benchmarks if you are interested in some numbers on Arche’s performance.