muninn is a lightweight, high-performance, archetype-based Entity Component System (ECS) written in Odin.
“Muninn” — Norse for “memory”, the raven that flies over Midgard to bring information to Odin.
——
A cache-optimized ECS implementing archetype-based SoA storage. By packing entities with identical component signatures into contiguous memory blocks, muninn maximizes data locality and enables high-throughput linear iteration, minimizing CPU cache misses.
Important
muninn is developed as the core ECS for Sweet Engine. The API is experimental and subject to change as the engine's requirements evolve.
Clone the repository directly into your project's shared or libs directory:
git clone https://github.com/GuilHartt/muninn libs/muninn
package main
import ecs "libs/muninn/ecs"
Position :: distinct [2]f32
Velocity :: distinct [2]f32
main :: proc() {
world := ecs.create_world()
e := ecs.create_entity(world)
ecs.add(world, e, Position{0, 0})
ecs.add(world, e, Velocity{1, 1})
ecs.each(world, proc(it: ecs.Iter, pos: ^Position, vel: ^Velocity) {
pos.x += vel.x
pos.y += vel.y
})
ecs.destroy_world(world)
}
The goal is to provide a robust foundation for data-oriented games in Odin.
- Archetype Storage: Contiguous SoA memory layout for maximum cache locality and SIMD-friendliness.
- Entity Relationships: First-class support for Pairs (e.g.,
ChildOf, Parent) and Wildcard matching. - Queries: Efficient filtering with
With,Without, and cached archetype iteration. - Iterators: High-level syntax wrappers to reduce boilerplate in query loops.
- Component Toggling: Enable or disable components without triggering structural changes, preserving archetype stability and performance.
- Observers: Event-driven hooks for component lifecycle events (Add, Remove, Set).
- Resources: Singleton storage for world-scoped data (e.g.,
Camera,PhysicsWorld), avoiding global state. - Command Buffer: Queue deferred operations to safely modify world structure during system execution.
Comprehensive documentation is currently being written and will be hosted on GitHub Pages.
This project is licensed under the zlib License.
See the LICENSE file for the full legal text.
Credits: Created by Guilherme Avelar (GuilHartt)