Skip to content
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

foxes shouldn't march in sync #10070

Merged
merged 3 commits into from Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 23 additions & 5 deletions examples/stress_tests/many_foxes.rs
Expand Up @@ -4,21 +4,37 @@
use std::f32::consts::PI;
use std::time::Duration;

use argh::FromArgs;
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
pbr::CascadeShadowConfigBuilder,
prelude::*,
window::{PresentMode, WindowPlugin},
};

#[derive(FromArgs, Resource)]
/// `many_foxes` stress test
struct Args {
/// wether all foxes run in sync.
#[argh(switch)]
sync: bool,

/// total number of foxes.
#[argh(option, default = "1000")]
count: usize,
}

#[derive(Resource)]
struct Foxes {
count: usize,
speed: f32,
moving: bool,
sync: bool,
}

fn main() {
let args: Args = argh::from_env();

App::new()
.add_plugins((
DefaultPlugins.set(WindowPlugin {
Expand All @@ -33,11 +49,10 @@ fn main() {
LogDiagnosticsPlugin::default(),
))
.insert_resource(Foxes {
count: std::env::args()
.nth(1)
.map_or(1000, |s| s.parse::<usize>().unwrap()),
count: args.count,
speed: 2.0,
moving: true,
sync: args.sync,
})
.insert_resource(AmbientLight {
color: Color::WHITE,
Expand Down Expand Up @@ -200,12 +215,15 @@ fn setup(
fn setup_scene_once_loaded(
animations: Res<Animations>,
foxes: Res<Foxes>,
mut player: Query<&mut AnimationPlayer>,
mut player: Query<(Entity, &mut AnimationPlayer)>,
mut done: Local<bool>,
) {
if !*done && player.iter().len() == foxes.count {
for mut player in &mut player {
for (entity, mut player) in &mut player {
player.play(animations.0[0].clone_weak()).repeat();
if !foxes.sync {
player.seek_to(entity.index() as f32 / 10.0);
}
}
*done = true;
}
Expand Down