mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fixes for .maybe() and animation
This commit is contained in:
parent
4de5489367
commit
e2c81dd036
@ -18,14 +18,14 @@ pub use animation::Animation;
|
|||||||
pub use animation::AnimationInfo;
|
pub use animation::AnimationInfo;
|
||||||
pub use controller::Controller;
|
pub use controller::Controller;
|
||||||
pub use inputs::Attacking;
|
pub use inputs::Attacking;
|
||||||
pub use inputs::Rolling;
|
|
||||||
pub use inputs::Crunning;
|
|
||||||
pub use inputs::Cidling;
|
pub use inputs::Cidling;
|
||||||
|
pub use inputs::Crunning;
|
||||||
pub use inputs::Gliding;
|
pub use inputs::Gliding;
|
||||||
pub use inputs::Jumping;
|
pub use inputs::Jumping;
|
||||||
pub use inputs::MoveDir;
|
pub use inputs::MoveDir;
|
||||||
pub use inputs::OnGround;
|
pub use inputs::OnGround;
|
||||||
pub use inputs::Respawning;
|
pub use inputs::Respawning;
|
||||||
|
pub use inputs::Rolling;
|
||||||
pub use player::Player;
|
pub use player::Player;
|
||||||
pub use stats::Dying;
|
pub use stats::Dying;
|
||||||
pub use stats::HealthSource;
|
pub use stats::HealthSource;
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{phys, Animation, AnimationInfo, Attacking, Rolling, Crunning, Cidling, Gliding, Jumping, OnGround},
|
comp::{
|
||||||
|
phys, Animation, AnimationInfo, Attacking, Cidling, Crunning, Gliding, Jumping, OnGround,
|
||||||
|
Rolling,
|
||||||
|
},
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
};
|
};
|
||||||
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
||||||
@ -23,9 +26,32 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
&mut self,
|
&mut self,
|
||||||
(entities, dt, velocities, on_grounds, jumpings, glidings, attackings, rollings, crunnings, cidlings, mut animation_infos): Self::SystemData,
|
(
|
||||||
|
entities,
|
||||||
|
dt,
|
||||||
|
velocities,
|
||||||
|
on_grounds,
|
||||||
|
jumpings,
|
||||||
|
glidings,
|
||||||
|
attackings,
|
||||||
|
rollings,
|
||||||
|
crunnings,
|
||||||
|
cidlings,
|
||||||
|
mut animation_infos,
|
||||||
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
for (entity, vel, on_ground, jumping, gliding, attacking, rolling, crunning, cidling, mut animation_info) in (
|
for (
|
||||||
|
entity,
|
||||||
|
vel,
|
||||||
|
on_ground,
|
||||||
|
jumping,
|
||||||
|
gliding,
|
||||||
|
attacking,
|
||||||
|
rolling,
|
||||||
|
crunning,
|
||||||
|
cidling,
|
||||||
|
mut animation_info,
|
||||||
|
) in (
|
||||||
&entities,
|
&entities,
|
||||||
&velocities,
|
&velocities,
|
||||||
on_grounds.maybe(),
|
on_grounds.maybe(),
|
||||||
@ -52,16 +78,23 @@ impl<'a> System<'a> for Sys {
|
|||||||
moving,
|
moving,
|
||||||
attacking.is_some(),
|
attacking.is_some(),
|
||||||
gliding.is_some(),
|
gliding.is_some(),
|
||||||
|
rolling.is_some(),
|
||||||
) {
|
) {
|
||||||
(true, false, false, false) => Animation::Idle,
|
(true, false, false, false, false) => Animation::Idle,
|
||||||
(true, true, false, false) => Animation::Run,
|
(true, true, false, false, false) => Animation::Run,
|
||||||
(false, _, false, false) => Animation::Jump,
|
(false, _, false, false, false) => Animation::Jump,
|
||||||
(_, _, false, true) => Animation::Gliding,
|
(_, _, false, true, false) => Animation::Gliding,
|
||||||
(_, _, true, false) => Animation::Attack,
|
(_, _, true, false, false) => Animation::Attack,
|
||||||
(true, true, false, false) => Animation::Roll,
|
(_, true, false, false, true) => {
|
||||||
(_, true, false, false) => Animation::Crun,
|
dbg!("roll");
|
||||||
(true, false, false, false) => Animation::Cidle,
|
Animation::Roll
|
||||||
(_, _, true, true) => impossible_animation(),
|
}
|
||||||
|
//(_, true, false, false, false) => Animation::Crun,
|
||||||
|
//(true, false, false, false, false) => Animation::Cidle,
|
||||||
|
(_, _, true, true, _) => impossible_animation(), // Attack while gliding
|
||||||
|
(_, _, true, _, true) => impossible_animation(), // Roll while attacking
|
||||||
|
(_, _, _, true, true) => impossible_animation(), // Roll while gliding
|
||||||
|
(_, false, _, _, true) => impossible_animation(), // Roll without moving
|
||||||
};
|
};
|
||||||
|
|
||||||
let last = animation_info.clone();
|
let last = animation_info.clone();
|
||||||
|
@ -16,8 +16,8 @@ impl<'a> System<'a> for Sys {
|
|||||||
ReadStorage<'a, Uid>,
|
ReadStorage<'a, Uid>,
|
||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
ReadStorage<'a, Pos>,
|
ReadStorage<'a, Pos>,
|
||||||
WriteStorage<'a, Vel>,
|
|
||||||
ReadStorage<'a, Ori>,
|
ReadStorage<'a, Ori>,
|
||||||
|
WriteStorage<'a, Vel>,
|
||||||
WriteStorage<'a, Attacking>,
|
WriteStorage<'a, Attacking>,
|
||||||
WriteStorage<'a, Stats>,
|
WriteStorage<'a, Stats>,
|
||||||
WriteStorage<'a, ForceUpdate>,
|
WriteStorage<'a, ForceUpdate>,
|
||||||
@ -30,8 +30,8 @@ impl<'a> System<'a> for Sys {
|
|||||||
uids,
|
uids,
|
||||||
dt,
|
dt,
|
||||||
positions,
|
positions,
|
||||||
mut velocities,
|
|
||||||
orientations,
|
orientations,
|
||||||
|
mut velocities,
|
||||||
mut attackings,
|
mut attackings,
|
||||||
mut stats,
|
mut stats,
|
||||||
mut force_updates,
|
mut force_updates,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{
|
comp::{
|
||||||
phys::{ForceUpdate, Ori, Pos, Vel},
|
phys::{ForceUpdate, Ori, Pos, Vel},
|
||||||
Animation, AnimationInfo, Attacking, Rolling, Crunning, Cidling, Controller, Gliding, HealthSource, Jumping, MoveDir,
|
Animation, AnimationInfo, Attacking, Cidling, Controller, Crunning, Gliding, HealthSource,
|
||||||
OnGround, Respawning, Stats,
|
Jumping, MoveDir, OnGround, Respawning, Rolling, Stats,
|
||||||
},
|
},
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
};
|
};
|
||||||
@ -17,10 +17,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
ReadStorage<'a, Controller>,
|
ReadStorage<'a, Controller>,
|
||||||
ReadStorage<'a, Stats>,
|
ReadStorage<'a, Stats>,
|
||||||
ReadStorage<'a, Pos>,
|
ReadStorage<'a, Pos>,
|
||||||
WriteStorage<'a, Vel>,
|
ReadStorage<'a, Vel>,
|
||||||
WriteStorage<'a, Ori>,
|
ReadStorage<'a, Ori>,
|
||||||
|
ReadStorage<'a, OnGround>,
|
||||||
WriteStorage<'a, MoveDir>,
|
WriteStorage<'a, MoveDir>,
|
||||||
WriteStorage<'a, OnGround>,
|
|
||||||
WriteStorage<'a, Jumping>,
|
WriteStorage<'a, Jumping>,
|
||||||
WriteStorage<'a, Attacking>,
|
WriteStorage<'a, Attacking>,
|
||||||
WriteStorage<'a, Rolling>,
|
WriteStorage<'a, Rolling>,
|
||||||
@ -28,7 +28,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
WriteStorage<'a, Cidling>,
|
WriteStorage<'a, Cidling>,
|
||||||
WriteStorage<'a, Respawning>,
|
WriteStorage<'a, Respawning>,
|
||||||
WriteStorage<'a, Gliding>,
|
WriteStorage<'a, Gliding>,
|
||||||
WriteStorage<'a, ForceUpdate>,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
@ -39,10 +38,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
controllers,
|
controllers,
|
||||||
stats,
|
stats,
|
||||||
positions,
|
positions,
|
||||||
mut velocities,
|
velocities,
|
||||||
mut orientations,
|
orientations,
|
||||||
|
on_grounds,
|
||||||
mut move_dirs,
|
mut move_dirs,
|
||||||
mut on_grounds,
|
|
||||||
mut jumpings,
|
mut jumpings,
|
||||||
mut attackings,
|
mut attackings,
|
||||||
mut rollings,
|
mut rollings,
|
||||||
@ -50,31 +49,16 @@ impl<'a> System<'a> for Sys {
|
|||||||
mut cidlings,
|
mut cidlings,
|
||||||
mut respawns,
|
mut respawns,
|
||||||
mut glidings,
|
mut glidings,
|
||||||
force_updates,
|
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
for (
|
for (entity, controller, stats, pos, vel, ori, on_ground) in (
|
||||||
entity,
|
|
||||||
controller,
|
|
||||||
stats,
|
|
||||||
pos,
|
|
||||||
mut vel,
|
|
||||||
mut ori,
|
|
||||||
on_ground,
|
|
||||||
mut attacking,
|
|
||||||
mut jumping,
|
|
||||||
mut gliding,
|
|
||||||
) in (
|
|
||||||
&entities,
|
&entities,
|
||||||
&controllers,
|
&controllers,
|
||||||
&stats,
|
&stats,
|
||||||
&positions,
|
&positions,
|
||||||
&mut velocities,
|
&velocities,
|
||||||
&mut orientations,
|
&orientations,
|
||||||
on_grounds.maybe(),
|
on_grounds.maybe(),
|
||||||
attackings.maybe(),
|
|
||||||
jumpings.maybe(),
|
|
||||||
glidings.maybe(),
|
|
||||||
)
|
)
|
||||||
.join()
|
.join()
|
||||||
{
|
{
|
||||||
@ -87,10 +71,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Glide
|
// Glide
|
||||||
if controller.glide && on_ground.is_none() && attacking.is_none() {
|
if controller.glide && on_ground.is_none() && attackings.get(entity).is_none() {
|
||||||
gliding = Some(&Gliding);
|
glidings.insert(entity, Gliding);
|
||||||
} else {
|
} else {
|
||||||
gliding = None
|
glidings.remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move dir
|
// Move dir
|
||||||
@ -104,19 +88,22 @@ impl<'a> System<'a> for Sys {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Attack
|
// Attack
|
||||||
if controller.attack && attacking.is_none() && gliding.is_none() {
|
if controller.attack
|
||||||
attacking = Some(&Attacking::start());
|
&& attackings.get(entity).is_none()
|
||||||
|
&& glidings.get(entity).is_none()
|
||||||
|
{
|
||||||
|
attackings.insert(entity, Attacking::start());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jump
|
// Jump
|
||||||
if on_ground.is_some() && controller.jump && vel.0.z <= 0.0 {
|
if on_ground.is_some() && controller.jump && vel.0.z <= 0.0 {
|
||||||
jumping = Some(&Jumping);
|
jumpings.insert(entity, Jumping);
|
||||||
} else {
|
} else {
|
||||||
jumping = None;
|
jumpings.remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Roll
|
// Roll
|
||||||
if on_grounds.get(entity).is_some() && controller.roll {
|
if on_ground.is_some() && controller.roll {
|
||||||
rollings.insert(entity, Rolling::start());
|
rollings.insert(entity, Rolling::start());
|
||||||
} else {
|
} else {
|
||||||
rollings.remove(entity);
|
rollings.remove(entity);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{
|
comp::{
|
||||||
phys::{Ori, Pos, Vel},
|
phys::{Ori, Pos, Vel},
|
||||||
Gliding, Jumping, MoveDir, OnGround, Stats, Rolling, Cidling, Crunning,
|
Cidling, Crunning, Gliding, Jumping, MoveDir, OnGround, Rolling, Stats,
|
||||||
},
|
},
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
terrain::TerrainMap,
|
terrain::TerrainMap,
|
||||||
@ -51,10 +51,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
ReadExpect<'a, TerrainMap>,
|
ReadExpect<'a, TerrainMap>,
|
||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
WriteStorage<'a, OnGround>,
|
|
||||||
WriteStorage<'a, Pos>,
|
|
||||||
WriteStorage<'a, Vel>,
|
|
||||||
WriteStorage<'a, Ori>,
|
|
||||||
ReadStorage<'a, MoveDir>,
|
ReadStorage<'a, MoveDir>,
|
||||||
ReadStorage<'a, Jumping>,
|
ReadStorage<'a, Jumping>,
|
||||||
ReadStorage<'a, Gliding>,
|
ReadStorage<'a, Gliding>,
|
||||||
@ -62,6 +58,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
ReadStorage<'a, Crunning>,
|
ReadStorage<'a, Crunning>,
|
||||||
ReadStorage<'a, Cidling>,
|
ReadStorage<'a, Cidling>,
|
||||||
ReadStorage<'a, Stats>,
|
ReadStorage<'a, Stats>,
|
||||||
|
WriteStorage<'a, OnGround>,
|
||||||
|
WriteStorage<'a, Pos>,
|
||||||
|
WriteStorage<'a, Vel>,
|
||||||
|
WriteStorage<'a, Ori>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
@ -70,10 +70,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
entities,
|
entities,
|
||||||
terrain,
|
terrain,
|
||||||
dt,
|
dt,
|
||||||
mut on_grounds,
|
|
||||||
mut positions,
|
|
||||||
mut velocities,
|
|
||||||
mut orientations,
|
|
||||||
move_dirs,
|
move_dirs,
|
||||||
jumpings,
|
jumpings,
|
||||||
glidings,
|
glidings,
|
||||||
@ -81,25 +77,39 @@ impl<'a> System<'a> for Sys {
|
|||||||
crunnings,
|
crunnings,
|
||||||
cidlings,
|
cidlings,
|
||||||
stats,
|
stats,
|
||||||
|
mut on_grounds,
|
||||||
|
mut positions,
|
||||||
|
mut velocities,
|
||||||
|
mut orientations,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
// Apply movement inputs
|
// Apply movement inputs
|
||||||
for (entity, mut pos, mut vel, mut ori, mut on_ground, move_dir, jumping, gliding, rolling, crunning, cidling, stats) in
|
for (
|
||||||
(
|
entity,
|
||||||
&entities,
|
stats,
|
||||||
&mut positions,
|
move_dir,
|
||||||
&mut velocities,
|
jumping,
|
||||||
&mut orientations,
|
gliding,
|
||||||
on_grounds.maybe(),
|
rolling,
|
||||||
move_dirs.maybe(),
|
crunning,
|
||||||
jumpings.maybe(),
|
cidling,
|
||||||
glidings.maybe(),
|
mut pos,
|
||||||
rollings.maybe(),
|
mut vel,
|
||||||
crunnings.maybe(),
|
mut ori,
|
||||||
cidlings.maybe(),
|
) in (
|
||||||
&stats,
|
&entities,
|
||||||
)
|
&stats,
|
||||||
.join()
|
move_dirs.maybe(),
|
||||||
|
jumpings.maybe(),
|
||||||
|
glidings.maybe(),
|
||||||
|
rollings.maybe(),
|
||||||
|
crunnings.maybe(),
|
||||||
|
cidlings.maybe(),
|
||||||
|
&mut positions,
|
||||||
|
&mut velocities,
|
||||||
|
&mut orientations,
|
||||||
|
)
|
||||||
|
.join()
|
||||||
{
|
{
|
||||||
// Disable while dead TODO: Replace with client states?
|
// Disable while dead TODO: Replace with client states?
|
||||||
if stats.is_dead {
|
if stats.is_dead {
|
||||||
@ -110,7 +120,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
if let Some(move_dir) = move_dir {
|
if let Some(move_dir) = move_dir {
|
||||||
vel.0 += Vec2::broadcast(dt.0)
|
vel.0 += Vec2::broadcast(dt.0)
|
||||||
* move_dir.0
|
* move_dir.0
|
||||||
* match (on_ground.is_some(), gliding.is_some()) {
|
* match (
|
||||||
|
on_grounds.get(entity).is_some(),
|
||||||
|
glidings.get(entity).is_some(),
|
||||||
|
) {
|
||||||
(true, false) if vel.0.magnitude() < HUMANOID_SPEED => HUMANOID_ACCEL,
|
(true, false) if vel.0.magnitude() < HUMANOID_SPEED => HUMANOID_ACCEL,
|
||||||
(false, true) if vel.0.magnitude() < GLIDE_SPEED => GLIDE_ACCEL,
|
(false, true) if vel.0.magnitude() < GLIDE_SPEED => GLIDE_ACCEL,
|
||||||
(false, false) if vel.0.magnitude() < HUMANOID_AIR_SPEED => {
|
(false, false) if vel.0.magnitude() < HUMANOID_AIR_SPEED => {
|
||||||
@ -151,15 +164,15 @@ impl<'a> System<'a> for Sys {
|
|||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
&& vel.0.z <= 0.0
|
&& vel.0.z <= 0.0
|
||||||
{
|
{
|
||||||
on_ground = Some(&OnGround);
|
on_grounds.insert(entity, OnGround);
|
||||||
} else {
|
} else {
|
||||||
on_ground = None;
|
on_grounds.remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Integrate forces
|
// Integrate forces
|
||||||
// Friction is assumed to be a constant dependent on location
|
// Friction is assumed to be a constant dependent on location
|
||||||
let friction = 50.0
|
let friction = 50.0
|
||||||
* if on_ground.is_some() {
|
* if on_grounds.get(entity).is_some() {
|
||||||
FRIC_GROUND
|
FRIC_GROUND
|
||||||
} else {
|
} else {
|
||||||
FRIC_AIR
|
FRIC_AIR
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
pub mod attack;
|
pub mod attack;
|
||||||
|
pub mod cidle;
|
||||||
|
pub mod crun;
|
||||||
pub mod gliding;
|
pub mod gliding;
|
||||||
pub mod idle;
|
pub mod idle;
|
||||||
pub mod jump;
|
pub mod jump;
|
||||||
pub mod run;
|
|
||||||
pub mod roll;
|
pub mod roll;
|
||||||
pub mod crun;
|
pub mod run;
|
||||||
pub mod cidle;
|
|
||||||
|
|
||||||
// Reexports
|
// Reexports
|
||||||
pub use self::attack::AttackAnimation;
|
pub use self::attack::AttackAnimation;
|
||||||
|
pub use self::cidle::CidleAnimation;
|
||||||
|
pub use self::crun::CrunAnimation;
|
||||||
pub use self::gliding::GlidingAnimation;
|
pub use self::gliding::GlidingAnimation;
|
||||||
pub use self::idle::IdleAnimation;
|
pub use self::idle::IdleAnimation;
|
||||||
pub use self::jump::JumpAnimation;
|
pub use self::jump::JumpAnimation;
|
||||||
pub use self::run::RunAnimation;
|
|
||||||
pub use self::roll::RollAnimation;
|
pub use self::roll::RollAnimation;
|
||||||
pub use self::crun::CrunAnimation;
|
pub use self::run::RunAnimation;
|
||||||
pub use self::cidle::CidleAnimation;
|
|
||||||
|
|
||||||
|
|
||||||
use super::{Bone, Skeleton};
|
use super::{Bone, Skeleton};
|
||||||
use crate::render::FigureBoneData;
|
use crate::render::FigureBoneData;
|
||||||
|
@ -34,8 +34,6 @@ pub struct ControlSettings {
|
|||||||
pub roll: KeyMouse,
|
pub roll: KeyMouse,
|
||||||
pub crun: KeyMouse,
|
pub crun: KeyMouse,
|
||||||
pub cidle: KeyMouse,
|
pub cidle: KeyMouse,
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ControlSettings {
|
impl Default for ControlSettings {
|
||||||
|
@ -141,7 +141,6 @@ impl Window {
|
|||||||
key_map.insert(settings.controls.crun, GameInput::Crun);
|
key_map.insert(settings.controls.crun, GameInput::Crun);
|
||||||
key_map.insert(settings.controls.cidle, GameInput::Cidle);
|
key_map.insert(settings.controls.cidle, GameInput::Cidle);
|
||||||
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
events_loop,
|
events_loop,
|
||||||
renderer: Renderer::new(device, factory, win_color_view, win_depth_view)?,
|
renderer: Renderer::new(device, factory, win_color_view, win_depth_view)?,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user