mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Begin sending audio events from animation events
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
use super::{super::{Animation, AnimationEventItem}, CharacterSkeleton, SkeletonAttr};
|
use super::{super::{Animation, AnimationEvent, AnimationEventItem}, CharacterSkeleton, SkeletonAttr};
|
||||||
use common::comp::item::{Hands, ToolKind};
|
use common::comp::item::{Hands, ToolKind};
|
||||||
use std::{f32::consts::PI, ops::Mul};
|
use std::{f32::consts::PI, ops::Mul};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
@ -34,7 +34,7 @@ impl Animation for RunAnimation {
|
|||||||
) -> (Self::Skeleton, VecDeque<AnimationEventItem>) {
|
) -> (Self::Skeleton, VecDeque<AnimationEventItem>) {
|
||||||
let mut next = (*skeleton).clone();
|
let mut next = (*skeleton).clone();
|
||||||
|
|
||||||
let speed = Vec2::<f32>::from(velocity).magnitude();
|
let speed = Vec2::<f32>::from(velocity).magnitude() / 3.0;
|
||||||
*rate = 1.0;
|
*rate = 1.0;
|
||||||
let impact = (avg_vel.z).max(-8.0);
|
let impact = (avg_vel.z).max(-8.0);
|
||||||
|
|
||||||
@ -266,6 +266,15 @@ impl Animation for RunAnimation {
|
|||||||
(_, _) => Vec3::zero(),
|
(_, _) => Vec3::zero(),
|
||||||
};
|
};
|
||||||
|
|
||||||
(next, VecDeque::new())
|
let mut animation_events = VecDeque::new();
|
||||||
|
|
||||||
|
// if anim_time.rem_euclid(0.5) < 0.01 {
|
||||||
|
// if (footrotl).abs() < (0.05) {
|
||||||
|
if (footvertl).abs() < 0.05 {
|
||||||
|
let pos = next.l_foot.offset;
|
||||||
|
animation_events.push_back(AnimationEventItem::new(AnimationEvent::Step, pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
(next, animation_events)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ pub trait Animation {
|
|||||||
f64,
|
f64,
|
||||||
&mut f32,
|
&mut f32,
|
||||||
&<Self::Skeleton as Skeleton>::Attr,
|
&<Self::Skeleton as Skeleton>::Attr,
|
||||||
) -> Self::Skeleton,
|
) -> (Self::Skeleton, VecDeque<AnimationEventItem>),
|
||||||
> = unsafe {
|
> = unsafe {
|
||||||
//let start = std::time::Instant::now();
|
//let start = std::time::Instant::now();
|
||||||
// Overhead of 0.5-5 us (could use hashmap to mitigate if this is an issue)
|
// Overhead of 0.5-5 us (could use hashmap to mitigate if this is an issue)
|
||||||
|
@ -156,7 +156,7 @@ impl MovementEventMapper {
|
|||||||
return if character_state.is_dodge() {
|
return if character_state.is_dodge() {
|
||||||
SfxEvent::Roll
|
SfxEvent::Roll
|
||||||
} else {
|
} else {
|
||||||
SfxEvent::Run
|
SfxEvent::Idle
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ pub use cache::FigureModelCache;
|
|||||||
pub use load::load_mesh; // TODO: Don't make this public.
|
pub use load::load_mesh; // TODO: Don't make this public.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
audio::sfx::{SfxEvent, SfxEventItem},
|
||||||
ecs::comp::Interpolated,
|
ecs::comp::Interpolated,
|
||||||
render::{Consts, FigureBoneData, FigureLocals, Globals, Light, Renderer, Shadow},
|
render::{Consts, FigureBoneData, FigureLocals, Globals, Light, Renderer, Shadow},
|
||||||
scene::{
|
scene::{
|
||||||
@ -13,6 +14,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anim::{
|
use anim::{
|
||||||
|
AnimationEvent,
|
||||||
biped_large::BipedLargeSkeleton, bird_medium::BirdMediumSkeleton,
|
biped_large::BipedLargeSkeleton, bird_medium::BirdMediumSkeleton,
|
||||||
bird_small::BirdSmallSkeleton, character::CharacterSkeleton, critter::CritterSkeleton,
|
bird_small::BirdSmallSkeleton, character::CharacterSkeleton, critter::CritterSkeleton,
|
||||||
dragon::DragonSkeleton, fish_medium::FishMediumSkeleton, fish_small::FishSmallSkeleton,
|
dragon::DragonSkeleton, fish_medium::FishMediumSkeleton, fish_small::FishSmallSkeleton,
|
||||||
@ -25,6 +27,7 @@ use common::{
|
|||||||
item::ItemKind, Body, CharacterState, Last, LightAnimation, LightEmitter, Loadout, Ori,
|
item::ItemKind, Body, CharacterState, Last, LightAnimation, LightEmitter, Loadout, Ori,
|
||||||
PhysicsState, Pos, Scale, Stats, Vel,
|
PhysicsState, Pos, Scale, Stats, Vel,
|
||||||
},
|
},
|
||||||
|
event::EventBus,
|
||||||
state::{DeltaTime, State},
|
state::{DeltaTime, State},
|
||||||
states::triple_strike,
|
states::triple_strike,
|
||||||
terrain::TerrainChunk,
|
terrain::TerrainChunk,
|
||||||
@ -32,10 +35,10 @@ use common::{
|
|||||||
};
|
};
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use specs::{Entity as EcsEntity, Join, WorldExt};
|
use specs::{Entity as EcsEntity, Join, WorldExt};
|
||||||
|
use std::collections::VecDeque;
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
use treeculler::{BVol, BoundingSphere};
|
use treeculler::{BVol, BoundingSphere};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
use std::collections::VecDeque;
|
|
||||||
|
|
||||||
const DAMAGE_FADE_COEFFICIENT: f64 = 5.0;
|
const DAMAGE_FADE_COEFFICIENT: f64 = 5.0;
|
||||||
const MOVING_THRESHOLD: f32 = 0.7;
|
const MOVING_THRESHOLD: f32 = 0.7;
|
||||||
@ -185,6 +188,7 @@ impl FigureMgr {
|
|||||||
let time = state.get_time();
|
let time = state.get_time();
|
||||||
let tick = scene_data.tick;
|
let tick = scene_data.tick;
|
||||||
let ecs = state.ecs();
|
let ecs = state.ecs();
|
||||||
|
let audio_events = ecs.read_resource::<EventBus<SfxEventItem>>();
|
||||||
let view_distance = scene_data.view_distance;
|
let view_distance = scene_data.view_distance;
|
||||||
let dt = state.get_delta_time();
|
let dt = state.get_delta_time();
|
||||||
let frustum = camera.frustum();
|
let frustum = camera.frustum();
|
||||||
@ -885,6 +889,15 @@ impl FigureMgr {
|
|||||||
true,
|
true,
|
||||||
is_player,
|
is_player,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
for event in animation_events {
|
||||||
|
match &event.event {
|
||||||
|
AnimationEvent::Step => {
|
||||||
|
let ev_pos = pos.0 + event.pos;
|
||||||
|
audio_events.emit_now(SfxEventItem::new(SfxEvent::Run, Some(ev_pos), Some(0.9)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Body::QuadrupedSmall(_) => {
|
Body::QuadrupedSmall(_) => {
|
||||||
let skeleton_attr = &self
|
let skeleton_attr = &self
|
||||||
|
Reference in New Issue
Block a user