Created
March 18, 2024 21:29
-
-
Save tomara-x/f6487d400d06e51dae012831e876a13b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! 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