Skip to content

Cleanup entity reference types #17149

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 3 commits into from
Jan 6, 2025

Conversation

ItsDoot
Copy link
Contributor

@ItsDoot ItsDoot commented Jan 5, 2025

Objective

Cleanup EntityRef, EntityMut, and EntityWorldMut in preparation for my "Scoped Entity References" PR.

Solution

  • Switched EntityRef/EntityMut from tuple structs to normal ones.
  • Ensured all conversion trait impls use the same entity argument name.
  • Replaced some unsafe with delegated calls from EntityMut to EntityRef
    • Added EntityMut::into_readonly to make the replacements clearer
  • Replaced some unsafe with delegated calls from EntityWorldMut to EntityMut and EntityRef
    • Added EntityWorldMut::into_readonly, ::as_readonly, ::into_mutable, ::as_mutable to make the replacements clearer

Testing

Reusing current tests.

@ItsDoot ItsDoot added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Jan 5, 2025
@ItsDoot ItsDoot force-pushed the entity-ref-cleanup branch from 1cc3ff7 to 43a6868 Compare January 5, 2025 00:34
@ItsDoot ItsDoot force-pushed the entity-ref-cleanup branch from 43a6868 to 5e7faa3 Compare January 5, 2025 00:39
@ItsDoot ItsDoot added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Jan 5, 2025
EntityRef::from(self)
}

/// Consumes `self` and returns non-structural mutable access to all of the
Copy link
Contributor

Choose a reason for hiding this comment

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

What does "non-structural" mean in this context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Structural access (&mut World access) means you can insert/remove components, or despawn the entity. Non-structural access allows none of that; instead you have sliced access to the world which means you aren't allowed to perform changes that might affect other entities.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks for the clarification!

@TimJentzsch TimJentzsch added the D-Unsafe Touches with unsafe code in some way label Jan 5, 2025
Copy link
Contributor

@chescock chescock left a comment

Choose a reason for hiding this comment

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

This looks nice! This would all be good cleanup even if it weren't necessary for the EntityPtr work. I especially like the reduction of unsafe by doing self.as_mutable().thing() and self.as_readonly().thing().

@hymm hymm self-requested a review January 5, 2025 01:45
@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Jan 5, 2025
@alice-i-cecile alice-i-cecile added the X-Uncontroversial This work is generally agreed upon label Jan 5, 2025
@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 Jan 5, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 6, 2025
Merged via the queue into bevyengine:main with commit f64f3ac Jan 6, 2025
29 checks passed
mrchantey pushed a commit to mrchantey/bevy that referenced this pull request Feb 4, 2025
# Objective

Cleanup `EntityRef`, `EntityMut`, and `EntityWorldMut` in preparation
for my "Scoped Entity References" PR.

## Solution

- Switched `EntityRef`/`EntityMut` from tuple structs to normal ones.
- Ensured all conversion trait impls use the same `entity` argument
name.
- Replaced some `unsafe` with delegated calls from `EntityMut` to
`EntityRef`
    - Added `EntityMut::into_readonly` to make the replacements clearer
- Replaced some `unsafe` with delegated calls from `EntityWorldMut` to
`EntityMut` and `EntityRef`
- Added `EntityWorldMut::into_readonly`, `::as_readonly`,
`::into_mutable`, `::as_mutable` to make the replacements clearer

## Testing

Reusing current tests.
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-Code-Quality A section of code that is hard to understand or change D-Straightforward Simple bug fixes and API improvements, docs, test and examples D-Unsafe Touches with unsafe code in some way 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.

7 participants