Merge branch 'update-controller' into 'master'

Update controller

See merge request veloren/veloren!679
This commit is contained in:
Acrimon 2019-12-09 14:45:10 +00:00
commit 7cb177bb44
5 changed files with 61 additions and 43 deletions

View File

@ -17,11 +17,24 @@ pub enum MovementState {
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub enum ActionState {
Idle,
Wield { time_left: Duration },
Attack { time_left: Duration, applied: bool },
Block { time_active: Duration },
Roll { time_left: Duration },
Charge { time_left: Duration },
Wield {
time_left: Duration,
},
Attack {
time_left: Duration,
applied: bool,
},
Block {
time_active: Duration,
},
Roll {
time_left: Duration,
// Whether character was wielding before they started roll
was_wielding: bool,
},
Charge {
time_left: Duration,
},
//Carry,
}
@ -38,7 +51,7 @@ impl ActionState {
match self {
Self::Wield { time_left }
| Self::Attack { time_left, .. }
| Self::Roll { time_left }
| Self::Roll { time_left, .. }
| Self::Charge { time_left } => *time_left == Duration::default(),
Self::Idle | Self::Block { .. } => false,
}

View File

@ -329,20 +329,17 @@ impl<'a> System<'a> for Sys {
continue;
}
inputs.update_look_dir();
inputs.update_move_dir();
match (character.action, character.movement) {
// Jumping, one frame state that calls jump server event
(_, Jump) => {
inputs.update_look_dir();
inputs.update_move_dir();
character.movement = get_state_from_move_dir(&inputs.move_dir);
character.movement = Fall;
local_emitter.emit(LocalEvent::Jump(entity));
}
// Charging + Any Movement, prioritizes finishing charge
// over movement states
(Charge { time_left }, _) => {
println!("{:?}", character);
inputs.update_move_dir();
if time_left == Duration::default() || vel.0.magnitude_squared() < 10.0 {
character.action = try_wield(stats);
@ -367,22 +364,35 @@ impl<'a> System<'a> for Sys {
}
// Rolling + Any Movement, prioritizes finishing charge
// over movement states
(Roll { time_left }, _) => {
(
Roll {
time_left,
was_wielding,
},
_,
) => {
if time_left == Duration::default() {
character.action = try_wield(stats);
if was_wielding {
character.action = try_wield(stats);
} else {
character.action = Idle;
}
} else {
character.action = Roll {
time_left: time_left
.checked_sub(Duration::from_secs_f32(dt.0))
.unwrap_or_default(),
was_wielding,
}
}
}
// Any Action + Falling
(action_state, Fall) => {
inputs.update_move_dir();
inputs.update_look_dir();
character.movement = get_state_from_move_dir(&inputs.move_dir);
// character.movement = get_state_from_move_dir(&inputs.move_dir);
if inputs.glide.is_pressed() && !inputs.glide.is_held_down() {
character.movement = Glide;
continue;
}
// Reset to Falling while not standing on ground,
// otherwise keep the state given above
if !physics.on_ground {
@ -391,9 +401,8 @@ impl<'a> System<'a> for Sys {
} else {
character.movement = Fall;
}
}
if inputs.glide.is_pressed() && !inputs.glide.is_held_down() {
character.movement = Glide;
} else {
character.movement = Stand;
continue;
}
@ -420,8 +429,6 @@ impl<'a> System<'a> for Sys {
}
// Any Action + Swimming
(_action_state, Swim) => {
inputs.update_move_dir();
inputs.update_look_dir();
character.movement = get_state_from_move_dir(&inputs.move_dir);
if !physics.on_ground && physics.in_fluid {
@ -451,7 +458,6 @@ impl<'a> System<'a> for Sys {
}
// Blocking, restricted look_dir compared to other states
(Block { .. }, Stand) | (Block { .. }, Run) => {
inputs.update_move_dir();
character.movement = get_state_from_move_dir(&inputs.move_dir);
if !inputs.secondary.is_pressed() {
@ -474,8 +480,6 @@ impl<'a> System<'a> for Sys {
}
// Standing and Running states, typical states :shrug:
(action_state, Run) | (action_state, Stand) => {
inputs.update_move_dir();
inputs.update_look_dir();
character.movement = get_state_from_move_dir(&inputs.move_dir);
// Try to sit
if inputs.sit.is_pressed() && physics.on_ground && body.is_humanoid() {
@ -522,6 +526,7 @@ impl<'a> System<'a> for Sys {
{
character.action = Roll {
time_left: ROLL_DURATION,
was_wielding: character.action.is_wield(),
};
continue;
}
@ -552,6 +557,7 @@ impl<'a> System<'a> for Sys {
}
Idle => {
character.action = try_wield(stats);
continue;
}
Charge { .. } | Roll { .. } | Block { .. } => {}
}
@ -579,8 +585,8 @@ impl<'a> System<'a> for Sys {
}
}
// Sitting
(Idle, Sit) => {
inputs.update_move_dir();
(_, Sit) => {
character.action = Idle;
character.movement = get_state_from_move_dir(&inputs.move_dir);
// character.movement will be Stand after updating when
@ -601,9 +607,6 @@ impl<'a> System<'a> for Sys {
(_, Glide) => {
character.action = Idle;
inputs.update_look_dir();
inputs.update_move_dir();
if !inputs.glide.is_pressed() {
character.movement = Fall;
} else if let Some(_wall_dir) = physics.on_wall {
@ -617,22 +620,23 @@ impl<'a> System<'a> for Sys {
// Any Action + Climbing, shouldnt care about action,
// because should be Idle
(_, Climb) => {
character.action = Idle;
if let None = physics.on_wall {
if physics.on_ground {
character.movement = Stand;
} else if inputs.jump.is_pressed() && !inputs.jump.is_held_down() {
if inputs.jump.is_pressed() {
character.movement = Jump;
} else {
character.movement = Fall;
}
}
}
// In case of adding new states
(_, _) => {
println!("UNKNOWN STATE");
character.action = Idle;
character.movement = Fall;
}
if physics.on_ground {
character.movement = Stand;
}
} // In case of adding new states
// (_, _) => {
// println!("UNKNOWN STATE");
// character.action = Idle;
// character.movement = Fall;
// }
};
// Process other controller events

View File

@ -12,7 +12,7 @@ use sphynx::Uid;
use std::time::Duration;
use vek::*;
pub const ROLL_DURATION: Duration = Duration::from_millis(250);
pub const ROLL_DURATION: Duration = Duration::from_millis(600);
const HUMANOID_ACCEL: f32 = 50.0;
const HUMANOID_SPEED: f32 = 120.0;
@ -150,7 +150,7 @@ impl<'a> System<'a> for Sys {
(false, Glide) if vel.0.magnitude_squared() < GLIDE_SPEED.powf(2.0) => {
GLIDE_ACCEL
}
(false, Jump)
(false, Fall) | (false, Jump)
if vel.0.magnitude_squared() < HUMANOID_AIR_SPEED.powf(2.0) =>
{
HUMANOID_AIR_ACCEL

View File

@ -307,6 +307,7 @@ mod tests {
&CharacterState {
action: ActionState::Roll {
time_left: Duration::new(1, 0),
was_wielding: false,
},
movement: MovementState::Run,
},

View File

@ -197,7 +197,7 @@ impl FigureMgr {
}
let target_base = match &character.movement {
Fall | Stand => anim::character::StandAnimation::update_skeleton(
Stand => anim::character::StandAnimation::update_skeleton(
&CharacterSkeleton::new(),
(active_tool_kind, time),
state.movement_time,
@ -211,7 +211,7 @@ impl FigureMgr {
&mut movement_animation_rate,
skeleton_attr,
),
Jump => anim::character::JumpAnimation::update_skeleton(
Jump | Fall => anim::character::JumpAnimation::update_skeleton(
&CharacterSkeleton::new(),
(active_tool_kind, time),
state.movement_time,