Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proof of concept] derive specs system #499

Closed
wants to merge 2 commits into from

Conversation

azriel91
Copy link
Member

@azriel91 azriel91 commented Oct 24, 2018

Relates to the RFC in issue #498. This allows you to do this:

#[specs_system(SysA)]
fn sys_a(mut pos: WriteStorage<Pos>, vel: ReadStorage<Vel>) {
    for (pos, vel) in (&mut pos, &vel).join() {
        pos.0 += vel.0;
    }
}

#[specs_system(SysPrint)]
fn sys_print(entities: Entities, pos: ReadStorage<Pos>, vel: ReadStorage<Vel>) {
    for (e, pos, vel) in (&entities, &pos, &vel).join() {
        println!("{:?}: Pos: {:?}   Vel: {:?}", e, pos, vel);
    }
}

// ...
let mut dispatcher = DispatcherBuilder::new()
    .with(SysA, "sys_a", &[])
    .with(SysPrint, "sys_print", &["sys_a"])
    .build();

and running this gives:

$ cargo run --example system_derive_with_components
    Finished dev [unoptimized + debuginfo] target(s) in 0.36s
     Running `target\debug\examples\system_derive_with_components.exe`
Entity(0, Generation(1)): Pos: Pos(2.0)   Vel: Vel(2.0)
Entity(1, Generation(1)): Pos: Pos(5.6)   Vel: Vel(4.0)
Entity(2, Generation(1)): Pos: Pos(6.9)   Vel: Vel(1.5)
Entity(0, Generation(1)): Pos: Pos(4.0)   Vel: Vel(2.0)
Entity(1, Generation(1)): Pos: Pos(9.6)   Vel: Vel(4.0)
Entity(2, Generation(1)): Pos: Pos(8.4)   Vel: Vel(1.5)

This change is Reviewable

@azriel91
Copy link
Member Author

failed on stable, but I think it would work when 1.30 is out [1, 2, 3]. That means using this feature would bump the minimum rust version

Type::Path(TypePath {
path:
Path {
ref mut segments, ..
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Rust #beginners:

dyn r#CryZe:

ref is pseudo deprecated
use default match bindings instead
match &mut ty

ᚮscottmcmᚭ:

and +1 to

let segments = match &mut ty {
    Type::Path(TypePath {
        path: Path {
            segments, ..    // <-- no more silliness
        },

Copy link
Member

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to shred.

@torkleyy
Copy link
Member

torkleyy commented Jan 3, 2019

Closing since it's outside of Specs' scope and belongs to shred.

@torkleyy torkleyy closed this Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants