archemodel

package module
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2024 License: MIT Imports: 0 Imported by: 0

README

Arche Model

Test status Coverage Status Go Report Card Go Reference GitHub MIT license

Arche Model provides a wrapper around the Arche Entity Component System (ECS), and some common systems and resources. It's purpose is to get started with prototyping and developing simulation models immediately, focussing on the model logic.

Features

  • Scheduler for running logic and UI systems with independent update rates.
  • Interfaces for ECS systems and observers.
  • Ready-to-use systems for common tasks like writing CSV files or terminating a simulation.
  • Common ECS resources, like central PRNG source or the current model tick.

Installation

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

Usage

See the API docs for more details and examples.
Go Reference

package main

import (
	"github.com/mlange-42/arche-model/model"
	"github.com/mlange-42/arche-model/system"
	"github.com/mlange-42/arche/ecs"
	"github.com/mlange-42/arche/generic"
)

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

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

func main() {
	// Create a new, seeded model.
	m := model.New().Seed(123)
	// Limit simulation speed
	m.TPS = 30

	// Add systems to the model.
	m.AddSystem(&VelocitySystem{EntityCount: 1000})
	// Add a termination system that ends the simulation.
	m.AddSystem(&system.FixedTermination{Steps: 100})

	// Run the model.
	m.Run()
}

// VelocitySystem is an example system adding velocity to position.
// For simplicity, it also creates entities during initialization.
type VelocitySystem struct {
	EntityCount int
	filter      generic.Filter2[Position, Velocity]
}

// Initialize the system
func (s *VelocitySystem) Initialize(w *ecs.World) {
	s.filter = *generic.NewFilter2[Position, Velocity]()

	mapper := generic.NewMap2[Position, Velocity](w)
	mapper.NewBatch(s.EntityCount)
}

// Update the system
func (s *VelocitySystem) Update(w *ecs.World) {
	query := s.filter.Query(w)

	for query.Next() {
		pos, vel := query.Get()
		pos.X += vel.X
		pos.Y += vel.Y
	}
}

// Finalize the system
func (s *VelocitySystem) Finalize(w *ecs.World) {}

License

This project is distributed under the MIT licence.

Documentation

Overview

Package archemodel provides a wrapper around and tools for the Arche ECS, for rapid prototyping of simulation models.

See the sub-packages:

Directories

Path Synopsis
examples
readme
The example from the README.
The example from the README.
Package model provides a wrapper around the Arche ECS world that helps with rapid prototyping and model development.
Package model provides a wrapper around the Arche ECS world that helps with rapid prototyping and model development.
Package observer provides interfaces for observers that extract data from the ECS world.
Package observer provides interfaces for observers that extract data from the ECS world.
Package reporter provides reporters as System implementations (github.com/mlange-42/arche-model/model.System).
Package reporter provides reporters as System implementations (github.com/mlange-42/arche-model/model.System).
Package resource provides commonly used resources (in the ECS sense).
Package resource provides commonly used resources (in the ECS sense).
Package system provides general-purpose [model.System] implementations.
Package system provides general-purpose [model.System] implementations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL