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

Deferred mutation queries #57

Closed
wants to merge 9 commits into from

Conversation

MiniaczQ
Copy link

@MiniaczQ MiniaczQ commented Jun 12, 2022

RENDERED
Queries that defer mutation of certain components.

@infmagic2047
Copy link

"Defer mutation for better parallelism" is basically the purpose of Command. Can we unify the implementation and/or API with that?

@Nilirad
Copy link

Nilirad commented Jun 12, 2022

I'm worried that the DeferMut can be easily confused with DerefMut.

@MiniaczQ
Copy link
Author

I'm worried that the DeferMut can be easily confused with DerefMut.

Yeah, we can bikeshed a better name if we decide to keep the mechanic.

"Defer mutation for better parallelism" is basically the purpose of Command. Can we unify the implementation and/or API with that?

Didn't consider Command, but yes, it seems to do exactly what is needed, assuming the mutations are batched together.
In fact, I think this piece of code would do exactly that:

fn foo(
  mut commands: Commands,
  bars: Query<(Entity, Cow<Bar>)>,
) {
  for (entity, bar) in vars.iter() {
    bar.0 = 0.0; // Copy happens
    commands.entity(entity).insert(bar.to_owned()); // We (re)insert the component
  }
}

2 problems with that would be:

  • bit boilerplate-y, you need to add commands as argument
  • order of mutation, with the original idea we'd keep the order the same as system order,
    but if it's commands and few of those get batched, what would the order of application be?

@MiniaczQ
Copy link
Author

Although bit non-obvious, using Commands seems like the way to go here.
I'm closing the request

@MiniaczQ MiniaczQ closed this Dec 12, 2023
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.

3 participants