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

[Merged by Bors] - Use updated window size in bevymark example #3335

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
22 changes: 12 additions & 10 deletions examples/tools/bevymark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct BirdTexture(Handle<Image>);

fn setup(
mut commands: Commands,
window: Res<WindowDescriptor>,
windows: Res<Windows>,
mut counter: ResMut<BevyCounter>,
asset_server: Res<AssetServer>,
) {
Expand All @@ -61,7 +61,7 @@ fn setup(
{
spawn_birds(
&mut commands,
&window,
&windows,
&mut counter,
initial_count,
texture.clone_weak(),
Expand Down Expand Up @@ -126,7 +126,7 @@ fn mouse_handler(
mut commands: Commands,
time: Res<Time>,
mouse_button_input: Res<Input<MouseButton>>,
window: Res<WindowDescriptor>,
windows: Res<Windows>,
bird_texture: Res<BirdTexture>,
mut counter: ResMut<BevyCounter>,
) {
Expand All @@ -138,7 +138,7 @@ fn mouse_handler(
let spawn_count = (BIRDS_PER_SECOND as f64 * time.delta_seconds_f64()) as u128;
spawn_birds(
&mut commands,
&window,
&windows,
&mut counter,
spawn_count,
bird_texture.0.clone(),
Expand All @@ -148,13 +148,14 @@ fn mouse_handler(

fn spawn_birds(
commands: &mut Commands,
window: &WindowDescriptor,
windows: &Windows,
counter: &mut BevyCounter,
spawn_count: u128,
texture: Handle<Image>,
) {
let bird_x = (window.width / -2.) + HALF_BIRD_SIZE;
let bird_y = (window.height / 2.) - HALF_BIRD_SIZE;
let window = windows.get_primary().unwrap();
let bird_x = (window.physical_width() as f32 / -2.) + HALF_BIRD_SIZE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this physical width?

That makes the behaviour with a non-1 scale factor is to spawn the birds off-screen, and let them bounce off-screen. That doesn't seem ideal for a benchmark, as it might make the performance seem better (as off-screen sprites are planned to be culled). I think bevymark is meant to be a stress-test for sprite rendering, not culling behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my bad, it shouldn't use the physical size, I will fix it.

I agree with your concern for the usefulness of resizing, though the main issue I had here was the use of WindowDescriptor since it gave the wrong impression (to me at least) that WindowDescriptor would be updated.

let bird_y = (window.physical_height() as f32 / 2.) - HALF_BIRD_SIZE;
for count in 0..spawn_count {
let bird_z = (counter.count + count) as f32 * 0.00001;
commands
Expand Down Expand Up @@ -190,9 +191,10 @@ fn movement_system(time: Res<Time>, mut bird_query: Query<(&mut Bird, &mut Trans
}
}

fn collision_system(window: Res<WindowDescriptor>, mut bird_query: Query<(&mut Bird, &Transform)>) {
let half_width = window.width as f32 * 0.5;
let half_height = window.height as f32 * 0.5;
fn collision_system(windows: Res<Windows>, mut bird_query: Query<(&mut Bird, &Transform)>) {
let window = windows.get_primary().unwrap();
let half_width = window.physical_width() as f32 * 0.5;
let half_height = window.physical_height() as f32 * 0.5;

for (mut bird, transform) in bird_query.iter_mut() {
let x_vel = bird.velocity.x;
Expand Down