Usage
# Cargo.toml
[]
= "1.0"
// lib.rs
use *;
The world
To start, create a new World. This is the starting point of the ecs.
The program can have multiple independent worlds.
Components
Components are defined as follows:
Entities
To spawn a new entity with the given ids:
// spawn_entity macro accepts the world as the first parameter, and the
// components to add to the entity as the other parameters
let id = spawn_entity!;
Systems
There are two ways to define systems.
The first is using the system macro:
// immutable system
// mutable system
// query entity ids as well
/// prints all entities ids having the position component
To create a mutable system, the function should contain world: &mut World as its first argument,
for an immutable one, add world: &World.
The function can contain any number of arguments you can pass to it when calling.
The function can return any type of Result<(), Any>. If this function has the given result
return type, Ok(()) will be returned at the end of the system.
The second is using the query and query_mut macros:
Note on safety: the query_mut macro is unsafe, because it can cause undefined behaviour
if two of the same component types are passed in.
License
Licensed under the MIT license.