Another Entity-Component-System, written in Rust.
Usage
Add the following to the Cargo.toml in your project:
[dependencies]
tinyecs = "*"
and import using:
extern crate tinyecs;
use tinyecs::*;
System is behaviour working with components.
rust
struct Position {
x : i32,
y : i32,
z : i32
}
impl Component for Position {}
Entities:
```rust let mut entitymanager = world.entitymanager(); let entity = entitymanager.createentity();
entity.addcomponent(Position {x : 0, y : 0, z : 0}); entity.addcomponent(Velocity {x : 1}); entity.refresh(); ```
Systems:
rust
process_entities!((MoveSystem): |pos: Position, vel: Velocity| => {
pos.x += vel.x;
println!("Moving! position: {}, velocity: {}", pos.x, vel.x);
});
Or without macroses: ```rust pub struct MoverSystem; impl System for MoverSystem { fn aspect(&self) -> Aspect { aspect_all![Position, Velocity] }
fn process_one(&mut self, entity : &mut Entity) {
let mut pos = entity.get_component::<Position>();
let vel = entity.get_component::<Velocity>(); // no problems with multiple mutable components
pos.pos.x += vel.x;
}
} ```
More features, described only in /examples atm: - Aspects - Entity creation from system's process - Data aspects - for additional kind of entities in process - Different process styles