jazzay / flecs-rs

Rust bindings for the Flecs ECS library
MIT License
69 stars 9 forks source link

No term_dynamic in SystemBuilder #6

Closed MalekiRe closed 2 years ago

MalekiRe commented 2 years ago

Second most recent commit removed the term_dynamic from the system builder.

Alexandre-P-J commented 2 years ago

I got stuck with this same issue. I recommend you to look into this example: https://github.com/jazzay/flecs-rs/blob/acb55ef4953792f09a16053ee991f1f4917f9fae/examples/systems.rs#L83

Here you have a working example using a runtime component and a runtime system:

use std::alloc::Layout;
use flecs::*;

fn system_with_iter(it: &Iter) {
    println!("system_with_iter: entities = {}", it.count());
}

fn main() {
    let mut world = World::new();
    let layout = Layout::from_size_align(4, 4).expect("Error unwraping Layout");
    world.component_dynamic("runtime_component", layout);

    let _entity = world.entity().named("my entity").set_dynamic("runtime_component", &[0 as u8; 4]);

    let system = world.system_dynamic().named("system_with_iter").expr("runtime_component").iter(system_with_iter);
    system.run(0.420);
}
jazzay commented 2 years ago

Did you take a look at (https://github.com/jazzay/flecs-rs/blob/main/examples/dynamic_components.rs?). world.system_dynamic() is no longer a thing, you can add dynamic terms now on any system, and access them inside iter via field_dynamic().

jazzay commented 2 years ago

Probably I need to publish an update to crates. Will do soon.