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

Update to bevy 0.15 #318

Merged
merged 4 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
1,678 changes: 1,193 additions & 485 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "MIT OR Apache-2.0 OR CC0-1.0"

[dependencies]
bevy = { version = "0.14", features = ["wayland"] }
bevy = { version = "0.15.0-rc.1", features = ["wayland"] }
rand = "0.8"
# Compile low-severity logs out of native builds for performance.
log = { version = "0.4", features = [
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bevy = { version = "0.14", features = ["wayland"] }
bevy = { version = "0.15.0-rc.1", features = ["wayland"] }
rand = "0.8"
# Compile low-severity logs out of native builds for performance.
log = { version = "0.4", features = [
Expand Down
9 changes: 5 additions & 4 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ You can also mix the dynamic and static approach according to your needs.
### Pattern

Spawn a game object by using a custom command. Inside the command,
run the spawning code with `world.run_system_once` or `world.run_system_once_with`:
run the spawning code with `world.run_system_cached` or `world.run_system_cached_with`:

```rust
// monster.rs
Expand All @@ -192,7 +192,7 @@ pub struct SpawnMonster {

impl Command for SpawnMonster {
fn apply(self, world: &mut World) {
world.run_system_once_with(self, spawn_monster);
let _ = world.run_system_cached_with(spawn_monster, self);
}
}

Expand All @@ -203,7 +203,8 @@ fn spawn_monster(
commands.spawn((
Name::new("Monster"),
Health::new(spawn_monster.health),
SpatialBundle::from_transform(spawn_monster.transform),
spawn_monster.transform,
Visibility::default(),
// other components
));
}
Expand All @@ -215,7 +216,7 @@ And then to use a spawn command, add it to `Commands`:
// dangerous_forest.rs

fn spawn_forest_goblin(mut commands: Commands) {
commands.add(SpawnMonster {
commands.queue(SpawnMonster {
health: 100,
transform: Transform::from_xyz(10.0, 0.0, 0.0),
});
Expand Down
13 changes: 7 additions & 6 deletions src/demo/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ fn update_animation_timer(time: Res<Time>, mut query: Query<&mut PlayerAnimation
}

/// Update the texture atlas to reflect changes in the animation.
fn update_animation_atlas(mut query: Query<(&PlayerAnimation, &mut TextureAtlas)>) {
for (animation, mut atlas) in &mut query {
fn update_animation_atlas(mut query: Query<(&PlayerAnimation, &mut Sprite)>) {
for (animation, mut sprite) in &mut query {
let Some(atlas) = sprite.texture_atlas.as_mut() else {
continue;
};
if animation.changed() {
atlas.index = animation.get_atlas_index();
}
Expand All @@ -83,10 +86,8 @@ fn trigger_step_sound_effect(
let rng = &mut rand::thread_rng();
let random_step = player_assets.steps.choose(rng).unwrap();
commands.spawn((
AudioBundle {
source: random_step.clone(),
settings: PlaybackSettings::DESPAWN,
},
AudioPlayer(random_step.clone()),
PlaybackSettings::DESPAWN,
SoundEffect,
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/demo/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn apply_movement(
) {
for (controller, mut transform) in &mut movement_query {
let velocity = controller.max_speed * controller.intent;
transform.translation += velocity.extend(0.0) * time.delta_seconds();
transform.translation += velocity.extend(0.0) * time.delta_secs();
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/demo/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! for other characters as well.

use bevy::{
ecs::{system::RunSystemOnce as _, world::Command},
ecs::world::Command,
prelude::*,
render::texture::{ImageLoaderSettings, ImageSampler},
};
Expand Down Expand Up @@ -42,7 +42,7 @@ pub struct SpawnPlayer {

impl Command for SpawnPlayer {
fn apply(self, world: &mut World) {
world.run_system_once_with(self, spawn_player);
let _ = world.run_system_cached_with(spawn_player, self);
}
}

Expand All @@ -64,15 +64,15 @@ fn spawn_player(
commands.spawn((
Name::new("Player"),
Player,
SpriteBundle {
texture: player_assets.ducky.clone(),
transform: Transform::from_scale(Vec2::splat(8.0).extend(1.0)),
..Default::default()
},
TextureAtlas {
layout: texture_atlas_layout.clone(),
index: player_animation.get_atlas_index(),
Sprite {
image: player_assets.ducky.clone(),
texture_atlas: Some(TextureAtlas {
layout: texture_atlas_layout.clone(),
index: player_animation.get_atlas_index(),
}),
..default()
},
Transform::from_scale(Vec2::splat(8.0).extend(1.0)),
MovementController {
max_speed: config.max_speed,
..default()
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ enum AppSet {
fn spawn_camera(mut commands: Commands) {
commands.spawn((
Name::new("Camera"),
Camera2dBundle::default(),
Camera2d,
// Render all UI to this camera.
// Not strictly necessary since we only use one camera,
// but if we don't use this component, our UI will disappear as soon
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs.template
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ enum AppSet {
fn spawn_camera(mut commands: Commands) {
commands.spawn((
Name::new("Camera"),
Camera2dBundle::default(),
Camera2d,
// Render all UI to this camera.
// Not strictly necessary since we only use one camera,
// but if we don't use this component, our UI will disappear as soon
Expand Down
6 changes: 2 additions & 4 deletions src/screens/credits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ fn play_credits_music(mut commands: Commands, mut music: ResMut<CreditsMusic>) {
music.entity = Some(
commands
.spawn((
AudioBundle {
source: music.music.clone(),
settings: PlaybackSettings::LOOP,
},
AudioPlayer(music.music.clone()),
PlaybackSettings::LOOP,
Music,
))
.id(),
Expand Down
10 changes: 4 additions & 6 deletions src/screens/gameplay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ pub(super) fn plugin(app: &mut App) {
app.add_systems(
Update,
return_to_title_screen
.run_if(in_state(Screen::Gameplay).and_then(input_just_pressed(KeyCode::Escape))),
.run_if(in_state(Screen::Gameplay).and(input_just_pressed(KeyCode::Escape))),
);
}

fn spawn_level(mut commands: Commands) {
commands.add(spawn_level_command);
commands.queue(spawn_level_command);
}

#[derive(Resource, Asset, Reflect, Clone)]
Expand All @@ -46,10 +46,8 @@ fn play_gameplay_music(mut commands: Commands, mut music: ResMut<GameplayMusic>)
music.entity = Some(
commands
.spawn((
AudioBundle {
source: music.handle.clone(),
settings: PlaybackSettings::LOOP,
},
AudioPlayer(music.handle.clone()),
PlaybackSettings::LOOP,
Music,
))
.id(),
Expand Down
4 changes: 2 additions & 2 deletions src/screens/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(super) fn plugin(app: &mut App) {

app.add_systems(
Update,
continue_to_title_screen.run_if(in_state(Screen::Loading).and_then(all_assets_loaded)),
continue_to_title_screen.run_if(in_state(Screen::Loading).and(all_assets_loaded)),
);
}

Expand All @@ -23,7 +23,7 @@ fn spawn_loading_screen(mut commands: Commands) {
.ui_root()
.insert(StateScoped(Screen::Loading))
.with_children(|children| {
children.label("Loading...").insert(Style {
children.label("Loading...").insert(Node {
justify_content: JustifyContent::Center,
..default()
});
Expand Down
33 changes: 15 additions & 18 deletions src/screens/splash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(super) fn plugin(app: &mut App) {
app.add_systems(
Update,
continue_to_loading_screen
.run_if(input_just_pressed(KeyCode::Escape).and_then(in_state(Screen::Splash))),
.run_if(input_just_pressed(KeyCode::Escape).and(in_state(Screen::Splash))),
);
}

Expand All @@ -59,24 +59,21 @@ fn spawn_splash_screen(mut commands: Commands, asset_server: Res<AssetServer>) {
.with_children(|children| {
children.spawn((
Name::new("Splash image"),
ImageBundle {
style: Style {
margin: UiRect::all(Val::Auto),
width: Val::Percent(70.0),
..default()
},
image: UiImage::new(asset_server.load_with_settings(
// This should be an embedded asset for instant loading, but that is
// currently [broken on Windows Wasm builds](https://github.com/bevyengine/bevy/issues/14246).
"images/splash.png",
|settings: &mut ImageLoaderSettings| {
// Make an exception for the splash image in case
// `ImagePlugin::default_nearest()` is used for pixel art.
settings.sampler = ImageSampler::linear();
},
)),
Node {
margin: UiRect::all(Val::Auto),
width: Val::Percent(70.0),
..default()
},
UiImage::new(asset_server.load_with_settings(
// This should be an embedded asset for instant loading, but that is
// currently [broken on Windows Wasm builds](https://github.com/bevyengine/bevy/issues/14246).
"images/splash.png",
|settings: &mut ImageLoaderSettings| {
// Make an exception for the splash image in case
// `ImagePlugin::default_nearest()` is used for pixel art.
settings.sampler = ImageSampler::linear();
},
)),
UiImageFadeInOut {
total_duration: SPLASH_DURATION_SECS,
fade_duration: SPLASH_FADE_DURATION_SECS,
Expand Down Expand Up @@ -110,7 +107,7 @@ impl UiImageFadeInOut {

fn tick_fade_in_out(time: Res<Time>, mut animation_query: Query<&mut UiImageFadeInOut>) {
for mut anim in &mut animation_query {
anim.t += time.delta_seconds();
anim.t += time.delta_secs();
}
}

Expand Down
8 changes: 1 addition & 7 deletions src/theme/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ fn trigger_interaction_sound_effect(
Interaction::Pressed => interaction_assets.press.clone(),
_ => continue,
};
commands.spawn((
AudioBundle {
source,
settings: PlaybackSettings::DESPAWN,
},
SoundEffect,
));
commands.spawn((AudioPlayer(source), PlaybackSettings::DESPAWN, SoundEffect));
}
}
Loading
Loading