Merge branch 'shandley/fix-glider-close-sfx' into 'master'

Fix the glider_close sfx event

See merge request veloren/veloren!678
This commit is contained in:
Acrimon 2019-12-09 09:50:14 +00:00
commit 47b480eac6
3 changed files with 20 additions and 56 deletions

View File

@ -4,7 +4,7 @@ use crate::audio::sfx::{SfxTriggerItem, SfxTriggers};
use client::Client; use client::Client;
use common::{ use common::{
comp::{ActionState, Body, CharacterState, ItemKind, MovementState, Pos, Stats, Vel}, comp::{ActionState, Body, CharacterState, ItemKind, MovementState, Pos, Stats},
event::{EventBus, SfxEvent, SfxEventItem}, event::{EventBus, SfxEvent, SfxEventItem},
}; };
use hashbrown::HashMap; use hashbrown::HashMap;
@ -38,11 +38,10 @@ impl SfxEventMapper {
.get(client.entity()) .get(client.entity())
.map_or(Vec3::zero(), |pos| pos.0); .map_or(Vec3::zero(), |pos| pos.0);
for (entity, pos, body, vel, stats, character) in ( for (entity, pos, body, stats, character) in (
&ecs.entities(), &ecs.entities(),
&ecs.read_storage::<Pos>(), &ecs.read_storage::<Pos>(),
&ecs.read_storage::<Body>(), &ecs.read_storage::<Body>(),
&ecs.read_storage::<Vel>(),
&ecs.read_storage::<Stats>(), &ecs.read_storage::<Stats>(),
ecs.read_storage::<CharacterState>().maybe(), ecs.read_storage::<CharacterState>().maybe(),
) )
@ -51,7 +50,7 @@ impl SfxEventMapper {
(e_pos.0.distance_squared(player_position)) < SFX_DIST_LIMIT_SQR (e_pos.0.distance_squared(player_position)) < SFX_DIST_LIMIT_SQR
}) })
{ {
if let (pos, body, Some(character), stats, vel) = (pos, body, character, stats, vel) { if let (pos, body, Some(character), stats) = (pos, body, character, stats) {
let state = self let state = self
.event_history .event_history
.entry(entity) .entry(entity)
@ -62,10 +61,10 @@ impl SfxEventMapper {
let mapped_event = match body { let mapped_event = match body {
Body::Humanoid(_) => { Body::Humanoid(_) => {
Self::map_character_event(character, state.event.clone(), vel.0, stats) Self::map_character_event(character, state.event.clone(), stats)
} }
Body::QuadrupedMedium(_) => { Body::QuadrupedMedium(_) => {
Self::map_quadriped_event(character, state.event.clone(), vel.0, stats) Self::map_quadriped_event(character, state.event.clone(), stats)
} }
_ => SfxEvent::Idle, _ => SfxEvent::Idle,
}; };
@ -133,17 +132,15 @@ impl SfxEventMapper {
fn map_quadriped_event( fn map_quadriped_event(
current_event: &CharacterState, current_event: &CharacterState,
previous_event: SfxEvent, previous_event: SfxEvent,
vel: Vec3<f32>,
stats: &Stats, stats: &Stats,
) -> SfxEvent { ) -> SfxEvent {
match ( match (
current_event.movement, current_event.movement,
current_event.action, current_event.action,
previous_event, previous_event,
vel,
stats, stats,
) { ) {
(_, ActionState::Attack { .. }, _, _, stats) => match stats.name.as_ref() { (_, ActionState::Attack { .. }, _, stats) => match stats.name.as_ref() {
"Wolf" => SfxEvent::AttackWolf, "Wolf" => SfxEvent::AttackWolf,
_ => SfxEvent::Idle, _ => SfxEvent::Idle,
}, },
@ -154,28 +151,21 @@ impl SfxEventMapper {
fn map_character_event( fn map_character_event(
current_event: &CharacterState, current_event: &CharacterState,
previous_event: SfxEvent, previous_event: SfxEvent,
vel: Vec3<f32>,
stats: &Stats, stats: &Stats,
) -> SfxEvent { ) -> SfxEvent {
match ( match (
current_event.movement, current_event.movement,
current_event.action, current_event.action,
previous_event, previous_event,
vel,
stats, stats,
) { ) {
(_, ActionState::Roll { .. }, ..) => SfxEvent::Roll, (_, ActionState::Roll { .. }, ..) => SfxEvent::Roll,
(MovementState::Climb, ..) => SfxEvent::Climb, (MovementState::Climb, ..) => SfxEvent::Climb,
(MovementState::Swim, ..) => SfxEvent::Swim, (MovementState::Swim, ..) => SfxEvent::Swim,
(MovementState::Run, ..) => SfxEvent::Run, (MovementState::Run, ..) => SfxEvent::Run,
(MovementState::Jump, _, previous_event, vel, _) => { (MovementState::Fall, _, previous_event, _) => {
// MovementState::Jump only indicates !on_ground
if previous_event != SfxEvent::Glide { if previous_event != SfxEvent::Glide {
if vel.z > 0.0 { SfxEvent::Fall
SfxEvent::Jump
} else {
SfxEvent::Fall
}
} else { } else {
SfxEvent::GliderClose SfxEvent::GliderClose
} }
@ -187,7 +177,7 @@ impl SfxEventMapper {
SfxEvent::Glide SfxEvent::Glide
} }
} }
(_, ActionState::Attack { .. }, _, _, stats) => { (_, ActionState::Attack { .. }, _, stats) => {
match &stats.equipment.main.as_ref().map(|i| &i.kind) { match &stats.equipment.main.as_ref().map(|i| &i.kind) {
Some(ItemKind::Tool { kind, .. }) => SfxEvent::Attack(*kind), Some(ItemKind::Tool { kind, .. }) => SfxEvent::Attack(*kind),
_ => SfxEvent::Idle, _ => SfxEvent::Idle,
@ -287,7 +277,6 @@ mod tests {
action: ActionState::Idle, action: ActionState::Idle,
}, },
SfxEvent::Idle, SfxEvent::Idle,
Vec3::zero(),
&stats, &stats,
); );
@ -304,7 +293,6 @@ mod tests {
action: ActionState::Idle, action: ActionState::Idle,
}, },
SfxEvent::Idle, SfxEvent::Idle,
Vec3::zero(),
&stats, &stats,
); );
@ -323,7 +311,6 @@ mod tests {
movement: MovementState::Run, movement: MovementState::Run,
}, },
SfxEvent::Run, SfxEvent::Run,
Vec3::zero(),
&stats, &stats,
); );
@ -331,38 +318,19 @@ mod tests {
} }
#[test] #[test]
fn maps_jump_or_fall() { fn maps_fall() {
let stats = Stats::new(String::from("Test"), None); let stats = Stats::new(String::from("Test"), None);
// positive z velocity, the character is on the rise (jumping) let result = SfxEventMapper::map_character_event(
let vel_jumping = Vec3::new(0.0, 0.0, 1.0);
let positive_result = SfxEventMapper::map_character_event(
&CharacterState { &CharacterState {
movement: MovementState::Jump, movement: MovementState::Fall,
action: ActionState::Idle, action: ActionState::Idle,
}, },
SfxEvent::Idle, SfxEvent::Idle,
vel_jumping,
&stats, &stats,
); );
assert_eq!(positive_result, SfxEvent::Jump); assert_eq!(result, SfxEvent::Fall);
// negative z velocity, the character is on the way down (!jumping)
let vel_falling = Vec3::new(0.0, 0.0, -1.0);
let negative_result = SfxEventMapper::map_character_event(
&CharacterState {
movement: MovementState::Jump,
action: ActionState::Idle,
},
SfxEvent::Idle,
vel_falling,
&stats,
);
assert_eq!(negative_result, SfxEvent::Fall);
} }
#[test] #[test]
@ -375,7 +343,6 @@ mod tests {
action: ActionState::Idle, action: ActionState::Idle,
}, },
SfxEvent::Jump, SfxEvent::Jump,
Vec3::zero(),
&stats, &stats,
); );
@ -392,7 +359,6 @@ mod tests {
action: ActionState::Idle, action: ActionState::Idle,
}, },
SfxEvent::Glide, SfxEvent::Glide,
Vec3::zero(),
&stats, &stats,
); );
@ -405,11 +371,10 @@ mod tests {
let result = SfxEventMapper::map_character_event( let result = SfxEventMapper::map_character_event(
&CharacterState { &CharacterState {
movement: MovementState::Jump, movement: MovementState::Fall,
action: ActionState::Idle, action: ActionState::Idle,
}, },
SfxEvent::Glide, SfxEvent::Glide,
Vec3::zero(),
&stats, &stats,
); );
@ -434,7 +399,6 @@ mod tests {
}, },
}, },
SfxEvent::Idle, SfxEvent::Idle,
Vec3::zero(),
&stats, &stats,
); );

