Skip to content

Latest commit

 

History

History
107 lines (81 loc) · 3.96 KB

README.md

File metadata and controls

107 lines (81 loc) · 3.96 KB

Ark (logo) Test status Coverage Status Go Report Card User Guide Go Reference GitHub MIT license

Ark is an archetype-based Entity Component System (ECS) for Go. It is the successor of Arche.

——

Features   •   Installation   •   Usage   •   Tools

Features

Installation

To use Ark in a Go project, run:

go get github.com/mlange-42/ark

Usage

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.
	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.
	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
		}
	}
}

Tools

  • 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.

License

This project is distributed under the MIT license.