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

Cascade support on terms with variables #1276

Open
farnoy opened this issue Jul 17, 2024 · 1 comment
Open

Cascade support on terms with variables #1276

farnoy opened this issue Jul 17, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@farnoy
Copy link

farnoy commented Jul 17, 2024

Describe the bug
Cascade ordering doesn't seem to be working with a relationship pair

To Reproduce

use flecs_ecs::prelude::*;

#[derive(Component, Debug)]
struct MyData {
    data: u32,
}

fn main() {
    let mut world = World::new();
    let e1 = world.entity_named("e1").set(MyData { data: 1 });
    let e3 = world.entity_named("e3").set(MyData { data: 3 });
    let e2 = world.entity_named("e2").set(MyData { data: 2 }).child_of_id(e1);
    let e4 = world.entity_named("e4").set(MyData { data: 4 }).child_of_id(e3);
    e3.child_of_id(e2);
    // e1 -> e2 -> e3 -> e4

    let q = world
        .query::<()>()
        .with::<&MyData>()
        .with::<&flecs::ChildOf>()
        .set_second_name("$loc")
        .src()
        .cascade()
        .desc()
        .self_()
        .optional()
        .set_cached()
        .build();
    println!("{}", q.to_string());
    println!("{}", q.plan());
    q.each_iter(|e, index, ()| unsafe {
        println!("[{index}] = {} parent {}", e.entity(index).name(), e.get_var_by_name("loc").name());
    });
}

Actual output

[in] ecs_tests.MyData($this), [in] ?ChildOf($this|self|cascade|desc ChildOf,$loc)
 0. [-1,  1]  setids
 1. [ 0,  2]  cachepop
 2. [ 1,  4]  option
 3. [ 2,  4]   selfup     $[this]           (ChildOf, $loc)
 4. [ 2,  5]  end         $[this]           (ChildOf, $loc)
 5. [ 4,  6]  yield

[0] = e1 parent *
[0] = e2 parent e1
[0] = e4 parent e3
[0] = e3 parent e2

Seems like no sorting is done and it matches physical/insertion order.

Expected behavior
I expected to see a descending cascade with this output:

[0] = e4 parent e3
[0] = e3 parent e2
[0] = e2 parent e1
[0] = e1 parent *

Additional context
I want to pull more than one component out of the traversal target. Cascade queries require caching, which only supports a single cascade traversal. Is this not a good alternative? I wanted to do ?OtherData($loc), ?SomethingElse($loc) once I got this working

@farnoy farnoy added the bug Something isn't working label Jul 17, 2024
@SanderMertens SanderMertens added enhancement New feature or request and removed bug Something isn't working labels Dec 18, 2024
@SanderMertens
Copy link
Owner

This requires being able to cache terms that have variables, which is something I hope to look into soon.

I wanted to do ?OtherData($loc), ?SomethingElse($loc) once I got this working

That should work!

@SanderMertens SanderMertens changed the title Cascade support on relationships Cascade support on terms with variables Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants