Skip to content

Commit

Permalink
Update to Bevy 0.15 (#97)
Browse files Browse the repository at this point in the history
* update to delta_secs, and use Transform

* update bevy dev dependency to 0.15.0-rc.2, and update examples accordingly to fit new version

* update spatial example with bevy 0.15 and format code

* Update to stable 0.15

* Complement audio_control display instructions

---------

Co-authored-by: Salzian <salzian.dev@gmail.com>
  • Loading branch information
CarlosEduR and Salzian authored Dec 2, 2024
1 parent 36d1a8f commit 6034b72
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ exclude = [
]

[dependencies]
bevy = { version = "0.14", default-features = false }
bevy = { version = "0.15", default-features = false }
libfmod = "~2.222.6"

[dev-dependencies.bevy]
version = "0.14"
version = "0.15"
features = [
"bevy_core_pipeline",
"bevy_render",
Expand Down
14 changes: 7 additions & 7 deletions examples/audio_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn startup(mut commands: Commands, studio: Res<FmodStudio>) {
});

// In this case only needed to show the controls:
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

fn play_music(mut audio_sources: Query<&AudioSource, With<MyMusicPlayer>>) {
Expand Down Expand Up @@ -65,10 +65,10 @@ fn audio_control(query: Query<&AudioSource>, input: Res<ButtonInput<KeyCode>>) {
}

fn display_controls(mut commands: Commands) {
commands.spawn(TextBundle::from_sections([
TextSection::from("Controls: \n"),
TextSection::from("S: Stop \n"),
TextSection::from("P: Play \n"),
TextSection::from("T: Toggle \n"),
]));
commands.spawn(Text::default()).with_children(|parent| {
parent.spawn(TextSpan::new("Controls: \n"));
parent.spawn(TextSpan::new("S: Stop \n"));
parent.spawn(TextSpan::new("P: Play \n"));
parent.spawn(TextSpan::new("T: Toggle Play/Pause \n"));
});
}
16 changes: 8 additions & 8 deletions examples/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn startup(mut commands: Commands, studio: Res<FmodStudio>) {
});

// In this case only needed to show the controls:
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

fn play_music(audio_sources: Query<&AudioSource>) {
Expand Down Expand Up @@ -128,11 +128,11 @@ fn set_hour(
}

fn display_controls(mut commands: Commands) {
commands.spawn(TextBundle::from_sections([
TextSection::from("Controls: \n"),
TextSection::from("Arrow Up: Increase Rain \n"),
TextSection::from("Arrow Down: Decrease Rain \n"),
TextSection::from("E: Change time to Evening \n"),
TextSection::from("M: Change time to Morning \n"),
]));
commands.spawn(Text::default()).with_children(|parent| {
parent.spawn(TextSpan::new("Controls: \n"));
parent.spawn(TextSpan::new("Arrow Up: Increase Rain \n"));
parent.spawn(TextSpan::new("Arrow Down: Decrease Rain \n"));
parent.spawn(TextSpan::new("E: Change time to Evening \n"));
parent.spawn(TextSpan::new("M: Change time to Morning \n"));
});
}
52 changes: 22 additions & 30 deletions examples/spatial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,25 @@ fn setup_scene(
studio: Res<FmodStudio>,
) {
// Plane
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
transform: Transform::from_xyz(0.0, -1.0, 0.0),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
Transform::from_xyz(0.0, -1.0, 0.0),
));

// Light
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
Transform::from_xyz(4.0, 8.0, 4.0),
));

// Camera
commands
.spawn(SpatialListenerBundle::default())
.insert(Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.0, 4.0),
..default()
});
.insert((Camera3d::default(), Transform::from_xyz(0.0, 0.0, 4.0)));

// Audio source: Orbiting cube
let event_description = studio.get_event("event:/Music/Radio Station").unwrap();
Expand All @@ -68,12 +63,11 @@ fn setup_scene(

commands
.spawn(SpatialAudioBundle::from(audio_source))
.insert(PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_scale(Vec3::splat(0.2)),
..default()
});
.insert((
Mesh3d(meshes.add(Cuboid::default())),
MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
Transform::from_scale(Vec3::splat(0.2)),
));
}

fn play_music(mut audio_sources: Query<&AudioSource>) {
Expand All @@ -85,8 +79,8 @@ fn orbit_audio_source(
mut audio_sources: Query<&mut Transform, With<AudioSource>>,
) {
for mut audio_source in audio_sources.iter_mut() {
audio_source.translation.x = time.elapsed_seconds().sin() * 2.0;
audio_source.translation.z = time.elapsed_seconds().cos() * 2.0;
audio_source.translation.x = time.elapsed_secs().sin() * 2.0;
audio_source.translation.z = time.elapsed_secs().cos() * 2.0;
}
}

Expand All @@ -100,21 +94,19 @@ fn update_listener(
let speed = 4.;

if keyboard.pressed(KeyCode::ArrowRight) {
transform.translation.x += speed * time.delta_seconds();
transform.translation.x += speed * time.delta_secs();
}
if keyboard.pressed(KeyCode::ArrowLeft) {
transform.translation.x -= speed * time.delta_seconds();
transform.translation.x -= speed * time.delta_secs();
}
if keyboard.pressed(KeyCode::ArrowDown) {
transform.translation.z += speed * time.delta_seconds();
transform.translation.z += speed * time.delta_secs();
}
if keyboard.pressed(KeyCode::ArrowUp) {
transform.translation.z -= speed * time.delta_seconds();
transform.translation.z -= speed * time.delta_secs();
}
}

fn display_controls(mut commands: Commands) {
commands.spawn(TextBundle::from(
"Controls: Use the arrow keys to move around",
));
commands.spawn(Text::from("Controls: Use the arrow keys to move around"));
}
10 changes: 5 additions & 5 deletions src/components/bundles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
//! For more information on bundles, see the [`Bundle`] trait.
use crate::prelude::{AudioListener, AudioSource, Velocity};
use bevy::prelude::{Bundle, TransformBundle};
use bevy::prelude::{Bundle, Transform};
use libfmod::{EventDescription, StopMode};

/// A bundle that includes all components required for emitting spatial audio.
#[derive(Bundle)]
pub struct SpatialAudioBundle {
audio_source: AudioSource,
velocity: Velocity,
transform: TransformBundle,
transform: Transform,
}

impl SpatialAudioBundle {
Expand All @@ -33,7 +33,7 @@ impl SpatialAudioBundle {
despawn_stop_mode: StopMode::AllowFadeout,
},
velocity: Velocity::default(),
transform: TransformBundle::default(),
transform: Transform::default(),
}
}
}
Expand All @@ -43,7 +43,7 @@ impl From<AudioSource> for SpatialAudioBundle {
SpatialAudioBundle {
audio_source: value,
velocity: Velocity::default(),
transform: TransformBundle::default(),
transform: Transform::default(),
}
}
}
Expand All @@ -53,5 +53,5 @@ impl From<AudioSource> for SpatialAudioBundle {
pub struct SpatialListenerBundle {
audio_listener: AudioListener,
velocity: Velocity,
transform: TransformBundle,
transform: Transform,
}
2 changes: 1 addition & 1 deletion src/components/velocity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl VelocityPlugin {
mut last_delta: Local<f32>,
) {
let delta_time = *last_delta;
*last_delta = time.delta_seconds();
*last_delta = time.delta_secs();

if delta_time == 0.0 {
return;
Expand Down

0 comments on commit 6034b72

Please sign in to comment.