Skip to content

Instantly share code, notes, and snippets.

@tomara-x
Created March 18, 2024 21:29
Show Gist options
  • Save tomara-x/f6487d400d06e51dae012831e876a13b to your computer and use it in GitHub Desktop.
Save tomara-x/f6487d400d06e51dae012831e876a13b to your computer and use it in GitHub Desktop.
[package]
name = "smol"
version = "0.1.0"
edition = "2021"
[dependencies.bevy]
version = "0.13.0"
default-features = false
features = [
"multi-threaded",
"bevy_winit",
"x11",
]
[profile.release]
panic = 'abort'
strip = true
codegen-units = 1
lto = "thin"
//! spawn/despawn many entities
use bevy::prelude::*;
#[derive(Component)]
struct F(f32);
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, de_spawn)
.run();
}
fn de_spawn(
keyboard_input: Res<ButtonInput<KeyCode>>,
query: Query<Entity, With<F>>,
mut commands: Commands,
) {
if keyboard_input.just_pressed(KeyCode::KeyS) {
for _ in 0..1_000_000 {
commands.spawn(F(42.0));
}
}
if keyboard_input.just_pressed(KeyCode::KeyD) {
for e in query.iter() {
commands.entity(e).despawn();
}
}
if keyboard_input.just_pressed(KeyCode::KeyI) {
info!("{}", query.iter().len());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment