Night time sfx and swimming

This commit is contained in:
jiminycrick 2020-10-29 23:53:15 -07:00
parent aa6b7cbb65
commit 3169562a80
12 changed files with 102 additions and 42 deletions

View File

@ -17,9 +17,36 @@
],
threshold: 30.0,
),
Cricket: (
files: [
"voxygen.audio.sfx.ambient.crickets_1",
],
threshold: 3.0,
),
Frog: (
files: [
"voxygen.audio.sfx.ambient.frog_croak_1",
],
threshold: 4.0,
),
Bees: (
files: [
"voxygen.audio.sfx.ambient.bees_1",
],
threshold: 15.0,
),
//
// Character States
//
Swim: (
files: [
"voxygen.audio.sfx.footsteps.water_splash_1",
"voxygen.audio.sfx.footsteps.water_splash_2",
"voxygen.audio.sfx.footsteps.water_splash_3",
"voxygen.audio.sfx.footsteps.water_splash_4",
],
threshold: 0.25,
),
Run: (
files: [
"voxygen.audio.sfx.footsteps.stepgrass_1",

BIN
assets/voxygen/audio/sfx/ambient/bees_1.wav (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/voxygen/audio/sfx/ambient/crickets_1.wav (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
assets/voxygen/audio/sfx/ambient/frog_croak_1.wav (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -97,7 +97,8 @@ impl EventMapper for BlockEventMapper {
range: 1,
sfx: SfxEvent::Birdcall,
volume: 1.0,
cond: |_| true,
//cond: |_| true,
cond: |st| st.get_day_period().is_light(),
},
BlockSounds {
blocks: |boi| &boi.embers,
@ -108,41 +109,35 @@ impl EventMapper for BlockEventMapper {
cond: |_| true,
//cond: |st| st.get_day_period().is_dark(),
},
//BlockSounds {
// blocks: |boi| &boi.reeds,
// range: 4,
// spacing: 2.0,
// sfx: SfxEvent::Run,
// volume: 1.0,
// //cond: |st| st.get_day_period().is_dark(),
// cond: |_| true,
//},
BlockSounds {
blocks: |boi| &boi.reeds,
range: 1,
sfx: SfxEvent::Frog,
volume: 0.8,
cond: |st| st.get_day_period().is_dark(),
//cond: |_| true,
},
//BlockSounds {
// blocks: |boi| &boi.flowers,
// range: 4,
// spacing: 2.5,
// sfx: SfxEvent::LevelUp,
// volume: 1.0,
// cond: |st| st.get_day_period().is_dark(),
//},
//BlockSounds {
// blocks: |boi| &boi.grass,
// range: 4,
// spacing: 2.5,
// sfx: SfxEvent::Roll,
// volume: 1.0,
// //cond: |st| st.get_day_period().is_light(),
// cond: |_| false,
//},
//BlockSounds {
// blocks: |boi| &boi.beehives,
// range: 4,
// spacing: 1.5,
// sfx: SfxEvent::Roll,
// volume: 1.0,
// //cond: |st| st.get_day_period().is_light(),
// cond: |_| true,
//},
BlockSounds {
blocks: |boi| &boi.grass,
range: 1,
sfx: SfxEvent::Cricket,
volume: 0.5,
cond: |st| st.get_day_period().is_dark(),
},
BlockSounds {
blocks: |boi| &boi.beehives,
range: 1,
sfx: SfxEvent::Bees,
volume: 1.0,
cond: |_| true,
},
];
// Iterate through each kind of block of interest
@ -166,7 +161,10 @@ impl EventMapper for BlockEventMapper {
// Iterate through each individual block
for block in blocks {
// Reduce the number of bird calls from trees
if sounds.sfx == SfxEvent::Birdcall && thread_rng().gen::<f32>() < 0.25 {
if sounds.sfx == SfxEvent::Birdcall && thread_rng().gen::<f32>() > 0.05 {
println!("skipped a bird");
continue;
} else if sounds.sfx == SfxEvent::Cricket && thread_rng().gen::<f32>() > 0.5 {
continue;
}
@ -252,7 +250,16 @@ impl BlockEventMapper {
) -> bool {
if let Some((event, item)) = sfx_trigger_item {
if &previous_state.event == event {
previous_state.time.elapsed().as_secs_f64() >= item.threshold
if event == &SfxEvent::Birdcall {
if thread_rng().gen_bool(0.5) {
previous_state.time.elapsed().as_secs_f64()
>= (item.threshold + thread_rng().gen_range(-3.0, 3.0))
} else {
false
}
} else {
previous_state.time.elapsed().as_secs_f64() >= item.threshold
}
} else {
true
}

View File

@ -22,6 +22,7 @@ struct PreviousEntityState {
event: SfxEvent,
time: Instant,
on_ground: bool,
in_water: bool,
}
impl Default for PreviousEntityState {
@ -30,6 +31,7 @@ impl Default for PreviousEntityState {
event: SfxEvent::Idle,
time: Instant::now(),
on_ground: true,
in_water: false,
}
}
}
@ -95,6 +97,11 @@ impl EventMapper for MovementEventMapper {
// it was dispatched
state.event = mapped_event;
state.on_ground = physics.on_ground;
if physics.in_fluid.is_some() {
state.in_water = true;
} else {
state.in_water = false;
}
}
}
@ -156,8 +163,14 @@ impl MovementEventMapper {
previous_state: &PreviousEntityState,
vel: Vec3<f32>,
) -> SfxEvent {
// Match run / roll state
if physics_state.on_ground && vel.magnitude() > 0.1
// Match run / roll / swim state
if physics_state.in_fluid.is_some()
&& physics_state.in_fluid.unwrap() < 2.0
&& vel.magnitude() > 0.1
|| !previous_state.in_water && physics_state.in_fluid.is_some()
{
return SfxEvent::Swim;
} else if physics_state.on_ground && vel.magnitude() > 0.1
|| !previous_state.on_ground && physics_state.on_ground
{
return if matches!(character_state, CharacterState::Roll(_)) {

View File

@ -137,7 +137,11 @@ impl SfxEventItem {
pub enum SfxEvent {
Embers,
Birdcall,
Cricket,
Frog,
Bees,
Idle,
Swim,
Run,
Roll,
Sneak,