GitHub – mlange-42/ark: Ark –

Date:

Share:

To use Ark in a Go project, run:

go get github.com/mlange-42/ark

Below is the classical Position/Velocity example that every ECS shows in the docs.

See the User Guide, API docs and examples for details.

package main

import (
	"math/rand/v2"

	"github.com/mlange-42/ark/ecs"
)

// Position component
type Position struct {
	X float64
	Y float64
}

// Velocity component
type Velocity struct {
	X float64
	Y 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.NewMap2[Position, Velocity](&world)

	// Create entities
	for range 1000 {
		// Create a new Entity with components
		_ = mapper.NewEntity(
			&Position{X: rand.Float64() * 100, Y: rand.Float64() * 100},
			&Velocity{X: rand.NormFloat64(), Y: rand.NormFloat64()},
		)
	}

	// Create a filter
	// Save filters permanently and re-use them for best performance
	filter := ecs.NewFilter2[Position, Velocity](&world)

	// Time loop
	for range 5000 {
		// Get a fresh query
		query := filter.Query()
		// Iterate it
		for query.Next() {
			// Component access through the Query
			pos, vel := query.Get()
			// Update component fields
			pos.X += vel.X
			pos.Y += vel.Y
		}
	}
}
  • ark-serde provides JSON serialization and deserialization for Ark’s World.
  • ark-tools provides systems, a scheduler, and other useful stuff for Ark.
  • ark-pixel provides OpenGL graphics and live plots via the Pixel game engine.

Lange, M. & contributors (2025): Ark – An archetype-based Entity Component System for Go. DOI: 10.5281/zenodo.14994239, GitHub repository: https://github.com/mlange-42/ark

Ark and all its sources and documentation are distributed under the MIT license and the Apache 2.0 license, as your options.

Source link

Subscribe to our magazine

━ more like this

September is Suicide Prevention Month

—email—Dear Frank,I was the one who sent this in September of  2007. It was September of my freshman year in high school and I...

See Grace Coddington’s Travel Collection With Louis Vuitton

You may recall Grace Coddington's highly covetable Catogram capsule collection with Louis Vuitton, which featured her cats, Pumpkin and Blanket, as well as Nicolas...

Glow Recipe Prickly Pear Peptide Mucin Serum Review

Per the instructions, I applied a few pumps onto clean skin in the morning. (You can either apply it to slightly damp skin post-cleanser...

Nuraghe Losa in Abbasanta, Italy

The nuraghe is the main class of ancient megalithic structure found on the island of Sardinia, Italy. They were developed during the so-called Nuragic...