Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

12
vendor/bevy/tests/3d/no_prepass.rs vendored Normal file
View File

@@ -0,0 +1,12 @@
//! A test to confirm that `bevy` allows disabling the prepass of the standard material.
//! This is run in CI to ensure that this doesn't regress again.
use bevy::{pbr::PbrPlugin, prelude::*};
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(PbrPlugin {
prepass_enabled: false,
..default()
}))
.run();
}

View File

@@ -0,0 +1,80 @@
//! A test to confirm that `bevy` doesn't regress its system ambiguities count when using [`DefaultPlugins`].
//! This is run in CI.
//!
//! Note that because this test requires rendering, it isn't actually an integration test!
//! Instead, it's secretly an example: you can run this test manually using `cargo run --example ambiguity_detection`.
use bevy::{
ecs::schedule::{InternedScheduleLabel, LogLevel, ScheduleBuildSettings},
platform::collections::HashMap,
prelude::*,
render::pipelined_rendering::RenderExtractApp,
};
fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins);
let main_app = app.main_mut();
configure_ambiguity_detection(main_app);
let render_extract_app = app.sub_app_mut(RenderExtractApp);
configure_ambiguity_detection(render_extract_app);
// Ambiguities in the RenderApp are currently allowed.
// Eventually, we should forbid these: see https://github.com/bevyengine/bevy/issues/7386
// Uncomment the lines below to show the current ambiguities in the RenderApp.
// let sub_app = app.sub_app_mut(bevy_render::RenderApp);
// configure_ambiguity_detection(sub_app);
app.finish();
app.cleanup();
app.update();
let main_app_ambiguities = count_ambiguities(app.main());
assert_eq!(
main_app_ambiguities.total(),
0,
"Main app has unexpected ambiguities among the following schedules: \n{main_app_ambiguities:#?}.",
);
// RenderApp is not checked here, because it is not within the App at this point.
let render_extract_ambiguities = count_ambiguities(app.sub_app(RenderExtractApp));
assert_eq!(
render_extract_ambiguities.total(),
0,
"RenderExtract app has unexpected ambiguities among the following schedules: \n{render_extract_ambiguities:#?}",
);
}
/// Contains the number of conflicting systems per schedule.
#[derive(Debug, Deref, DerefMut)]
struct AmbiguitiesCount(pub HashMap<InternedScheduleLabel, usize>);
impl AmbiguitiesCount {
fn total(&self) -> usize {
self.values().sum()
}
}
fn configure_ambiguity_detection(sub_app: &mut SubApp) {
let mut schedules = sub_app.world_mut().resource_mut::<Schedules>();
for (_, schedule) in schedules.iter_mut() {
schedule.set_build_settings(ScheduleBuildSettings {
// NOTE: you can change this to `LogLevel::Ignore` to easily see the current number of ambiguities.
ambiguity_detection: LogLevel::Warn,
use_shortnames: false,
..default()
});
}
}
/// Returns the number of conflicting systems per schedule.
fn count_ambiguities(sub_app: &SubApp) -> AmbiguitiesCount {
let schedules = sub_app.world().resource::<Schedules>();
let mut ambiguities = <HashMap<_, _>>::default();
for (_, schedule) in schedules.iter() {
let ambiguities_in_schedule = schedule.graph().conflicting_systems().len();
ambiguities.insert(schedule.label(), ambiguities_in_schedule);
}
AmbiguitiesCount(ambiguities)
}

144
vendor/bevy/tests/how_to_test_apps.rs vendored Normal file
View File

