Usage
# Cargo.toml
[]
= "1.3"
// 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:
Flags
Unit structs can't be used as Components, this is where you would have to use a flag. Flags are represented as an enum:
Entities
To spawn a new entity with the given components:
// spawn_entity macro accepts the world as the first parameter, and the
// components to add to the entity as the other parameters
let entity_id = spawn_entity!;
You can give an entity a flag using the set_flag method:
world.set_flag;
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:
Flags in queries
You can further filter queries using flags:
let query_result = query!
.filter;
Feature flags
try
The try feature of this crate enables returning early from a system.
To enable it:
# Cargo.toml
[]
= { = "*", = ["try"] }
Usage
Mark a system which returns a Result of ok type () with try:
Next to returning an Err, you can also use
return std::ops::ControlFlow::Continue(()) to skip the current entity
and continue to the next.
Contributing
Contributors are always welcome. If you find any bugs, feel free to open an issue. If you feel like it, PRs are also appreciated!
License
Licensed under the MIT license.