foxes shouldn't march in sync (#10070)
# Objective - All foxes in `many_foxes` are running in sync - It's scary - It can also be a source of optimisation that won't be useful in a general case ## Solution - Advance the animation of each fox so that they are not synced anymore by default - Add a cli arg to enable them running in sync
This commit is contained in:
parent
e5f5ce5e97
commit
a52ca170ac
@ -4,6 +4,7 @@
|
|||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use argh::FromArgs;
|
||||||
use bevy::{
|
use bevy::{
|
||||||
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
||||||
pbr::CascadeShadowConfigBuilder,
|
pbr::CascadeShadowConfigBuilder,
|
||||||
@ -11,14 +12,29 @@ use bevy::{
|
|||||||
window::{PresentMode, WindowPlugin},
|
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)]
|
#[derive(Resource)]
|
||||||
struct Foxes {
|
struct Foxes {
|
||||||
count: usize,
|
count: usize,
|
||||||
speed: f32,
|
speed: f32,
|
||||||
moving: bool,
|
moving: bool,
|
||||||
|
sync: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let args: Args = argh::from_env();
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins((
|
.add_plugins((
|
||||||
DefaultPlugins.set(WindowPlugin {
|
DefaultPlugins.set(WindowPlugin {
|
||||||
@ -33,11 +49,10 @@ fn main() {
|
|||||||
LogDiagnosticsPlugin::default(),
|
LogDiagnosticsPlugin::default(),
|
||||||
))
|
))
|
||||||
.insert_resource(Foxes {
|
.insert_resource(Foxes {
|
||||||
count: std::env::args()
|
count: args.count,
|
||||||
.nth(1)
|
|
||||||
.map_or(1000, |s| s.parse::<usize>().unwrap()),
|
|
||||||
speed: 2.0,
|
speed: 2.0,
|
||||||
moving: true,
|
moving: true,
|
||||||
|
sync: args.sync,
|
||||||
})
|
})
|
||||||
.insert_resource(AmbientLight {
|
.insert_resource(AmbientLight {
|
||||||
color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
@ -200,12 +215,15 @@ fn setup(
|
|||||||
fn setup_scene_once_loaded(
|
fn setup_scene_once_loaded(
|
||||||
animations: Res<Animations>,
|
animations: Res<Animations>,
|
||||||
foxes: Res<Foxes>,
|
foxes: Res<Foxes>,
|
||||||
mut player: Query<&mut AnimationPlayer>,
|
mut player: Query<(Entity, &mut AnimationPlayer)>,
|
||||||
mut done: Local<bool>,
|
mut done: Local<bool>,
|
||||||
) {
|
) {
|
||||||
if !*done && player.iter().len() == foxes.count {
|
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();
|
player.play(animations.0[0].clone_weak()).repeat();
|
||||||
|
if !foxes.sync {
|
||||||
|
player.seek_to(entity.index() as f32 / 10.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*done = true;
|
*done = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user