View File

@ -11,7 +11,8 @@ fn main() {
let _nz_x = SuperSimplex::new().set_seed(0); let _nz_x = SuperSimplex::new().set_seed(0);
let _nz_y = SuperSimplex::new().set_seed(1); let _nz_y = SuperSimplex::new().set_seed(1);
let mut time = 0.0f64; let mut _time = 0.0f64;
while win.is_open() { while win.is_open() {
let mut buf = vec![0; W * H]; let mut buf = vec![0; W * H];
@ -35,6 +36,6 @@ fn main() {
win.update_with_buffer(&buf).unwrap(); win.update_with_buffer(&buf).unwrap();
time += 1.0 / 60.0; _time += 1.0 / 60.0;
} }
} }

View File

@ -1,7 +1,6 @@
use vek::*; use vek::*;
use veloren_world::{ use veloren_world::{
sim::{RiverKind, WORLD_SIZE}, sim::{RiverKind, WORLD_SIZE},
util::Sampler,
World, CONFIG, World, CONFIG,
}; };
@ -17,7 +16,7 @@ fn main() {
minifb::Window::new("World Viewer", W, H, minifb::WindowOptions::default()).unwrap(); minifb::Window::new("World Viewer", W, H, minifb::WindowOptions::default()).unwrap();
let mut focus = Vec2::zero(); let mut focus = Vec2::zero();
let mut gain = 1.0; let mut _gain = 1.0;
let mut scale = (WORLD_SIZE.x / W) as i32; let mut scale = (WORLD_SIZE.x / W) as i32;
while win.is_open() { while win.is_open() {
@ -70,10 +69,10 @@ fn main() {
focus.x += spd * scale; focus.x += spd * scale;
} }
if win.is_key_down(minifb::Key::Q) { if win.is_key_down(minifb::Key::Q) {
gain += 10.0; _gain += 10.0;
} }
if win.is_key_down(minifb::Key::E) { if win.is_key_down(minifb::Key::E) {
gain -= 10.0; _gain -= 10.0;
} }
if win.is_key_down(minifb::Key::R) { if win.is_key_down(minifb::Key::R) {
scale += 1; scale += 1;