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

Added/Changed detection #30

Closed
wants to merge 12 commits into from
Closed

Conversation

bzm3r
Copy link
Contributor

@bzm3r bzm3r commented Dec 10, 2022

ImplementsAdded/Changed functionality for bevy-trait-query!

Closes: #23

What is needed to for this to go out of draft status:

  • add more change detection tests

  • update documentation to show how change detection should be used

@bzm3r bzm3r force-pushed the added-changed branch 2 times, most recently from 87030ea to b7bad05 Compare December 10, 2022 22:31
@bzm3r bzm3r changed the title Added/Changed functionality Added/Changed detection Dec 26, 2022
@bzm3r bzm3r marked this pull request as ready for review December 26, 2022 23:30
Copy link
Owner

@JoJoJet JoJoJet left a comment

Choose a reason for hiding this comment

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

Looks very solid on my initial scan-throughs. Sorry for taking a while to get to it :).

let (column, meta) = unsafe { zip_exact(&mut self.components, &mut self.meta) }
.find_map(|(&component, meta)| self.table.get_column(component).zip(Some(meta)))?;

// SAFETY: we know that the table row is a valid index???
Copy link
Owner

Choose a reason for hiding this comment

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

To be more explicit about this invariant, it would be good to add a safety comment to the self.table_row field. Something like // SAFETY: must correspond to a valid row in `self.table` .

.byte_add(self.table_row * meta.size_bytes);
meta.dyn_ctor.cast(ptr)
})
.or_else(|| self.next())
Copy link
Owner

Choose a reason for hiding this comment

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

We should use loops instead of recursion here, though this PR is already really big so we can leave this change for a followup if you prefer.

Comment on lines +141 to +144
// SAFETY ISSUE! SAFETY ISSUE! SAFETY ISSUE! Unlike in the write case, we do not have
// exclusive access! We have shared access to the entire column and ticks? This might be
// okay though because there cannot be any other accesses with write access at the same
// time?
Copy link
Owner

Choose a reason for hiding this comment

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

This is correct. AddedReadTraits registers read-access, so the scheduler prevents write-access from occurring. Same deal in the other places you have this comment.

Comment on lines +84 to +86
/// [`WorldQuery`] adapter that fetches entities with exactly one component implementing a trait,
/// with the condition that the component was newly added since the last tick
pub struct AddedOne<T>(pub T);
Copy link
Owner

Choose a reason for hiding this comment

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

Just making sure, this essentially a shorthand for Query<One<&dyn Trait>, AddedOneFilter<dyn Trait>>, right?

@alice-i-cecile
Copy link

@bzm3r @JoJoJet would you like me to adopt this? <3

@JoJoJet
Copy link
Owner

JoJoJet commented Feb 1, 2023

I am okay with that :)

@Shatur
Copy link

Shatur commented May 7, 2023

@alice-i-cecile are you still planning to tackle this?

@alice-i-cecile
Copy link

No: I'm not currently using bevy-trait-query in any of my projects.

@Shatur
Copy link

Shatur commented May 7, 2023

Thanks for letting me know. Then I will try to adopt this.

@Shatur
Copy link

Shatur commented May 7, 2023

A lot of things changed in Bevy related to change detection:
bevyengine/bevy#6547
bevyengine/bevy#6681
bevyengine/bevy#7905
Not sure how to properly update some places of this PR. @JoJoJet Maybe you can take a look since you the author of the last one? :)

@bzm3r
Copy link
Contributor Author

bzm3r commented Jun 28, 2023

This was rebased later on, and the comments here will be addressed through review there: #42

@bzm3r bzm3r closed this Jun 28, 2023
@bzm3r bzm3r deleted the added-changed branch June 28, 2023 02:19
JoJoJet added a commit that referenced this pull request Sep 8, 2023
Rebase of #30.
Resolves #23.

Adds support for trait queries that filter based on change detection.

Co-authored-by: Brian Merchant <bhmerchant@gmail.com>
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.

Add support for change detection filters Changed<>, Added<>, etc
4 participants