- Odin 96%
- Nix 4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| ecs | ||
| .editorconfig | ||
| .gitignore | ||
| flake.lock | ||
| flake.nix | ||
| LICENSE | ||
| odinfmt.json | ||
| ols.json | ||
| README.md | ||
MECSio
Description
A matrix ECS library in Odin. Probably less efficient then other ECS implementations, but can boast a nice, simple API and pointer stability. Doesn't actually have of a concept of systems.
Building
Needs the Odin core library.
MECSio's heavy use of generics might cause some build issues. I would recommend trying the -no-threaded-checker odin build flag to resolve those issues. You can also put it into ols.json: "checker_args", if ols crashes a bunch.
Using the library
World Matrix
The world struct holds the entire ECS state. It's constructed with create_world or init_world, and takes a compile-time parameter type for the key. The key type is most likely going to be typeid, string, or an enum. The world is destroyed with 'destroy_world'.
import "ecs"
main :: proc() {
world: ecs.World(typeid)
ecs.init_world(&world)
defer ecs.destroy_world(world)
...
}
Using typeid
Using typeid as the world key is temping, but has a few notable disadvantages.
- Aliases do not have their own typeid, each component type must be distinct
- They are not stable between dynamic libraries or hot-reloads
If you are ok with those downsides, then using typeid gives you access to a few convience functions that make the API more simple.
// Without typeid as key
for entity in ecs.query(&world, &iterator, key1, key2, key3) {
comp1: ^int
comp2: ^string
comp3: ^Struct_Type
ecs.entity_component(&world, entity, key1, comp1)
ecs.entity_component(&world, entity, key2, comp2)
ecs.entity_component(&world, entity, key3, comp3)
...
}
// With typeid as key
comp1: ^int
comp2: ^string
comp3: ^Struct_Type
for entity in ecs.query(&world, &iterator, comp1, comp2, comp3) {
...
}
Acknowledgements
I copied and modified the bit_array module from the odin core library. Most of it is not my code. As of when it was copied, the module was developed by github users Jeroen van Rijn, ap29600, Piotr Zalewski, and jon lipstate. Thanks a ton!