-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 ComponentTicks::set_changed public #1711
Conversation
for public consumption, could we have another method that takes a |
It would also need to take the world for getting the current change tick, right? I haven't been following the reliable change detection work much. |
|
My preferred API to expose for this would be a EDIT: At the same time, I think we should include a As a bit of context, @cart mentioned in #1471 that the requested functionality here might be needed, but to wait for a separate pr / use case. This seems like just that :) |
Adding to the 0.5 milestone: I'd like to avoid a regression in useful functionality, especially for such a critical ecosystem plugin. |
My concern with exposing the API directly as done in the first commit is that it's very, very coupled to the implementation details. This makes it very liable to break, and forces a huge burden of knowledge on the end user to use correctly. |
I'm against
What cart suggested in #1471 is to have |
rather than having a |
The issue as I understand it is that |
Hmm. I can imagine specialized use cases (e.g. specialized loading workflows) where we set these as false, but they would be both obscure and dangerous. Probably better to avoid encouraging it.
I can accept this, provided the doc strings are clear that it's probably not what you want to be using and we eventually create commands to set entities as added / changed in a user-friendly way. |
285658c
to
0d5ee87
Compare
I added a doc comment explaining how this is usually done automatically. |
crates/bevy_ecs/src/component/mod.rs
Outdated
/// let world: World = todo!(); | ||
/// let component_ticks: ComponentTicks = todo!(); |
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.
Do you intend to fill this in this PR?
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 just wanted the variables in scope, but I agree that todo!()
doesn't really fit. Do you think changing it to unimplemented!()
would be fine or would you like a larger example with proper values?
Its hard to come up with a simple example as this is the code I used (copied from bevy):
#[inline]
unsafe fn get_component_and_ticks(
world: &World,
component_id: ComponentId,
entity: Entity,
location: EntityLocation,
) -> Option<(*mut u8, *mut ComponentTicks)> {
let archetype = &world.archetypes()[location.archetype_id];
let component_info = world.components().get_info_unchecked(component_id);
match component_info.storage_type() {
StorageType::Table => {
let table = &world.storages().tables[archetype.table_id()];
let components = table.get_column(component_id)?;
let table_row = archetype.entity_table_row(location.index);
// SAFE: archetypes only store valid table_rows and the stored component type is T
Some((
components.get_unchecked(table_row),
components.get_ticks_unchecked(table_row),
))
}
StorageType::SparseSet => world
.storages()
.sparse_sets
.get(component_id)
.and_then(|sparse_set| sparse_set.get_with_ticks(entity)),
}
}
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.
Yeah lets just change these to unimplemented().
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.
Done
I'm cool with just making this public. ComponentTicks is "just" a holder of the last changed ticks. Adding a |
bors r+ |
Pull request successfully merged into main. Build succeeded: |
fixes #1710