Skip to content

Tweak many gizmos stress test #8309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions examples/stress_tests/many_gizmos.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp::max;
use std::f32::consts::TAU;

use bevy::{
Expand Down Expand Up @@ -30,8 +31,12 @@ fn main() {
.add_systems(Startup, setup)
.add_systems(Update, (input, ui_system));

for _ in 0..SYSTEM_COUNT {
app.add_systems(Update, system);
let make_system = |index: u32| {
move |config: Res<Config>, time: Res<Time>, draw: Gizmos| system(index, config, time, draw)
};

for index in 0..SYSTEM_COUNT {
app.add_systems(Update, make_system(index));
}

app.run();
Expand All @@ -45,30 +50,43 @@ struct Config {

fn input(mut config: ResMut<Config>, input: Res<Input<KeyCode>>) {
if input.just_pressed(KeyCode::Up) {
config.line_count += 10_000;
config.line_count = max((config.line_count as f32 * 1.2).ceil() as u32, 1);
}
if input.just_pressed(KeyCode::Down) {
config.line_count = config.line_count.saturating_sub(10_000);
config.line_count = (config.line_count as f32 / 1.2).floor() as u32;
}
if input.just_pressed(KeyCode::Space) {
config.fancy = !config.fancy;
}
}

fn system(config: Res<Config>, time: Res<Time>, mut draw: Gizmos) {
if !config.fancy {
for _ in 0..(config.line_count / SYSTEM_COUNT) {
draw.line(Vec3::NEG_Y, Vec3::Y, Color::BLACK);
}
fn system(index: u32, config: Res<Config>, time: Res<Time>, mut draw: Gizmos) {
let mut rand_state = if !config.fancy {
index as i32
} else {
for i in 0..(config.line_count / SYSTEM_COUNT) {
let angle = i as f32 / (config.line_count / SYSTEM_COUNT) as f32 * TAU;
(time.elapsed_seconds() as i32 as f32 * (index + 1) as f32) as i32
};

let mut rand = || -> f32 {
rand_state = rand_state.wrapping_mul(1103515245).wrapping_add(12345) & 0x7fffffff;
(rand_state as f32 / 0x3fffffff as f32) - 1.
};

let line_count =
config.line_count / SYSTEM_COUNT + (index < config.line_count % SYSTEM_COUNT) as u32;

for i in 0..line_count {
let start = Vec3::new(rand(), rand(), rand());
let end = Vec3::new(rand(), rand(), rand());

if !config.fancy {
draw.line(start, end, Color::WHITE);
} else {
let angle = (i * SYSTEM_COUNT + index) as f32 / config.line_count as f32 * TAU;
let vector = Vec2::from(angle.sin_cos()).extend(time.elapsed_seconds().sin());
let start_color = Color::rgb(vector.x, vector.z, 0.5);
let end_color = Color::rgb(-vector.z, -vector.y, 0.5);

draw.line_gradient(vector, -vector, start_color, end_color);
draw.line_gradient(start, end, start_color, end_color);
}
}
}
Expand All @@ -77,7 +95,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
warn!(include_str!("warning_string.txt"));

commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(3., 1., 5.).looking_at(Vec3::ZERO, Vec3::Y),
transform: Transform::from_xyz(3., 2., 4.).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});

Expand Down