@@ -0,0 +1,144 @@
//! Demonstrates simple integration testing of Bevy applications.
//!
//! By substituting [`DefaultPlugins`] with [`MinimalPlugins`], Bevy can run completely headless.
//!
//! The list of minimal plugins does not include things like window or input handling. The downside
//! of this is that resources or entities associated with those systems (for example:
//! `ButtonInput::<KeyCode>`) need to be manually added, either directly or via e.g.
//! [`InputPlugin`]. The upside, however, is that the test has complete control over these
//! resources, meaning we can fake user input, fake the window being moved around, and more.
use bevy::prelude::*;
#[derive(Component)]
struct Player {
mana: u32,
}
impl Default for Player {
fn default() -> Self {
Self { mana: 10 }
}
}
/// Splitting a Bevy project into multiple smaller plugins can make it more testable. We can
/// write tests for individual plugins in isolation, as well as for the entire project.
fn game_plugin(app: &mut App) {
app.add_systems(Startup, (spawn_player, window_title_system).chain());
app.add_systems(Update, spell_casting);
}
fn window_title_system(mut windows: Query<&mut Window>) {
for (index, mut window) in windows.iter_mut().enumerate() {
window.title = format!("This is window {index}!");
}
}
fn spawn_player(mut commands: Commands) {
commands.spawn(Player::default());
}
fn spell_casting(mut player: Query<&mut Player>, keyboard_input: Res<ButtonInput<KeyCode>>) {
if keyboard_input.just_pressed(KeyCode::Space) {
let Ok(mut player) = player.single_mut() else {
return;
};
if player.mana > 0 {
player.mana -= 1;
}
}
}
fn create_test_app() -> App {
let mut app = App::new();
// Note the use of `MinimalPlugins` instead of `DefaultPlugins`, as described above.
app.add_plugins(MinimalPlugins);
// Inserting a `KeyCode` input resource allows us to inject keyboard inputs, as if the user had
// pressed them.
app.insert_resource(ButtonInput::<KeyCode>::default());
// Spawning a fake window allows testing systems that require a window.
app.world_mut().spawn(Window::default());
app
}
#[test]
fn test_player_spawn() {
let mut app = create_test_app();
app.add_plugins(game_plugin);
// The `update` function needs to be called at least once for the startup
// systems to run.
app.update();
// Now that the startup systems have run, we can check if the player has
// spawned as expected.
let expected = Player::default();
let actual = app.world_mut().query::<&Player>().single(app.world());
assert!(actual.is_ok(), "There should be exactly 1 player.");
assert_eq!(
expected.mana,
actual.unwrap().mana,
"Player does not have expected starting mana."
);
}
#[test]
fn test_spell_casting() {
let mut app = create_test_app();
app.add_plugins(game_plugin);
// Simulate pressing space to trigger the spell casting system.
app.world_mut()
.resource_mut::<ButtonInput<KeyCode>>()
.press(KeyCode::Space);
// Allow the systems to recognize the input event.
app.update();
let expected = Player::default();
let actual = app
.world_mut()
.query::<&Player>()
.single(app.world())
.unwrap();
assert_eq!(
expected.mana - 1,
actual.mana,
"A single mana point should have been used."
);
// Clear the `just_pressed` status for all `KeyCode`s
app.world_mut()
.resource_mut::<ButtonInput<KeyCode>>()
.clear();
app.update();
// No extra spells have been cast, so no mana should have been used.
let after_keypress_event = app
.world_mut()
.query::<&Player>()
.single(app.world())
.unwrap();
assert_eq!(
expected.mana - 1,
after_keypress_event.mana,
"No further mana should have been used."
);
}
#[test]
fn test_window_title() {
let mut app = create_test_app();
app.add_plugins(game_plugin);
app.update();
let window = app
.world_mut()
.query::<&Window>()
.single(app.world())
.unwrap();
assert_eq!(window.title, "This is window 0!");
}

174
vendor/bevy/tests/how_to_test_systems.rs vendored Normal file
View File

