-
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
Change tracking #174
Comments
There have been a couple experiments, at #83 and #92. Both are just syntax sugar for stuff you can already do. As far as I'm aware, an external implementation does not sacrifice any performance. Depending on application you'll want to choose between |
I have ported Bevy mutation tracking to current hecs Unfortunately this changes public API. for (id, (number, &flag)) in world.query_mut::<(&mut i32, &bool)>() { becomes for (id, (mut number, &flag)) in world.query_mut::<(&mut i32, &bool)>() { |
I'm not interested in unconditional blanket mutation tracking, as I don't believe most applications, let alone most components, require it. #92-style explicit tracking fortunately doesn't change the behavior of existing queries. |
Would you consider such change hidden behind feature flag? |
More features, especially ones that are deeply intertwined with the core, can significantly complicate maintenance, so I'd prefer to find an alternative solution.
Could you address this by making the inner type private to a module, and only exporting a tracked interface to it? Providing strong static guarantees might require exposing some of the currently-internal query extension interfaces, but I think you could achieve a first approximation of this based on the draft PR today with |
I'm trying to implement my change tracking as a wrapper around hecs types. The basic idea is to have a I have successfully implemented a trait that converts tuples like Is there any example of a query wrapper? I will be grateful for any help.
|
Here is my attempt at making trackable queries. It can only detect if some component is changed and intended to be used in the system scheduler. And yes, it is much slower then original queries. Here is an example: use core::any::{type_name, TypeId};
use hecs::World;
use hecs_query_tracker::{Changes, TrackableQuery};
fn main() {
let mut world = World::default();
world.spawn((1i32, 2u32));
let changes = Changes::new_for::<(&i32, &u32)>();
<(&mut i32, &mut u32)>::track(&changes)
.query(&world)
.iter()
.for_each(|(_, (mut a, b))| *a = *b as i32);
for (type_id, type_name) in [
(TypeId::of::<i32>(), type_name::<i32>()),
(TypeId::of::<u32>(), type_name::<u32>()),
] {
if changes.is_changed(type_id) {
println!("{} is changed", type_name);
} else {
println!("{} is not changed", type_name);
}
}
} |
A non-invasive equality-based helper for change tracking was added in #366. |
The upstreaming Bevy changes issue (#71) mentioned among othert things change detection.
That issue was closed with Bevy ECS and Hecs diverging due to serving different needs.
However, change tracking seems like a useful feature to have as part of the core ECS. Especially if having an ability to query changed components could be implemented in the ECS with better time complexity than just querying all components and checking for some changed boolean.
What is the current status of this? Are there any plans to include change detection in Hecs?
The text was updated successfully, but these errors were encountered: