https://github.com/mlange-42/arche-model
Everything you need to rapidly build a model with the Arche Entity Component System (ECS).
https://github.com/mlange-42/arche-model
ecs entity-component-system go golang individual-based-modelling
Last synced: over 1 year ago
JSON representation
Everything you need to rapidly build a model with the Arche Entity Component System (ECS).
- Host: GitHub
- URL: https://github.com/mlange-42/arche-model
- Owner: mlange-42
- License: mit
- Created: 2023-04-03T11:31:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-08T23:19:55.000Z (over 1 year ago)
- Last Synced: 2025-02-28T03:22:30.825Z (over 1 year ago)
- Topics: ecs, entity-component-system, go, golang, individual-based-modelling
- Language: Go
- Homepage: https://pkg.go.dev/github.com/mlange-42/arche-model
- Size: 130 KB
- Stars: 14
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Arche Model
[](https://github.com/mlange-42/arche-model/actions/workflows/tests.yml)
[](https://coveralls.io/github/mlange-42/arche-model?branch=main)
[](https://goreportcard.com/report/github.com/mlange-42/arche-model)
[](https://pkg.go.dev/github.com/mlange-42/arche-model)
[](https://github.com/mlange-42/arche-model)
[](https://github.com/mlange-42/arche-model/blob/main/LICENSE)
*Arche Model* provides a wrapper around the [Arche](https://github.com/mlange-42/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](https://pkg.go.dev/github.com/mlange-42/arche-model) for more details and examples.
[](https://pkg.go.dev/github.com/mlange-42/arche-model)
```go
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](./LICENSE).