@@ -0,0 +1,174 @@
#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
use bevy::prelude::*;
#[derive(Component, Default)]
struct Enemy {
hit_points: u32,
score_value: u32,
}
#[derive(Event)]
struct EnemyDied(u32);
#[derive(Resource)]
struct Score(u32);
fn update_score(mut dead_enemies: EventReader<EnemyDied>, mut score: ResMut<Score>) {
for value in dead_enemies.read() {
score.0 += value.0;
}
}
fn despawn_dead_enemies(
mut commands: Commands,
mut dead_enemies: EventWriter<EnemyDied>,
enemies: Query<(Entity, &Enemy)>,
) {
for (entity, enemy) in &enemies {
if enemy.hit_points == 0 {
commands.entity(entity).despawn();
dead_enemies.write(EnemyDied(enemy.score_value));
}
}
}
fn hurt_enemies(mut enemies: Query<&mut Enemy>) {
for mut enemy in &mut enemies {
enemy.hit_points -= 1;
}
}
fn spawn_enemy(mut commands: Commands, keyboard_input: Res<ButtonInput<KeyCode>>) {
if keyboard_input.just_pressed(KeyCode::Space) {
commands.spawn(Enemy {
hit_points: 5,
score_value: 3,
});
}
}
#[test]
fn did_hurt_enemy() {
// Setup app
let mut app = App::new();
// Add Score resource
app.insert_resource(Score(0));
// Add `EnemyDied` event
app.add_event::<EnemyDied>();
// Add our two systems
app.add_systems(Update, (hurt_enemies, despawn_dead_enemies).chain());
// Setup test entities
let enemy_id = app
.world_mut()
.spawn(Enemy {
hit_points: 5,
score_value: 3,
})
.id();
// Run systems
app.update();
// Check resulting changes
assert!(app.world().get::<Enemy>(enemy_id).is_some());
assert_eq!(app.world().get::<Enemy>(enemy_id).unwrap().hit_points, 4);
}
#[test]
fn did_despawn_enemy() {
// Setup app
let mut app = App::new();
// Add Score resource
app.insert_resource(Score(0));
// Add `EnemyDied` event
app.add_event::<EnemyDied>();
// Add our two systems
app.add_systems(Update, (hurt_enemies, despawn_dead_enemies).chain());
// Setup test entities
let enemy_id = app
.world_mut()
.spawn(Enemy {
hit_points: 1,
score_value: 1,
})
.id();
// Run systems
app.update();
// Check enemy was despawned
assert!(app.world().get::<Enemy>(enemy_id).is_none());
// Get `EnemyDied` event reader
let enemy_died_events = app.world().resource::<Events<EnemyDied>>();
let mut enemy_died_reader = enemy_died_events.get_cursor();
let enemy_died = enemy_died_reader.read(enemy_died_events).next().unwrap();
// Check the event has been sent
assert_eq!(enemy_died.0, 1);
}
#[test]
fn spawn_enemy_using_input_resource() {
// Setup app
let mut app = App::new();
// Add our systems
app.add_systems(Update, spawn_enemy);
// Setup test resource
let mut input = ButtonInput::<KeyCode>::default();
input.press(KeyCode::Space);
app.insert_resource(input);
// Run systems
app.update();
// Check resulting changes, one entity has been spawned with `Enemy` component
assert_eq!(app.world_mut().query::<&Enemy>().iter(app.world()).len(), 1);
// Clear the `just_pressed` status for all `KeyCode`s
app.world_mut()
.resource_mut::<ButtonInput<KeyCode>>()
.clear();
// Run systems
app.update();
// Check resulting changes, no new entity has been spawned
assert_eq!(app.world_mut().query::<&Enemy>().iter(app.world()).len(), 1);
}
#[test]
fn update_score_on_event() {
// Setup app
let mut app = App::new();
// Add Score resource
app.insert_resource(Score(0));
// Add `EnemyDied` event
app.add_event::<EnemyDied>();
// Add our systems
app.add_systems(Update, update_score);
// Send an `EnemyDied` event
app.world_mut()
.resource_mut::<Events<EnemyDied>>()
.send(EnemyDied(3));
// Run systems
app.update();
// Check resulting changes
assert_eq!(app.world().resource::<Score>().0, 3);
}

View File

@@ -0,0 +1,62 @@
//! a test that confirms that 'bevy' does not panic while changing from Windowed to Fullscreen when viewport is set
use bevy::{prelude::*, render::camera::Viewport, window::WindowMode};
//Having a viewport set to the same size as a window used to cause panic on some occasions when switching to Fullscreen
const WINDOW_WIDTH: f32 = 1366.0;
const WINDOW_HEIGHT: f32 = 768.0;
fn main() {
//Specify Window Size.
let window = Window {
resolution: (WINDOW_WIDTH, WINDOW_HEIGHT).into(),
..default()
};
let primary_window = Some(window);
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window,
..default()
}))
.add_systems(Startup, startup)
.add_systems(Update, toggle_window_mode)
.run();
}
fn startup(mut cmds: Commands) {
//Match viewport to Window size.
let physical_position = UVec2::new(0, 0);
let physical_size = Vec2::new(WINDOW_WIDTH, WINDOW_HEIGHT).as_uvec2();
let viewport = Some(Viewport {
physical_position,
physical_size,
..default()
});
cmds.spawn(Camera2d).insert(Camera {
viewport,
..default()
});
}
fn toggle_window_mode(mut qry_window: Query<&mut Window>) {
let Ok(mut window) = qry_window.single_mut() else {
return;
};
window.mode = match window.mode {
WindowMode::Windowed => {
// it takes a while for the window to change from `Windowed` to `Fullscreen` and back
std::thread::sleep(std::time::Duration::from_secs(4));
WindowMode::Fullscreen(
MonitorSelection::Entity(entity),
VideoModeSelection::Current,
)
}
_ => {
std::thread::sleep(std::time::Duration::from_secs(4));
WindowMode::Windowed
}
};
}

