You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ark Tools provides systems, a scheduler, and other useful stuff for the Ark Entity Component System (ECS).
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 update tick.
package main
import (
"github.com/mlange-42/ark-tools/app""github.com/mlange-42/ark-tools/system""github.com/mlange-42/ark/ecs"
)
// Position component.typePositionstruct {
Xfloat64Yfloat64
}
// Velocity component.typeVelocitystruct {
Xfloat64Yfloat64
}
funcmain() {
// Create a new, seeded app.app:=app.New(1024).Seed(123)
// Limit simulation speed.app.TPS=30// Add systems to the app.app.AddSystem(&VelocitySystem{EntityCount: 1000})
// Add a termination system that ends the simulation.app.AddSystem(&system.FixedTermination{Steps: 100})
// Run the app.app.Run()
}
// VelocitySystem is an example system adding velocity to position.// For simplicity, it also creates entities during initialization.typeVelocitySystemstruct {
EntityCountintfilter*ecs.Filter2[Position, Velocity]
}
// Initialize the system.func (s*VelocitySystem) Initialize(w*ecs.World) {
s.filter=s.filter.New(w)
mapper:= ecs.NewMap2[Position, Velocity](w)
mapper.NewBatch(s.EntityCount, &Position{}, &Velocity{})
}
// Update the system.func (s*VelocitySystem) Update(w*ecs.World) {
query:=s.filter.Query()
forquery.Next() {
pos, vel:=query.Get()
pos.X+=vel.Xpos.Y+=vel.Y
}
}
// Finalize the system.func (s*VelocitySystem) Finalize(w*ecs.World) {}
License
This project is distributed under the MIT licence.
About
Systems, scheduler, and more for the Ark Entity Component System (ECS)