#gamedev #ecs #game-engine

xecs

A rust grouped Entity-Component-System library

12 releases

new 0.3.3 Oct 21, 2021
0.3.2 Oct 10, 2021
0.3.1 Sep 30, 2021
0.2.13 Sep 23, 2021
0.2.8 Aug 24, 2021

#100 in Game dev

Download history 50/week @ 2021-08-22 13/week @ 2021-08-29 39/week @ 2021-09-05 21/week @ 2021-09-12 33/week @ 2021-09-19 17/week @ 2021-09-26 26/week @ 2021-10-03 28/week @ 2021-10-10 30/week @ 2021-10-17

82 downloads per month

MIT license

105KB
2.5K SLoC

XECS

xecs is a rust Entity-Component-System library

Details

XECS is a Grouped ECS library.

Examples

Create an empty world

let mut world = World::new();

Register some components

Component is T : Send + Sync + 'static

struct Position(f64,f64,f64);
struct Particle;
world.register::<Position>();
world.register::<Particle>();

Create 100 entity with Position and Particle components

for _ in 0..100 {
    world
        .create_entity()
        .attach(Position(1.0,2.0,1.2))
        .attach(Particle);
}

Make a full-owning group to improve the performance of query iteration

world.make_group::<(Particle,Position)>(true,true);

Create a system and update all entities with position and particle components

struct UpdatePosition;
impl<'a> System<'a> for UpdatePosition {
    type InitResource = ();
    type Resource = (&'a mut World);
    type Dependencies = ();
    type Error = Infallible;


    fn update(&'a mut self, world : RefMut<'a,World>) -> Result<(),Self::Error> {
        for (pos,_tag) in world.query::<(&mut Position,&Particle)>() {
            pos.0 += 1.1;
            pos.1 += 1.2;
            pos.3 += 1.4;
        }
        Ok(())
    }
}

Add system to stage and run this stage

let mut stage = Stage::from_world(world);
stage.add_system(UpdatePosition);
stage.run();

No runtime deps