77
vendor/bevy/tests/window/minimizing.rs vendored Normal file
View File

@@ -0,0 +1,77 @@
//! A test to confirm that `bevy` allows minimizing the window
//! This is run in CI to ensure that this doesn't regress again.
use bevy::{diagnostic::FrameCount, prelude::*};
fn main() {
// TODO: Combine this with `resizing` once multiple_windows is simpler than
// it is currently.
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Minimizing".into(),
..default()
}),
..default()
}))
.add_systems(Startup, (setup_3d, setup_2d))
.add_systems(Update, minimize_automatically)
.run();
}
fn minimize_automatically(mut window: Single<&mut Window>, frames: Res<FrameCount>) {
if frames.0 != 60 {
return;
}
window.set_minimized(true);
}
/// 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((
Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
));
// cube
commands.spawn((
Mesh3d(meshes.add(Cuboid::default())),
MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
Transform::from_xyz(0.0, 0.5, 0.0),
));
// light
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
Transform::from_xyz(4.0, 8.0, 4.0),
));
// camera
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}
/// A simple 2d scene, taken from the `rect` example
fn setup_2d(mut commands: Commands) {
commands.spawn((
Camera2d,
Camera {
// render the 2d camera after the 3d camera
order: 1,
// do not use a clear color
clear_color: ClearColorConfig::None,
..default()
},
));
commands.spawn(Sprite::from_color(
Color::srgb(0.25, 0.25, 0.75),
Vec2::new(50.0, 50.0),
));
}

153
vendor/bevy/tests/window/resizing.rs vendored Normal file
View File

@@ -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::{prelude::*, window::WindowResolution};
// 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;
#[derive(Resource)]
struct Dimensions {
width: u16,
height: u16,
}
fn main() {
App::new()
.add_plugins(
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(MAX_WIDTH as f32, MAX_HEIGHT as f32)
.with_scale_factor_override(1.0),
title: "Resizing".into(),
..default()
}),
..default()
}),
)
.insert_resource(Dimensions {
width: MAX_WIDTH,
height: MAX_HEIGHT,
})
.insert_resource(ContractingY)
.add_systems(Startup, (setup_3d, setup_2d))
.add_systems(Update, (change_window_size, sync_dimensions))
.run();
}
#[derive(Resource)]
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 {
ContractingY => {
if height <= MIN_HEIGHT {
*phase = ContractingX;
} else {
windows.height -= RESIZE_STEP;
}
}
ContractingX => {
if width <= MIN_WIDTH {
*phase = ExpandingY;
} else {
windows.width -= RESIZE_STEP;
}
}
ExpandingY => {
if height >= MAX_HEIGHT {
*phase = ExpandingX;
} else {
windows.height += RESIZE_STEP;
}
}
ExpandingX => {
if width >= MAX_WIDTH {
*phase = ContractingY;
} else {
windows.width += RESIZE_STEP;
}
}
}
}
fn sync_dimensions(dim: Res<Dimensions>, mut window: Single<&mut Window>) {
if dim.is_changed() {
window.resolution.set(dim.width as f32, dim.height as f32);
}
}
/// 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((
Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
));
// cube
commands.spawn((
Mesh3d(meshes.add(Cuboid::default())),
MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
Transform::from_xyz(0.0, 0.5, 0.0),
));
// light
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
Transform::from_xyz(4.0, 8.0, 4.0),
));
// camera
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}
/// A simple 2d scene, taken from the `rect` example
fn setup_2d(mut commands: Commands) {
commands.spawn((
Camera2d,
Camera {
// render the 2d camera after the 3d camera
order: 1,
// do not use a clear color
clear_color: ClearColorConfig::None,
..default()
},
));
commands.spawn(Sprite::from_color(
Color::srgb(0.25, 0.25, 0.75),
Vec2::new(50.0, 50.0),
));
}