Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb3ed08

Browse files
committed
migrate to seedling 0.5; implement music fade_in/fade_out
1 parent21800f7 commiteb3ed08

File tree

12 files changed

+743
-622
lines changed

12 files changed

+743
-622
lines changed

‎Cargo.lock‎

Lines changed: 556 additions & 397 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ bevy_skein = "0.2.1" # blender integration
8585
iyes_perf_ui ="0.5"# diagnostics overlay
8686

8787
avian3d = {version ="0.3",features = ["3d","parallel","collider-from-mesh"] }# physics
88-
bevy_seedling ="0.4"# audio engine
88+
bevy_seedling ="0.5"# audio engine
8989
bevy_third_person_camera = {version ="0.3",optional =true }# 3rd person camera
9090
bevy_top_down_camera = {version ="0.1",optional =true }# top down camera
9191
bevy-tnua ="0.24"# floating character control

‎assets/settings.ron‎

Lines changed: 50 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,59 @@
11
(
22
sound: (
33
general:1.0,
4-
music:0.10000002,
4+
music:1.0000001,
55
sfx:0.5,
66
),
77
fov:45.0,
88
sun_cycle:DayNight,
9-
keybind: (
10-
left: [
11-
Keyboard(
12-
key:KeyA,
13-
mod_keys: (0),
14-
),
15-
Keyboard(
16-
key:ArrowLeft,
17-
mod_keys: (0),
18-
),
19-
],
20-
right: [
21-
Keyboard(
22-
key:KeyD,
23-
mod_keys: (0),
24-
),
25-
Keyboard(
26-
key:ArrowRight,
27-
mod_keys: (0),
28-
),
29-
],
30-
forward: [
31-
Keyboard(
32-
key:KeyW,
33-
mod_keys: (0),
34-
),
35-
Keyboard(
36-
key:ArrowUp,
37-
mod_keys: (0),
38-
),
39-
],
40-
backward: [
41-
Keyboard(
42-
key:KeyS,
43-
mod_keys: (0),
44-
),
45-
Keyboard(
46-
key:ArrowDown,
47-
mod_keys: (0),
48-
),
49-
],
50-
jump: [
51-
Keyboard(
52-
key:Space,
53-
mod_keys: (0),
54-
),
55-
],
56-
dash: [
57-
Keyboard(
58-
key:AltLeft,
59-
mod_keys: (0),
60-
),
61-
],
62-
crouch: [
63-
Keyboard(
64-
key:ControlLeft,
65-
mod_keys: (0),
66-
),
67-
],
68-
sprint: [
69-
Keyboard(
70-
key:ShiftLeft,
71-
mod_keys: (0),
72-
),
73-
],
74-
attack: [
75-
MouseButton(
76-
button:Left,
77-
mod_keys: (0),
78-
),
79-
],
9+
input_map: (
10+
forward: (Keyboard(
11+
key:KeyW,
12+
mod_keys: (0),
13+
),Keyboard(
14+
key:ArrowUp,
15+
mod_keys: (0),
16+
),r#None),
17+
left: (Keyboard(
18+
key:KeyA,
19+
mod_keys: (0),
20+
),Keyboard(
21+
key:ArrowLeft,
22+
mod_keys: (0),
23+
),r#None),
24+
backward: (Keyboard(
25+
key:KeyS,
26+
mod_keys: (0),
27+
),Keyboard(
28+
key:ArrowDown,
29+
mod_keys: (0),
30+
),r#None),
31+
right: (Keyboard(
32+
key:KeyD,
33+
mod_keys: (0),
34+
),Keyboard(
35+
key:ArrowRight,
36+
mod_keys: (0),
37+
),r#None),
38+
jump: (Keyboard(
39+
key:Space,
40+
mod_keys: (0),
41+
),r#None,r#None),
42+
dash: (Keyboard(
43+
key:AltLeft,
44+
mod_keys: (0),
45+
),r#None,r#None),
46+
sprint: (Keyboard(
47+
key:ShiftLeft,
48+
mod_keys: (0),
49+
),r#None,r#None),
50+
crouch: (Keyboard(
51+
key:ControlLeft,
52+
mod_keys: (0),
53+
),r#None,r#None),
54+
attack: (MouseButton(
55+
button:Left,
56+
mod_keys: (0),
57+
),r#None,r#None),
8058
),
8159
)

‎src/asset_loading/mod.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
usecrate::*;
22
use bevy::asset::Asset;
3-
use bevy_seedling::sample::Sample;
3+
use bevy_seedling::sample::AudioSample;
44

55
mod ron;
66
mod tracking;
@@ -83,19 +83,19 @@ impl FromWorld for Models {
8383
pubstructAudioSources{
8484
// SFX
8585
#[dependency]
86-
pubbtn_hover:Handle<Sample>,
86+
pubbtn_hover:Handle<AudioSample>,
8787
#[dependency]
88-
pubbtn_press:Handle<Sample>,
88+
pubbtn_press:Handle<AudioSample>,
8989
#[dependency]
90-
pubsteps:Vec<Handle<Sample>>,
90+
pubsteps:Vec<Handle<AudioSample>>,
9191

9292
// music
9393
#[dependency]
94-
pubmenu:Vec<Handle<Sample>>,
94+
pubmenu:Vec<Handle<AudioSample>>,
9595
#[dependency]
96-
pubexplore:Vec<Handle<Sample>>,
96+
pubexplore:Vec<Handle<AudioSample>>,
9797
#[dependency]
98-
pubcombat:Vec<Handle<Sample>>,
98+
pubcombat:Vec<Handle<AudioSample>>,
9999
}
100100

101101
implAudioSources{

‎src/audio.rs‎

Lines changed: 55 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
//! Simple setup for a game: main bus, music and sfx channels
22
//!
3-
//! [Music sampler pool](Music)
4-
//! [Sfx sampler pool](Sfx)
5-
//!
6-
//! ```text
7-
//! ┌─────┐┌───┐┌───────────┐
8-
//! │Music││Sfx││DefaultPool│
9-
//! └┬────┘└┬──┘└┬──────────┘
10-
//! ┌▽──────▽────▽┐
11-
//! │MainBus │
12-
//! └─────────────┘
13-
//! ```
14-
//!
153
//! The `Music` pool, `Sfx` pool, and `DefaultPool` are all routed to the `MainBus` node.
164
//! Since each pool has a `VolumeNode`, we can control them all individually. And,
175
//! since they're all routed to the `MainBus`, we can also set the volume of all three
186
//! at once.
197
//!
208
//! You can see this in action in the knob observers: to set the master volume,
21-
//! we adjust the `MainBus` node, and to set the individual volumes, we adjust the
9+
//! we adjust the `MainPool` node, and to set the individual volumes, we adjust the
2210
//! pool nodes.
2311
//!
2412
//! # Example
2513
//! ```rust,no_run
14+
//! use bevy_seedling::{
15+
//! configuration::{MusicPool, SfxBus},
16+
//! pool::SamplerPool,
17+
//! prelude::*,
18+
//! };
2619
//! #[derive(Resource, Debug, Clone, Serialize, Deserialize, Reflect)]
2720
//! pub struct Sound {
2821
//! pub general: f32,
2922
//! pub music: f32,
3023
//! pub sfx: f32,
3124
//! }
25+
//!
3226
//! fn lower_general(
3327
//! mut sound: ResMut<Sound>,
3428
//! mut general: Single<&mut VolumeNode, With<MainBus>>,
@@ -37,10 +31,54 @@
3731
//! sound.general = new_volume;
3832
//! general.volume = Volume::Linear(new_volume);
3933
//! }
34+
//!
35+
//! fn play_music(
36+
//! _: Trigger<Pointer<Click>>,
37+
//! playing: Query<(), (With<MusicPool>, With<SamplePlayer>)>,
38+
//! mut commands: Commands,
39+
//! server: Res<AssetServer>,
40+
//! ) {
41+
//! // We'll only play music if it's not already playing.
42+
//! if playing.iter().len() > 0 {
43+
//! return;
44+
//! }
45+
//!
46+
//! commands.spawn((
47+
//! // Including the `MusicPool` marker queues this sample in the `MusicPool`.
48+
//! MusicPool,
49+
//! SamplePlayer::new(source).with_volume(Volume::Decibels(-6.0)),
50+
//! ));
51+
//! }
52+
//!
53+
//! fn play_sfx(_: Trigger<Pointer<Click>>, mut commands: Commands, server: Res<AssetServer>) {
54+
//! let source = server.load("caw.ogg");
55+
//! // The default pool is routed to the `SfxBus`, so we don't
56+
//! // need to include any special markers for sound effects.
57+
//! commands.spawn(SamplePlayer::new(source));
58+
//! }
4059
//! ```
4160
//!
4261
use bevy::prelude::*;
43-
use bevy_seedling::{pool::SamplerPool, prelude::*};
62+
use bevy_seedling::prelude::*;
63+
64+
/// Utility for converting a simple `[0.0, 1.0]` range to [`Volume`].
65+
///
66+
///# Example
67+
/// ```
68+
/// use bevy_seedling::prelude::*;
69+
/// use bevy::prelude::*;
70+
///
71+
/// const STEP: f32 = 0.1;
72+
/// const MIN_VOLUME: f32 = 0.0;
73+
/// const MAX_VOLUME: f32 = 1.0;
74+
///
75+
/// pub fn increment_volume(volume: Volume) -> Volume {
76+
/// let perceptual = CONVERTER.volume_to_perceptual(volume);
77+
/// let new_perceptual = (perceptual + STEP).min(MAX_VOLUME);
78+
/// CONVERTER.perceptual_to_volume(new_perceptual)
79+
/// }
80+
/// ```
81+
pubconstCONVERTER:PerceptualVolume =PerceptualVolume::new();
4482

4583
pubfnplugin(app:&mutApp){
4684
// #[cfg(target_arch = "wasm32")]
@@ -56,67 +94,9 @@ pub fn plugin(app: &mut App) {
5694
// #[cfg(not(target_arch = "wasm32"))]
5795
app.add_plugins(bevy_seedling::SeedlingPlugin::default());
5896

59-
app.add_systems(Startup,spawn_pools);
97+
app.add_systems(Startup,setup);
6098
}
6199

62-
fnspawn_pools(mutmaster:Single<&mutVolumeNode,With<MainBus>>,mutcmds:Commands){
63-
// Since the main bus already exists, we can just set the desired volume.
64-
master.volume =Volume::UNITY_GAIN;
65-
66-
cmds.spawn((
67-
SamplerPool(Music),
68-
VolumeNode{
69-
volume:Volume::Linear(0.5),
70-
},
71-
));
72-
cmds.spawn((
73-
SamplerPool(Sfx),
74-
VolumeNode{
75-
volume:Volume::Linear(0.5),
76-
},
77-
));
100+
fnsetup(mutmaster:Single<&mutVolumeNode,With<MainBus>>){
101+
master.volume =CONVERTER.perceptual_to_volume(0.7);
78102
}
79-
80-
/// An organizational marker component that indicates that [`SamplePlayer`] should be routed to the music sampler pool.
81-
///
82-
/// Suitable for anything in "music" category (e.g. global background music, soundtrack)
83-
///
84-
/// This can then be used to query for and operate on sounds in that category
85-
/// ```rust,no_run
86-
/// commands.spawn(
87-
/// Music,
88-
/// SamplePlayer::new(handle).with_volume(Volume::Linear(vol)),
89-
/// );
90-
///
91-
/// // or looping
92-
///
93-
/// commands.spawn(
94-
/// Music,
95-
/// SamplePlayer::new(handle).with_volume(Volume::Linear(vol)).looping(),
96-
/// );
97-
/// ```
98-
#[derive(PoolLabel,Debug,Clone,PartialEq,Eq,Hash,Default,Reflect)]
99-
#[reflect(Component)]
100-
pubstructMusic;
101-
102-
/// An organizational marker component that indicates that [`SamplePlayer`] should be routed to the SFX sampler pool.
103-
///
104-
/// Suitable for anything in "sound effect" category (e.g. footsteps, the sound of a magic spell, a door opening)
105-
///
106-
/// This can then be used to query for and operate on sounds in that category
107-
/// ```rust,no_run
108-
/// commands.spawn(
109-
/// Sfx,
110-
/// SamplePlayer::new(handle).with_volume(Volume::Linear(vol)),
111-
/// );
112-
///
113-
/// // or looping
114-
///
115-
/// commands.spawn(
116-
/// Sfx,
117-
/// SamplePlayer::new(handle).with_volume(Volume::Linear(vol)).looping(),
118-
/// );
119-
/// ```
120-
#[derive(PoolLabel,Debug,Clone,PartialEq,Eq,Hash,Default,Reflect)]
121-
#[reflect(Component)]
122-
pubstructSfx;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp