-
Notifications
You must be signed in to change notification settings - Fork 84
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
add dynamic query support from feather-hecs #196
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks like a good start on #69! There are, however, some soundness issues as-is, and I think we'll want to iterate on the API a bit.
/// | ||
/// # Panics | ||
/// Panics if `T` is not the type of the components in this slice. | ||
pub fn as_slice<T: 'static>(&self) -> &[T] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unsound because &[T]
may outlive the query (and indeed the entire World
). ComponentSlice
should have a lifetime parameter bounded by the lifetime of the query, which should be propagated to this return value.
pub fn iter_component_slices<'a>( | ||
&'a self, | ||
component_type: TypeId, | ||
) -> impl Iterator<Item = ComponentSlice> + 'a { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unsound because no dynamic borrow-checking is performed, and the use of &self
here and in World::query_dynamic
allows for other outstanding (potentially mutable) borrows. Either something analogous to Fetch::borrow
is needed to perform dynamic borrow-checking, or a lot of stuff should be switched to &mut self
to statically prevent a dynamic query from coexisting with any other component borrow.
component_layout: Layout, | ||
} | ||
|
||
impl ComponentSlice { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a safe way to get mutable access to the write_types
of the query.
Thanks for the feedback @Ralith! Will dig into it soon. |
This brings over the dynamic query changes from a hard fork of hecs:
https://github.com/feather-rs/feather-hecs
This allows us to build and query components dynamically at runtime.