-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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] - Add an example to test small window sizes #3597
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
72ce798
Add an example to test small window sizes
DJMcNab d399b0e
Use constants instead
DJMcNab 5759c6a
Actually do some rendering for testing
DJMcNab 8b2982d
No longer test 0x0 windows as they are unsupported on X11
DJMcNab b878e10
Don't 'abuse' 0x0 windows for the example
DJMcNab 1a3b7f3
Also test 2d
DJMcNab 9de6300
Address review comments
DJMcNab 82da36b
Apply suggestions from code review
DJMcNab 290b973
Move to the tests directory
DJMcNab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
( | ||
exit_after: Some(90) | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
( | ||
// Ensures that the full cycle will run | ||
exit_after: Some(410) | ||
) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//! A test to confirm that `bevy` allows minimising the window | ||
//! This is run in CI to ensure that this doesn't regress again. | ||
use bevy::prelude::*; | ||
|
||
fn main() { | ||
// TODO: Combine this with `resizing` once multiple_windows is simpler than | ||
// it is currently. | ||
App::new() | ||
.insert_resource(WindowDescriptor { | ||
title: "Minimising".into(), | ||
..Default::default() | ||
}) | ||
.add_plugins(DefaultPlugins) | ||
.add_system(minimise_automatically) | ||
.add_startup_system(setup_3d) | ||
.add_startup_system(setup_2d) | ||
.run(); | ||
} | ||
|
||
fn minimise_automatically(mut windows: ResMut<Windows>, mut frames: Local<u32>) { | ||
if *frames == 60 { | ||
windows.get_primary_mut().unwrap().set_minimized(true); | ||
} else { | ||
*frames += 1; | ||
} | ||
} | ||
|
||
/// A simple 3d scene, taken from the `3d_scene` example | ||
fn setup_3d( | ||
mut commands: Commands, | ||
mut meshes: ResMut<Assets<Mesh>>, | ||
mut materials: ResMut<Assets<StandardMaterial>>, | ||
) { | ||
// plane | ||
commands.spawn_bundle(PbrBundle { | ||
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), | ||
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), | ||
..default() | ||
}); | ||
// cube | ||
commands.spawn_bundle(PbrBundle { | ||
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), | ||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), | ||
transform: Transform::from_xyz(0.0, 0.5, 0.0), | ||
..default() | ||
}); | ||
// light | ||
commands.spawn_bundle(PointLightBundle { | ||
point_light: PointLight { | ||
intensity: 1500.0, | ||
shadows_enabled: true, | ||
..default() | ||
}, | ||
transform: Transform::from_xyz(4.0, 8.0, 4.0), | ||
..default() | ||
}); | ||
// camera | ||
commands.spawn_bundle(PerspectiveCameraBundle { | ||
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), | ||
..default() | ||
}); | ||
} | ||
|
||
/// A simple 2d scene, taken from the `rect` example | ||
fn setup_2d(mut commands: Commands) { | ||
commands.spawn_bundle(OrthographicCameraBundle::new_2d()); | ||
commands.spawn_bundle(SpriteBundle { | ||
sprite: Sprite { | ||
color: Color::rgb(0.25, 0.25, 0.75), | ||
custom_size: Some(Vec2::new(50.0, 50.0)), | ||
..default() | ||
}, | ||
..default() | ||
}); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
//! A test to confirm that `bevy` allows setting the window to arbitrary small sizes | ||
//! This is run in CI to ensure that this doesn't regress again. | ||
|
||
use bevy::{input::system::exit_on_esc_system, prelude::*}; | ||
|
||
// The smallest size reached is 1x1, as X11 doesn't support windows with a 0 dimension | ||
// TODO: Add a check for platforms other than X11 for 0xk and kx0, despite those currently unsupported on CI. | ||
const MAX_WIDTH: u16 = 401; | ||
const MAX_HEIGHT: u16 = 401; | ||
const MIN_WIDTH: u16 = 1; | ||
const MIN_HEIGHT: u16 = 1; | ||
const RESIZE_STEP: u16 = 4; | ||
|
||
struct Dimensions { | ||
width: u16, | ||
height: u16, | ||
} | ||
|
||
fn main() { | ||
App::new() | ||
.insert_resource(WindowDescriptor { | ||
width: MAX_WIDTH.try_into().unwrap(), | ||
height: MAX_HEIGHT.try_into().unwrap(), | ||
scale_factor_override: Some(1.), | ||
title: "Resizing".into(), | ||
..Default::default() | ||
}) | ||
.insert_resource(Dimensions { | ||
width: MAX_WIDTH, | ||
height: MAX_HEIGHT, | ||
}) | ||
.add_plugins(DefaultPlugins) | ||
.insert_resource(Phase::ContractingY) | ||
.add_system(change_window_size) | ||
.add_system(sync_dimensions) | ||
.add_system(exit_on_esc_system) | ||
.add_startup_system(setup_3d) | ||
.add_startup_system(setup_2d) | ||
.run(); | ||
} | ||
|
||
enum Phase { | ||
ContractingY, | ||
ContractingX, | ||
ExpandingY, | ||
ExpandingX, | ||
} | ||
|
||
use Phase::*; | ||
|
||
fn change_window_size( | ||
mut windows: ResMut<Dimensions>, | ||
mut phase: ResMut<Phase>, | ||
mut first_complete: Local<bool>, | ||
) { | ||
// Put off rendering for one frame, as currently for a frame where | ||
// resizing happens, nothing is presented. | ||
// TODO: Debug and fix this if feasible | ||
if !*first_complete { | ||
*first_complete = true; | ||
return; | ||
} | ||
let height = windows.height; | ||
let width = windows.width; | ||
match *phase { | ||
Phase::ContractingY => { | ||
if height <= MIN_HEIGHT { | ||
*phase = ContractingX; | ||
} else { | ||
windows.height -= RESIZE_STEP; | ||
} | ||
} | ||
Phase::ContractingX => { | ||
if width <= MIN_WIDTH { | ||
*phase = ExpandingY; | ||
} else { | ||
windows.width -= RESIZE_STEP; | ||
} | ||
} | ||
Phase::ExpandingY => { | ||
if height >= MAX_HEIGHT { | ||
*phase = ExpandingX; | ||
} else { | ||
windows.height += RESIZE_STEP; | ||
} | ||
} | ||
Phase::ExpandingX => { | ||
if width >= MAX_WIDTH { | ||
*phase = ContractingY; | ||
} else { | ||
windows.width += RESIZE_STEP; | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn sync_dimensions(dim: Res<Dimensions>, mut windows: ResMut<Windows>) { | ||
if dim.is_changed() { | ||
windows.get_primary_mut().unwrap().set_resolution( | ||
dim.width.try_into().unwrap(), | ||
dim.height.try_into().unwrap(), | ||
); | ||
} | ||
} | ||
|
||
/// A simple 3d scene, taken from the `3d_scene` example | ||
fn setup_3d( | ||
mut commands: Commands, | ||
mut meshes: ResMut<Assets<Mesh>>, | ||
mut materials: ResMut<Assets<StandardMaterial>>, | ||
) { | ||
// plane | ||
commands.spawn_bundle(PbrBundle { | ||
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), | ||
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), | ||
..default() | ||
}); | ||
// cube | ||
commands.spawn_bundle(PbrBundle { | ||
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), | ||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), | ||
transform: Transform::from_xyz(0.0, 0.5, 0.0), | ||
..default() | ||
}); | ||
// light | ||
commands.spawn_bundle(PointLightBundle { | ||
point_light: PointLight { | ||
intensity: 1500.0, | ||
shadows_enabled: true, | ||
..default() | ||
}, | ||
transform: Transform::from_xyz(4.0, 8.0, 4.0), | ||
..default() | ||
}); | ||
// camera | ||
commands.spawn_bundle(PerspectiveCameraBundle { | ||
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), | ||
..default() | ||
}); | ||
} | ||
|
||
/// A simple 2d scene, taken from the `rect` example | ||
fn setup_2d(mut commands: Commands) { | ||
commands.spawn_bundle(OrthographicCameraBundle::new_2d()); | ||
commands.spawn_bundle(SpriteBundle { | ||
sprite: Sprite { | ||
color: Color::rgb(0.25, 0.25, 0.75), | ||
custom_size: Some(Vec2::new(50.0, 50.0)), | ||
..default() | ||
}, | ||
..default() | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so cursed, but kind of makes sense? @mockersf I'll defer to your judgement here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get the point of doing that. Is it to make it easy to run manually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because we currently have a scripting setup to run examples. And so if these are examples, they can be run by that setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with it