-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 by Bors] - Make most Entity
methods const
#5688
Conversation
Update the methods on the `Entity` struct to be `const`, so we can define compile-time constants and more generally use them in a const context. Fixes bevyengine#5687
In principle, I agree with this change, the more code that can be executed at compile time, the better. In practice, I don't see a (current) benefit for these fn's to be const already, as Entity is an unstable runtime identifier. |
I want to make an invalid
You can argue that this will break when the 4th billionth entity reaches its 4th billionth generation; I'm willing to take that risk as a limitation of my batching algorithm. I'm also willing to bet other stuffs will break before anyone reaches that limit. So I appreciate defining an invalid |
I think a better alternative would be defining an invalid entity (with eg index 0) in bevy as const and making sure that it doesn't get allocated, which I think is possible by "allocating" it with EntityMeta::EMPTY. |
This requires the current PR though, doesn't it? 😬 |
No, you can have |
I like @bjorn3's suggestion. Letting users define custom const entities feels like a foot gun. |
Sure, but that's a much larger and more complex change, even maybe due for an RFC if now all systems need to account for this. We could use ideally some |
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.
I guess in fairness we do already support creating these identifiers from their "pieces" at runtime (which is also generally a foot gun for the same reasons).
Supporting specific entities at compile time isn't particularly different, and I do like the idea of not needing Options or unsafe for scenarios like this, despite there being user-facing risk.
Short term, I'm cool with merging this. But long term, we should consider closing up these apis entirely (while still supporting the scenarios we need to support). I do like the idea of Entity:INVALID. Seems worth exploring, but I do agree thats a big-ish change.
bors r+ |
Pull request successfully merged into main. Build succeeded: |
Entity
methods const
Entity
methods const
# Objective Fixes bevyengine#5687 ## Solution Update the methods on the `Entity` struct to be `const`, so we can define compile-time constants and more generally use them in a const context. --- ## Changelog ### Added - Most `Entity` methods are now `const fn`.
# Objective Fixes bevyengine#5687 ## Solution Update the methods on the `Entity` struct to be `const`, so we can define compile-time constants and more generally use them in a const context. --- ## Changelog ### Added - Most `Entity` methods are now `const fn`.
# Objective Fix bevyengine#6548. Most of these methods were already made `const` in bevyengine#5688. `Entity::to_bits` is the only one that remained. ## Solution Make it const.
Objective
Fixes #5687
Solution
Update the methods on the
Entity
struct to beconst
, so we candefine compile-time constants and more generally use them in a const
context.
Changelog
Added
Entity
methods are nowconst fn
.