Former-commit-id: 8f0bc964e00bfd9461f752622862de5335678e5b
This commit is contained in:
Joshua Barretto 2019-05-16 20:23:45 +01:00
parent a0e685c03f
commit 7b09070fc8
12 changed files with 83 additions and 66 deletions

View File

@ -202,7 +202,8 @@ impl Client {
self.state.terrain().iter().for_each(|(key, _)| { self.state.terrain().iter().for_each(|(key, _)| {
if (Vec2::from(chunk_pos) - Vec2::from(key)) if (Vec2::from(chunk_pos) - Vec2::from(key))
.map(|e: i32| e.abs()) .map(|e: i32| e.abs())
.reduce_max() > 10 .reduce_max()
> 10
{ {
chunks_to_remove.push(key); chunks_to_remove.push(key);
} }

View File

@ -155,7 +155,8 @@ const ALL_QRACES: [Race; 6] = [
Race::Elf, Race::Elf,
Race::Human, Race::Human,
Race::Orc, Race::Orc,
Race::Undead,]; Race::Undead,
];
const ALL_QBODY_TYPES: [BodyType; 3] = [BodyType::Female, BodyType::Male, BodyType::Unspecified]; const ALL_QBODY_TYPES: [BodyType; 3] = [BodyType::Female, BodyType::Male, BodyType::Unspecified];
const ALL_QHEADS: [Pighead; 1] = [Pighead::Default]; const ALL_QHEADS: [Pighead; 1] = [Pighead::Default];
const ALL_QCHESTS: [Pigchest; 1] = [Pigchest::Default]; const ALL_QCHESTS: [Pigchest; 1] = [Pigchest::Default];
@ -170,7 +171,6 @@ pub struct QuadrupedBody {
pub pigchest: Pigchest, pub pigchest: Pigchest,
pub pigleg_l: Pigleg_l, pub pigleg_l: Pigleg_l,
pub pigleg_r: Pigleg_r, pub pigleg_r: Pigleg_r,
} }
impl QuadrupedBody { impl QuadrupedBody {

View File

@ -59,7 +59,8 @@ impl<'a> System<'a> for Sys {
if control.gliding && vel.0.z < 0.0 { if control.gliding && vel.0.z < 0.0 {
// TODO: Don't hard-code this // TODO: Don't hard-code this
let anti_grav = 9.81 * 3.95 + vel.0.z.powf(2.0) * 0.2; let anti_grav = 9.81 * 3.95 + vel.0.z.powf(2.0) * 0.2;
vel.0.z += dt.0 * anti_grav * Vec2::<f32>::from(vel.0 * 0.15).magnitude().min(1.0); vel.0.z +=
dt.0 * anti_grav * Vec2::<f32>::from(vel.0 * 0.15).magnitude().min(1.0);
(true, 0.008) (true, 0.008)
} else { } else {
@ -68,7 +69,14 @@ impl<'a> System<'a> for Sys {
}; };
// Friction // Friction
vel.0 -= Vec2::broadcast(dt.0) * 50.0 * vel.0.map(|e| (e.abs() * friction * (vel.0.magnitude() * 0.1 + 0.5)).min(e.abs()).copysign(e)) * Vec3::new(1.0, 1.0, 0.0); vel.0 -= Vec2::broadcast(dt.0)
* 50.0
* vel.0.map(|e| {
(e.abs() * friction * (vel.0.magnitude() * 0.1 + 0.5))
.min(e.abs())
.copysign(e)
})
* Vec3::new(1.0, 1.0, 0.0);
if vel.0.magnitude_squared() != 0.0 { if vel.0.magnitude_squared() != 0.0 {
dir.0 = vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0); dir.0 = vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0);

View File

@ -33,7 +33,6 @@ impl Animation for GlidingAnimation {
let waveveryslowalt = (anim_time as f32 * 2.5).sin(); let waveveryslowalt = (anim_time as f32 * 2.5).sin();
let waveveryslowcos = (anim_time as f32 * 3.0).cos(); let waveveryslowcos = (anim_time as f32 * 3.0).cos();
let wave_slowtest = (anim_time as f32).min(PI / 2.0).sin(); let wave_slowtest = (anim_time as f32).min(PI / 2.0).sin();
let head_look = Vec2::new( let head_look = Vec2::new(
@ -49,7 +48,8 @@ impl Animation for GlidingAnimation {
* 0.25, * 0.25,
); );
next.head.offset = Vec3::new(5.5, 2.0, 12.0); next.head.offset = Vec3::new(5.5, 2.0, 12.0);
next.head.ori = Quaternion::rotation_x(0.35 - waveveryslow * 0.10 + head_look.y) * Quaternion::rotation_z(head_look.x + waveveryslowcos * 0.15); next.head.ori = Quaternion::rotation_x(0.35 - waveveryslow * 0.10 + head_look.y)
* Quaternion::rotation_z(head_look.x + waveveryslowcos * 0.15);
next.head.scale = Vec3::one(); next.head.scale = Vec3::one();
next.chest.offset = Vec3::new(5.5, 0.0, 8.0); next.chest.offset = Vec3::new(5.5, 0.0, 8.0);
@ -73,11 +73,13 @@ impl Animation for GlidingAnimation {
next.r_hand.scale = Vec3::one(); next.r_hand.scale = Vec3::one();
next.l_foot.offset = Vec3::new(-3.4, 1.0, 8.0); next.l_foot.offset = Vec3::new(-3.4, 1.0, 8.0);
next.l_foot.ori = Quaternion::rotation_x(wave_stop * -0.7 - wavecos_slow * -0.21 + waveveryslow * 0.19); next.l_foot.ori =
Quaternion::rotation_x(wave_stop * -0.7 - wavecos_slow * -0.21 + waveveryslow * 0.19);
next.l_foot.scale = Vec3::one(); next.l_foot.scale = Vec3::one();
next.r_foot.offset = Vec3::new(3.4, 1.0, 8.0); next.r_foot.offset = Vec3::new(3.4, 1.0, 8.0);
next.r_foot.ori = Quaternion::rotation_x(wave_stop * -0.8 + waveslow * -0.25 + waveveryslowalt * 0.13); next.r_foot.ori =
Quaternion::rotation_x(wave_stop * -0.8 + waveslow * -0.25 + waveveryslowalt * 0.13);
next.r_foot.scale = Vec3::one(); next.r_foot.scale = Vec3::one();
next.weapon.offset = Vec3::new(-5.0, -6.0, 19.0); next.weapon.offset = Vec3::new(-5.0, -6.0, 19.0);

View File

@ -1,14 +1,13 @@
pub mod gliding;
pub mod idle; pub mod idle;
pub mod jump; pub mod jump;
pub mod run; pub mod run;
pub mod gliding;
// Reexports // Reexports
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::run::RunAnimation;
pub use self::gliding::GlidingAnimation;
// Crate // Crate
use crate::render::FigureBoneData; use crate::render::FigureBoneData;

View File

@ -44,7 +44,8 @@ impl Animation for IdleAnimation {
); );
next.pighead.offset = Vec3::new(0.0, -2.0, -1.5 + wave * 0.2) / 11.0; next.pighead.offset = Vec3::new(0.0, -2.0, -1.5 + wave * 0.2) / 11.0;
next.pighead.ori = Quaternion::rotation_z(pighead_look.x) * Quaternion::rotation_x(pighead_look.y + wavecos_slow * 0.03); next.pighead.ori = Quaternion::rotation_z(pighead_look.x)
* Quaternion::rotation_x(pighead_look.y + wavecos_slow * 0.03);
next.pighead.scale = Vec3::one() / 10.5; next.pighead.scale = Vec3::one() / 10.5;
next.pigchest.offset = Vec3::new(wave_slow * 0.05, -9.0, 1.5 + wavecos_slow * 0.4) / 11.0; next.pigchest.offset = Vec3::new(wave_slow * 0.05, -9.0, 1.5 + wavecos_slow * 0.4) / 11.0;
@ -67,9 +68,6 @@ impl Animation for IdleAnimation {
next.pigrb_leg.ori = Quaternion::rotation_x(wave_slow * 0.08); next.pigrb_leg.ori = Quaternion::rotation_x(wave_slow * 0.08);
next.pigrb_leg.scale = Vec3::one() / 11.0; next.pigrb_leg.scale = Vec3::one() / 11.0;
next next
} }
} }

View File

@ -29,7 +29,6 @@ impl Animation for JumpAnimation {
let wave_dip = (wave_slow.abs() - 0.5).abs(); let wave_dip = (wave_slow.abs() - 0.5).abs();
let wave_stop = (anim_time as f32 * 4.5).min(PI / 2.0).sin(); let wave_stop = (anim_time as f32 * 4.5).min(PI / 2.0).sin();
next.pighead.offset = Vec3::new(0.0, 0.0, -1.5) / 11.0; next.pighead.offset = Vec3::new(0.0, 0.0, -1.5) / 11.0;
next.pighead.ori = Quaternion::rotation_x(wave_stop * 0.4); next.pighead.ori = Quaternion::rotation_x(wave_stop * 0.4);
next.pighead.scale = Vec3::one() / 10.5; next.pighead.scale = Vec3::one() / 10.5;

View File

@ -1,13 +1,11 @@
pub mod run;
pub mod idle; pub mod idle;
pub mod jump; pub mod jump;
pub mod run;
// Reexports // Reexports
pub use self::run::RunAnimation;
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;
// Crate // Crate
use crate::render::FigureBoneData; use crate::render::FigureBoneData;
@ -25,7 +23,6 @@ pub struct QuadrupedSkeleton {
pigrf_leg: Bone, pigrf_leg: Bone,
piglb_leg: Bone, piglb_leg: Bone,
pigrb_leg: Bone, pigrb_leg: Bone,
} }
impl QuadrupedSkeleton { impl QuadrupedSkeleton {

View File

@ -31,26 +31,31 @@ impl Animation for RunAnimation {
let wave_dip = (wave_slow.abs() - 0.5).abs(); let wave_dip = (wave_slow.abs() - 0.5).abs();
next.pighead.offset = Vec3::new(0.0, 0.0, -1.5 + wave * 1.5) / 11.0; next.pighead.offset = Vec3::new(0.0, 0.0, -1.5 + wave * 1.5) / 11.0;
next.pighead.ori = Quaternion::rotation_x(0.2 + wave * 0.05) * Quaternion::rotation_y(wavecos * 0.03); next.pighead.ori =
Quaternion::rotation_x(0.2 + wave * 0.05) * Quaternion::rotation_y(wavecos * 0.03);
next.pighead.scale = Vec3::one() / 10.5; next.pighead.scale = Vec3::one() / 10.5;
next.pigchest.offset = Vec3::new(0.0, -9.0, 1.5 + wavecos * 1.2) / 11.0; next.pigchest.offset = Vec3::new(0.0, -9.0, 1.5 + wavecos * 1.2) / 11.0;
next.pigchest.ori = Quaternion::rotation_x(wave * 0.1); next.pigchest.ori = Quaternion::rotation_x(wave * 0.1);
next.pigchest.scale = Vec3::one() / 11.0; next.pigchest.scale = Vec3::one() / 11.0;
next.piglf_leg.offset = Vec3::new(-4.5, 2.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0; next.piglf_leg.offset =
Vec3::new(-4.5, 2.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0;
next.piglf_leg.ori = Quaternion::rotation_x(wavequick * 0.3); next.piglf_leg.ori = Quaternion::rotation_x(wavequick * 0.3);
next.piglf_leg.scale = Vec3::one() / 11.0; next.piglf_leg.scale = Vec3::one() / 11.0;
next.pigrf_leg.offset = Vec3::new(2.5, 2.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0; next.pigrf_leg.offset =
Vec3::new(2.5, 2.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0;
next.pigrf_leg.ori = Quaternion::rotation_x(wavequickcos * -0.3); next.pigrf_leg.ori = Quaternion::rotation_x(wavequickcos * -0.3);
next.pigrf_leg.scale = Vec3::one() / 11.0; next.pigrf_leg.scale = Vec3::one() / 11.0;
next.piglb_leg.offset = Vec3::new(-4.5, -3.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0; next.piglb_leg.offset =
Vec3::new(-4.5, -3.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0;
next.piglb_leg.ori = Quaternion::rotation_x(wavequickcos * -0.3); next.piglb_leg.ori = Quaternion::rotation_x(wavequickcos * -0.3);
next.piglb_leg.scale = Vec3::one() / 11.0; next.piglb_leg.scale = Vec3::one() / 11.0;
next.pigrb_leg.offset = Vec3::new(2.5, -3.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0; next.pigrb_leg.offset =
Vec3::new(2.5, -3.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0;
next.pigrb_leg.ori = Quaternion::rotation_x(wavequick * 0.3); next.pigrb_leg.ori = Quaternion::rotation_x(wavequick * 0.3);
next.pigrb_leg.scale = Vec3::one() / 11.0; next.pigrb_leg.scale = Vec3::one() / 11.0;

View File

@ -7,11 +7,7 @@ use crate::{
Direction, GlobalState, PlayState, PlayStateResult, Direction, GlobalState, PlayState, PlayStateResult,
}; };
use client::{self, Client}; use client::{self, Client};
use common::{ use common::{clock::Clock, comp, msg::ClientMsg};
comp,
clock::Clock,
msg::ClientMsg,
};
use scene::Scene; use scene::Scene;
use std::{cell::RefCell, rc::Rc, time::Duration}; use std::{cell::RefCell, rc::Rc, time::Duration};
use ui::CharSelectionUi; use ui::CharSelectionUi;

View File

@ -99,8 +99,12 @@ impl Scene {
); );
self.figure_state.skeleton_mut().interpolate(&tgt_skeleton); self.figure_state.skeleton_mut().interpolate(&tgt_skeleton);
self.figure_state self.figure_state.update(
.update(renderer, Vec3::zero(), -Vec3::unit_y(), Rgba::broadcast(1.0)); renderer,
Vec3::zero(),
-Vec3::unit_y(),
Rgba::broadcast(1.0),
);
} }
pub fn render(&mut self, renderer: &mut Renderer, client: &Client) { pub fn render(&mut self, renderer: &mut Renderer, client: &Client) {

View File

@ -15,8 +15,11 @@ use common::{
assets, assets,
comp::{ comp::{
self, self,
actor::{Belt, Chest, Foot, Hand, Head, Pants, Shoulder, Weapon, Draw, Pighead, Pigchest, Pigleg_l, Pigleg_r}, actor::{
Body, HumanoidBody, QuadrupedBody Belt, Chest, Draw, Foot, Hand, Head, Pants, Pigchest, Pighead, Pigleg_l, Pigleg_r,
Shoulder, Weapon,
},
Body, HumanoidBody, QuadrupedBody,
}, },
figure::Segment, figure::Segment,
msg, msg,
@ -230,11 +233,8 @@ impl FigureModelCache {
Self::load_mesh( Self::load_mesh(
match draw { match draw {
Draw::Default => "glider.vox", Draw::Default => "glider.vox",
}, },
Vec3::new(-26.0, -26.0, -5.0) Vec3::new(-26.0, -26.0, -5.0),
) )
} }
@ -293,7 +293,6 @@ impl FigureModelCache {
} }
} }
pub struct FigureMgr { pub struct FigureMgr {
model_cache: FigureModelCache, model_cache: FigureModelCache,
character_states: HashMap<EcsEntity, FigureState<CharacterSkeleton>>, character_states: HashMap<EcsEntity, FigureState<CharacterSkeleton>>,
@ -350,17 +349,19 @@ impl FigureMgr {
time, time,
animation_history.time, animation_history.time,
), ),
comp::Animation::Gliding => character::GlidingAnimation::update_skeleton( comp::Animation::Gliding => {
character::GlidingAnimation::update_skeleton(
state.skeleton_mut(), state.skeleton_mut(),
time, time,
animation_history.time, animation_history.time,
), )
}
}; };
state.skeleton.interpolate(&target_skeleton); state.skeleton.interpolate(&target_skeleton);
state.update(renderer, pos.0, dir.0, Rgba::white()); state.update(renderer, pos.0, dir.0, Rgba::white());
}, }
Body::Quadruped(body) => { Body::Quadruped(body) => {
let state = self.quadruped_states.entry(entity).or_insert_with(|| { let state = self.quadruped_states.entry(entity).or_insert_with(|| {
FigureState::new(renderer, QuadrupedSkeleton::new()) FigureState::new(renderer, QuadrupedSkeleton::new())
@ -392,21 +393,21 @@ impl FigureMgr {
// Change in health as color! // Change in health as color!
let col = stats let col = stats
.and_then(|stats| stats.hp.last_change) .and_then(|stats| stats.hp.last_change)
.map(|(change_by, change_time)| { .map(|(change_by, change_time)| Rgba::new(1.0, 0.7, 0.7, 1.0))
Rgba::new(1.0, 0.7, 0.7, 1.0)
})
.unwrap_or(Rgba::broadcast(1.0)); .unwrap_or(Rgba::broadcast(1.0));
state.update(renderer, pos.0, dir.0, col); state.update(renderer, pos.0, dir.0, col);
}, }
}, },
// TODO: Non-character actors // TODO: Non-character actors
} }
} }
// Clear states that have dead entities // Clear states that have dead entities
self.character_states.retain(|entity, _| ecs.entities().is_alive(*entity)); self.character_states
self.quadruped_states.retain(|entity, _| ecs.entities().is_alive(*entity)); .retain(|entity, _| ecs.entities().is_alive(*entity));
self.quadruped_states
.retain(|entity, _| ecs.entities().is_alive(*entity));
} }
pub fn render( pub fn render(
@ -422,19 +423,20 @@ impl FigureMgr {
match actor { match actor {
comp::Actor::Character { body, .. } => { comp::Actor::Character { body, .. } => {
if let Some((locals, bone_consts)) = match body { if let Some((locals, bone_consts)) = match body {
Body::Humanoid(_) => self.character_states.get(&entity).map(|state| (state.locals(), state.bone_consts())), Body::Humanoid(_) => self
Body::Quadruped(_) => self.quadruped_states.get(&entity).map(|state| (state.locals(), state.bone_consts())), .character_states
.get(&entity)
.map(|state| (state.locals(), state.bone_consts())),
Body::Quadruped(_) => self
.quadruped_states
.get(&entity)
.map(|state| (state.locals(), state.bone_consts())),
} { } {
let model = self.model_cache.get_or_create_model(renderer, *body, tick); let model = self.model_cache.get_or_create_model(renderer, *body, tick);
renderer.render_figure( renderer.render_figure(model, globals, locals, bone_consts);
model, }
globals,
locals,
bone_consts,
);
} }
},
} }
} }
} }
@ -457,7 +459,13 @@ impl<S: Skeleton> FigureState<S> {
} }
} }
pub fn update(&mut self, renderer: &mut Renderer, pos: Vec3<f32>, dir: Vec3<f32>, col: Rgba<f32>) { pub fn update(
&mut self,
renderer: &mut Renderer,
pos: Vec3<f32>,
dir: Vec3<f32>,
col: Rgba<f32>,
) {
let mat = Mat4::<f32>::identity() let mat = Mat4::<f32>::identity()
* Mat4::translation_3d(pos) * Mat4::translation_3d(pos)
* Mat4::rotation_z(-dir.x.atan2(dir.y)); // + f32::consts::PI / 2.0); * Mat4::rotation_z(-dir.x.atan2(dir.y)); // + f32::consts::PI / 2.0);