13 releases (6 breaking)

0.7.6 Nov 18, 2024
0.7.5 Nov 18, 2024
0.6.5 Nov 16, 2024
0.5.5 Nov 8, 2024
0.1.2 Jan 8, 2024

#849 in Data structures

Download history 5/week @ 2024-09-22 248/week @ 2024-10-20 333/week @ 2024-10-27 164/week @ 2024-11-03 124/week @ 2024-11-10 333/week @ 2024-11-17 12/week @ 2024-11-24 1/week @ 2024-12-01 19/week @ 2024-12-08

428 downloads per month

Custom license

30KB
787 lines

Retaker

Retaker is an ECS(very wip) that aims for simplicity and just enough performance to use ECS.

Example :

use retaker::{entity::DefaultEntityIdGenerator, system::Scheduler, world::World};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum SystemGroups {
    SomeSystemGroup,
}

pub struct State {
    world: World,
    generator: DefaultEntityIdGenerator,
}

pub struct MyComponent(String);
pub struct Exclude;

fn system(state: &mut State) {
    let entity1 = state.generator.generate();
    state.world.insert_component(&entity1, MyComponent(String::from("hi!!!")));

    let entity2 = state.generator.generate();
    state.world.insert_component(&entity2, MyComponent(String::from("bye!!!")));

    let entity3 = state.generator.generate();
    state.world.insert_component2(
        &entity3,
        (MyComponent(String::from("excluded!!!")), Exclude),
    );

    {
        let mut query = state.world.query::<MyComponent>();
        query.filter_without::<Exclude>(&state.world);
        for entity in query {
            let mut string = state.world.mut_component::<MyComponent>(&entity).unwrap();

            string.0 = string.0.to_uppercase();

            println!("{}", string.0);
        }
    }
}

fn main() {
    let mut state = State {
        world: World::new().into(),
        generator: DefaultEntityIdGenerator::new().into(),
    };
    let mut scheduler: Scheduler<SystemGroups, State> = Scheduler::new();

    scheduler.add_system(system, SystemGroups::SomeSystemGroup);

    scheduler.run_group(&mut state, SystemGroups::SomeSystemGroup);
}

Dependencies

~2.2–7MB
~51K SLoC