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