Skip to content

Add ComponentId-taking functions to Entity{Ref,Mut}Except to mirror FilteredEntity{Ref,Mut} #17800

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

Merged
merged 2 commits into from
Feb 12, 2025

Conversation

anlumo
Copy link
Contributor

@anlumo anlumo commented Feb 11, 2025

Objective

Related to #17784. The ticket is actually about just getting rid of Entity{Ref,Mut}Except in favor of FilteredEntity{Ref,Mut}, but I got told the unification of Entity types is a bigger endeavor that has been going on for a while now (as the "Pointing Fingers" working group) and I should just add the functions I actually need in the meantime.

Solution

This PR adds all of the functions necessary to access components by TypeId or ComponentId instead of static types.

Testing

Did you test these changes? If so, how?

Haven't tested it yet, but the changes are mostly copy/paste from other implementations in the same file, since there is a lot of duplicated functionality there.

Not a Migration Guide

There shouldn't be any breaking changes, it's just a few new functions on existing types.

@anlumo anlumo force-pushed the entityrefexcept-componentid branch from f49bfe3 to b7a9d9c Compare February 11, 2025 13:59
@anlumo anlumo force-pushed the entityrefexcept-componentid branch from b7a9d9c to 4d331dd Compare February 11, 2025 14:18
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 11, 2025
/// Unlike [`EntityRefExcept::get`], this returns a raw pointer to the component,
/// which is only valid while the [`EntityRefExcept`] is alive.
#[inline]
pub fn get_by_id(&self, component_id: ComponentId) -> Option<Ptr<'w>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could be generalized using DynamicComponentFetch to match the other get_by_id() methods. But that should happen anyway when these get merged by the "Pointing Fingers: Deduplicating Entity APIs with EntityPtr" working group, so this is fine for now!

@anlumo anlumo force-pushed the entityrefexcept-componentid branch from 7adeefe to 161ca26 Compare February 12, 2025 10:37
@anlumo
Copy link
Contributor Author

anlumo commented Feb 12, 2025

@chescock I reverted the unsound lifetime change by an amend commit, apparently that removes the entire conversation from GitHub. Everything seems to be fine, so the issues I was having apparently were solved by some other change during development.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 12, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 12, 2025
Merged via the queue into bevyengine:main with commit 267a0d0 Feb 12, 2025
30 checks passed
alice-i-cecile pushed a commit to alice-i-cecile/bevy that referenced this pull request Feb 12, 2025
…ilteredEntity{Ref,Mut} (bevyengine#17800)

# Objective

Related to bevyengine#17784. The ticket is actually about just getting rid of
`Entity{Ref,Mut}Except` in favor of `FilteredEntity{Ref,Mut}`, but I got
told the unification of Entity types is a bigger endeavor that has been
going on for a while now (as the "Pointing Fingers" working group) and I
should just add the functions I actually need in the meantime.

## Solution

This PR adds all of the functions necessary to access components by
TypeId or ComponentId instead of static types.

## Testing

> Did you test these changes? If so, how?

Haven't tested it yet, but the changes are mostly copy/paste from other
implementations in the same file, since there is a lot of duplicated
functionality there.

## Not a Migration Guide

There shouldn't be any breaking changes, it's just a few new functions
on existing types.

I had to shuffle around the lifetimes in `From<&EntityMutExcept<'a, B>>
for EntityRefExcept<'a, B>` (originally it was `From<&'a
EntityMutExcept<'_, B>> for EntityRefExcept<'_, B>`) to make the borrow
checker happy, but I don't think that this should have an impact on user
code (correct me if I'm wrong).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants