feature: UniqueIndex support
TotalKrill opened this issue · comments
Basically, its sometimes very useful to use another unique name that is not the entityname to refer to an entity, be it a serialnumber, or maybe just a name of a character. Its Very helpful for syncing stuff across networks etc.
it would basically be very similar to the index already there, but in your example, it would be quite reversed. I am imagining an UX similar to this.
fn update_players(
update_packet: ListOfUpdate, // would probably be in an event or smth idk
mut transforms: Query<&mut Transform, UniqueIndex<Id>>,
) {
for update in &update_packet {
transforms.get_unique(update.id).unwrap().move_player(update.transform);
}
}
From your example, it sounds like you're asking for two things here:
- You want an index that returns a single entity instead of a hash set, since you know your components are unique.
- You want to be able to look up the id and get the components in a single step instead of asking the index for the Entity and passing that to a Query.
Is that accurate?
That is indeed accurate. This would also be more performant than looping both query and the list of items to update. Generally I do this today by having some systems update a resource (intmap or btreemap usually), which keeps the component value as the key, and the entity as the value.
then I go the way of
let entity = resource.get(id);
components.get(entity);
in each system that works this way, I usually go with "nohash_hasher" IntMaps, or BTreeMaps as the depending on the nature of the unique id, or if i need them sorted sometimes since BTreeMap is ordered.
It seems this crate is trying to make things like this more ergonomic, so i thought maybe this would be a good crate for this.