# Objective Take advantage of the "impl Bundle for Component" changes in #2975 / add the follow up changes discussed there. ## Solution - Change `insert` and `remove` to accept a Bundle instead of a Component (for both Commands and World) - Deprecate `insert_bundle`, `remove_bundle`, and `remove_bundle_intersection` - Add `remove_intersection` --- ## Changelog - Change `insert` and `remove` now accept a Bundle instead of a Component (for both Commands and World) - `insert_bundle` and `remove_bundle` are deprecated ## Migration Guide Replace `insert_bundle` with `insert`: ```rust // Old (0.8) commands.spawn().insert_bundle(SomeBundle::default()); // New (0.9) commands.spawn().insert(SomeBundle::default()); ``` Replace `remove_bundle` with `remove`: ```rust // Old (0.8) commands.entity(some_entity).remove_bundle::<SomeBundle>(); // New (0.9) commands.entity(some_entity).remove::<SomeBundle>(); ``` Replace `remove_bundle_intersection` with `remove_intersection`: ```rust // Old (0.8) world.entity_mut(some_entity).remove_bundle_intersection::<SomeBundle>(); // New (0.9) world.entity_mut(some_entity).remove_intersection::<SomeBundle>(); ``` Consider consolidating as many operations as possible to improve ergonomics and cut down on archetype moves: ```rust // Old (0.8) commands.spawn() .insert_bundle(SomeBundle::default()) .insert(SomeComponent); // New (0.9) - Option 1 commands.spawn().insert(( SomeBundle::default(), SomeComponent, )) // New (0.9) - Option 2 commands.spawn_bundle(( SomeBundle::default(), SomeComponent, )) ``` ## Next Steps Consider changing `spawn` to accept a bundle and deprecate `spawn_bundle`.
48 lines
1.1 KiB
Rust
48 lines
1.1 KiB
Rust
use bevy_ecs::prelude::*;
|
|
use glam::*;
|
|
|
|
#[derive(Component, Copy, Clone)]
|
|
struct Transform(Mat4);
|
|
|
|
#[derive(Component, Copy, Clone)]
|
|
struct Position(Vec3);
|
|
|
|
#[derive(Component, Copy, Clone)]
|
|
struct Rotation(Vec3);
|
|
|
|
#[derive(Component, Copy, Clone)]
|
|
struct Velocity(Vec3);
|
|
|
|
pub struct Benchmark(World, Box<dyn System<In = (), Out = ()>>);
|
|
|
|
impl Benchmark {
|
|
pub fn new() -> Self {
|
|
let mut world = World::new();
|
|
|
|
// TODO: batch this
|
|
for _ in 0..10_000 {
|
|
world.spawn().insert((
|
|
Transform(Mat4::from_scale(Vec3::ONE)),
|
|
Position(Vec3::X),
|
|
Rotation(Vec3::X),
|
|
Velocity(Vec3::X),
|
|
));
|
|
}
|
|
|
|
fn query_system(mut query: Query<(&Velocity, &mut Position)>) {
|
|
for (velocity, mut position) in &mut query {
|
|
position.0 += velocity.0;
|
|
}
|
|
}
|
|
|
|
let mut system = IntoSystem::into_system(query_system);
|
|
system.initialize(&mut world);
|
|
system.update_archetype_component_access(&world);
|
|
Self(world, Box::new(system))
|
|
}
|
|
|
|
pub fn run(&mut self) {
|
|
self.1.run((), &mut self.0);
|
|
}
|
|
}
|