legion::world::World::get_component_mut_or_default() ?
Hi,
Would it be possible to have legion::world::World::get_component_mut_or_default() to be able to create or get, then modify a component while minimizing code and accesses ?
This would be to avoid code like:
if let Some(mut component) = self.world.get_component_mut(entity) {
return component;
}
self.world.add_component(entity, C::default());
self.world.get_component_mut(entity).unwrap()
(which doesn't even compile)
I am unsure if this is a good idea. Legion performs best when mutations to Layout are minimized. That means adding components has a significant cost and thus providing a convenience function to do an expensive operation needs to avoid a lot of code.
Also I believe that you should normally be deferring changes to components that are currently being looked at to avoid race conditions which means the idea of "get or add" doesn't make sense.