From 838eadda4ec99ff989b3ffc7d1f0495e8466620d Mon Sep 17 00:00:00 2001 From: jshipsey Date: Thu, 18 Jun 2020 23:33:30 -0400 Subject: [PATCH] add hotloads to all anims --- voxygen/src/anim/src/biped_large/idle.rs | 6 +- voxygen/src/anim/src/biped_large/jump.rs | 6 +- voxygen/src/anim/src/biped_large/mod.rs | 6 +- voxygen/src/anim/src/biped_large/run.rs | 6 +- voxygen/src/anim/src/bird_medium/fly.rs | 6 +- voxygen/src/anim/src/bird_medium/idle.rs | 7 +- voxygen/src/anim/src/bird_medium/mod.rs | 7 +- voxygen/src/anim/src/bird_medium/run.rs | 6 +- voxygen/src/anim/src/bird_small/idle.rs | 6 +- voxygen/src/anim/src/bird_small/jump.rs | 6 +- voxygen/src/anim/src/bird_small/mod.rs | 7 +- voxygen/src/anim/src/bird_small/run.rs | 6 +- voxygen/src/anim/src/character/alpha.rs | 6 +- voxygen/src/anim/src/character/beta.rs | 6 +- voxygen/src/anim/src/character/block.rs | 6 +- voxygen/src/anim/src/character/blockidle.rs | 6 +- voxygen/src/anim/src/character/charge.rs | 6 +- voxygen/src/anim/src/character/climb.rs | 6 +- voxygen/src/anim/src/character/dance.rs | 6 +- voxygen/src/anim/src/character/dash.rs | 6 +- voxygen/src/anim/src/character/equip.rs | 6 +- voxygen/src/anim/src/character/glidewield.rs | 308 +++++++++++++++++++ voxygen/src/anim/src/character/gliding.rs | 6 +- voxygen/src/anim/src/character/idle.rs | 6 +- voxygen/src/anim/src/character/jump.rs | 6 +- voxygen/src/anim/src/character/mod.rs | 7 +- voxygen/src/anim/src/character/roll.rs | 6 +- voxygen/src/anim/src/character/run.rs | 6 +- voxygen/src/anim/src/character/shoot.rs | 6 +- voxygen/src/anim/src/character/sit.rs | 6 +- voxygen/src/anim/src/character/spin.rs | 6 +- voxygen/src/anim/src/character/stand.rs | 6 +- voxygen/src/anim/src/character/swim.rs | 6 +- voxygen/src/anim/src/character/wield.rs | 6 +- voxygen/src/anim/src/critter/idle.rs | 6 +- voxygen/src/anim/src/critter/jump.rs | 6 +- voxygen/src/anim/src/critter/mod.rs | 7 +- voxygen/src/anim/src/critter/run.rs | 6 +- voxygen/src/anim/src/dragon/fly.rs | 6 +- voxygen/src/anim/src/dragon/idle.rs | 6 +- voxygen/src/anim/src/dragon/mod.rs | 7 +- voxygen/src/anim/src/dragon/run.rs | 6 +- voxygen/src/anim/src/fish_medium/idle.rs | 6 +- voxygen/src/anim/src/fish_medium/jump.rs | 6 +- voxygen/src/anim/src/fish_medium/mod.rs | 6 +- voxygen/src/anim/src/fish_medium/run.rs | 6 +- voxygen/src/anim/src/fish_small/idle.rs | 6 +- voxygen/src/anim/src/fish_small/jump.rs | 6 +- voxygen/src/anim/src/fish_small/mod.rs | 7 +- voxygen/src/anim/src/fish_small/run.rs | 6 +- voxygen/src/anim/src/fixture/mod.rs | 7 +- voxygen/src/anim/src/golem/idle.rs | 7 +- voxygen/src/anim/src/golem/jump.rs | 7 +- voxygen/src/anim/src/golem/mod.rs | 27 +- voxygen/src/anim/src/golem/run.rs | 7 +- voxygen/src/anim/src/lib.rs | 36 +-- voxygen/src/anim/src/object/mod.rs | 8 +- 57 files changed, 613 insertions(+), 95 deletions(-) create mode 100644 voxygen/src/anim/src/character/glidewield.rs diff --git a/voxygen/src/anim/src/biped_large/idle.rs b/voxygen/src/anim/src/biped_large/idle.rs index 79f778c92b..7c7fdfa976 100644 --- a/voxygen/src/anim/src/biped_large/idle.rs +++ b/voxygen/src/anim/src/biped_large/idle.rs @@ -8,7 +8,11 @@ impl Animation for IdleAnimation { type Dependency = f64; type Skeleton = BipedLargeSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"biped_large_idle\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_idle")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, global_time: Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/biped_large/jump.rs b/voxygen/src/anim/src/biped_large/jump.rs index 1c9d4c987c..650db18ffb 100644 --- a/voxygen/src/anim/src/biped_large/jump.rs +++ b/voxygen/src/anim/src/biped_large/jump.rs @@ -8,7 +8,11 @@ impl Animation for JumpAnimation { type Dependency = (f32, f64); type Skeleton = BipedLargeSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"biped_large_jump\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_jump")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/biped_large/mod.rs b/voxygen/src/anim/src/biped_large/mod.rs index fc85fd7b03..29405a89e9 100644 --- a/voxygen/src/anim/src/biped_large/mod.rs +++ b/voxygen/src/anim/src/biped_large/mod.rs @@ -32,9 +32,13 @@ impl BipedLargeSkeleton { impl Skeleton for BipedLargeSkeleton { type Attr = SkeletonAttr; + #[cfg(feature = "use-dyn-lib")] + const COMPUTE_FN: &'static [u8] = b"biped_large_compute_mats\0"; + fn bone_count(&self) -> usize { 11 } - fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { + #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_compute_mats")] + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { let upper_torso_mat = self.upper_torso.compute_base_matrix(); let shoulder_l_mat = self.shoulder_l.compute_base_matrix(); let shoulder_r_mat = self.shoulder_r.compute_base_matrix(); diff --git a/voxygen/src/anim/src/biped_large/run.rs b/voxygen/src/anim/src/biped_large/run.rs index 6927c85cbf..b02dade71b 100644 --- a/voxygen/src/anim/src/biped_large/run.rs +++ b/voxygen/src/anim/src/biped_large/run.rs @@ -8,7 +8,11 @@ impl Animation for RunAnimation { type Dependency = (f32, f64); type Skeleton = BipedLargeSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"biped_large_run\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_run")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_velocity, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/bird_medium/fly.rs b/voxygen/src/anim/src/bird_medium/fly.rs index 163a996109..23477c3671 100644 --- a/voxygen/src/anim/src/bird_medium/fly.rs +++ b/voxygen/src/anim/src/bird_medium/fly.rs @@ -8,7 +8,11 @@ impl Animation for FlyAnimation { type Dependency = (f32, f64); type Skeleton = BirdMediumSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"bird_medium_fly\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_medium_fly")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/bird_medium/idle.rs b/voxygen/src/anim/src/bird_medium/idle.rs index 86b776720e..33b430636b 100644 --- a/voxygen/src/anim/src/bird_medium/idle.rs +++ b/voxygen/src/anim/src/bird_medium/idle.rs @@ -8,7 +8,12 @@ impl Animation for IdleAnimation { type Dependency = f64; type Skeleton = BirdMediumSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"bird_medium_idle\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_medium_idle")] + + fn update_skeleton_inner( skeleton: &Self::Skeleton, global_time: Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/bird_medium/mod.rs b/voxygen/src/anim/src/bird_medium/mod.rs index d0a40a351b..d759616c7a 100644 --- a/voxygen/src/anim/src/bird_medium/mod.rs +++ b/voxygen/src/anim/src/bird_medium/mod.rs @@ -27,9 +27,14 @@ impl BirdMediumSkeleton { impl Skeleton for BirdMediumSkeleton { type Attr = SkeletonAttr; + #[cfg(feature = "use-dyn-lib")] + const COMPUTE_FN: &'static [u8] = b"bird_medium_compute_mats\0"; + fn bone_count(&self) -> usize { 7 } - fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { + #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_medium_compute_mats")] + + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { let torso_mat = self.torso.compute_base_matrix(); ( diff --git a/voxygen/src/anim/src/bird_medium/run.rs b/voxygen/src/anim/src/bird_medium/run.rs index 930f16a9ae..c86f16a86b 100644 --- a/voxygen/src/anim/src/bird_medium/run.rs +++ b/voxygen/src/anim/src/bird_medium/run.rs @@ -8,7 +8,11 @@ impl Animation for RunAnimation { type Dependency = (f32, f64); type Skeleton = BirdMediumSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"bird_medium_run\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_medium_run")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_velocity, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/bird_small/idle.rs b/voxygen/src/anim/src/bird_small/idle.rs index a7de9bf1a1..f25b9a8810 100644 --- a/voxygen/src/anim/src/bird_small/idle.rs +++ b/voxygen/src/anim/src/bird_small/idle.rs @@ -8,7 +8,11 @@ impl Animation for IdleAnimation { type Dependency = f64; type Skeleton = BirdSmallSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"bird_small_idle\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_small_idle")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/bird_small/jump.rs b/voxygen/src/anim/src/bird_small/jump.rs index 58b6de31c4..059480cc4a 100644 --- a/voxygen/src/anim/src/bird_small/jump.rs +++ b/voxygen/src/anim/src/bird_small/jump.rs @@ -8,7 +8,11 @@ impl Animation for JumpAnimation { type Dependency = (f32, f64); type Skeleton = BirdSmallSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"bird_small_jump\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_small_jump")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/bird_small/mod.rs b/voxygen/src/anim/src/bird_small/mod.rs index 7937e99b4b..dde8a69b6f 100644 --- a/voxygen/src/anim/src/bird_small/mod.rs +++ b/voxygen/src/anim/src/bird_small/mod.rs @@ -32,9 +32,14 @@ impl BirdSmallSkeleton { impl Skeleton for BirdSmallSkeleton { type Attr = SkeletonAttr; + #[cfg(feature = "use-dyn-lib")] + const COMPUTE_FN: &'static [u8] = b"bird_small_compute_mats\0"; + fn bone_count(&self) -> usize { 4 } - fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { + #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_small_compute_mats")] + + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { let torso_mat = self.torso.compute_base_matrix(); ( diff --git a/voxygen/src/anim/src/bird_small/run.rs b/voxygen/src/anim/src/bird_small/run.rs index 2db15fb2bc..167889c0d0 100644 --- a/voxygen/src/anim/src/bird_small/run.rs +++ b/voxygen/src/anim/src/bird_small/run.rs @@ -8,7 +8,11 @@ impl Animation for RunAnimation { type Dependency = (f32, f64); type Skeleton = BirdSmallSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"bird_small_run\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_small_run")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_velocity, _global_time): Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/character/alpha.rs b/voxygen/src/anim/src/character/alpha.rs index be0b10846d..4e79bb340e 100644 --- a/voxygen/src/anim/src/character/alpha.rs +++ b/voxygen/src/anim/src/character/alpha.rs @@ -9,8 +9,12 @@ impl Animation for AlphaAnimation { type Dependency = (Option, f32, f64); type Skeleton = CharacterSkeleton; + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_alpha\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_alpha")] #[allow(clippy::approx_constant)] // TODO: Pending review in #587 - fn update_skeleton( + fn update_skeleton_inner( skeleton: &Self::Skeleton, (active_tool_kind, velocity, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/beta.rs b/voxygen/src/anim/src/character/beta.rs index 5ea06b431f..d8a638f4ba 100644 --- a/voxygen/src/anim/src/character/beta.rs +++ b/voxygen/src/anim/src/character/beta.rs @@ -8,7 +8,11 @@ impl Animation for BetaAnimation { type Dependency = (Option, f32, f64); type Skeleton = CharacterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_beta\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_beta")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (active_tool_kind, _velocity, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/block.rs b/voxygen/src/anim/src/character/block.rs index 54b5b57c12..7dc6f6b382 100644 --- a/voxygen/src/anim/src/character/block.rs +++ b/voxygen/src/anim/src/character/block.rs @@ -12,7 +12,11 @@ impl Animation for BlockAnimation { type Dependency = (Option, f64); type Skeleton = CharacterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_block\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_block")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (active_tool_kind, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/blockidle.rs b/voxygen/src/anim/src/character/blockidle.rs index b29f4ff2df..bc36193dc3 100644 --- a/voxygen/src/anim/src/character/blockidle.rs +++ b/voxygen/src/anim/src/character/blockidle.rs @@ -12,7 +12,11 @@ impl Animation for BlockIdleAnimation { type Dependency = (Option, f64); type Skeleton = CharacterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_blockidle\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_blockidle")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (active_tool_kind, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/charge.rs b/voxygen/src/anim/src/character/charge.rs index 4e71e03e85..b5b225f290 100644 --- a/voxygen/src/anim/src/character/charge.rs +++ b/voxygen/src/anim/src/character/charge.rs @@ -9,9 +9,13 @@ impl Animation for ChargeAnimation { type Dependency = (Option, f32, Vec3, Vec3, f64); type Skeleton = CharacterSkeleton; + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_charge\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_charge")] #[allow(clippy::approx_constant)] // TODO: Pending review in #587 #[allow(clippy::identity_conversion)] // TODO: Pending review in #587 - fn update_skeleton( + fn update_skeleton_inner( skeleton: &Self::Skeleton, (active_tool_kind, velocity, orientation, last_ori, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/climb.rs b/voxygen/src/anim/src/character/climb.rs index 0cc29d97a1..cc3ff78184 100644 --- a/voxygen/src/anim/src/character/climb.rs +++ b/voxygen/src/anim/src/character/climb.rs @@ -9,7 +9,11 @@ impl Animation for ClimbAnimation { type Dependency = (Option, Vec3, Vec3, f64); type Skeleton = CharacterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_climb\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_climb")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_active_tool_kind, velocity, _orientation, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/dance.rs b/voxygen/src/anim/src/character/dance.rs index fd0b919e5b..fd9ce57de3 100644 --- a/voxygen/src/anim/src/character/dance.rs +++ b/voxygen/src/anim/src/character/dance.rs @@ -9,7 +9,11 @@ impl Animation for DanceAnimation { type Dependency = (Option, f64); type Skeleton = CharacterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_dance\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_dance")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_active_tool_kind, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/dash.rs b/voxygen/src/anim/src/character/dash.rs index 6bab9a07fd..173232d93c 100644 --- a/voxygen/src/anim/src/character/dash.rs +++ b/voxygen/src/anim/src/character/dash.rs @@ -11,8 +11,12 @@ impl Animation for DashAnimation { type Dependency = (Option, f64); type Skeleton = CharacterSkeleton; + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_dash\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_dash")] #[allow(clippy::single_match)] // TODO: Pending review in #587 - fn update_skeleton( + fn update_skeleton_inner( skeleton: &Self::Skeleton, (active_tool_kind, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/equip.rs b/voxygen/src/anim/src/character/equip.rs index 1a6a1e95ab..02676b33e3 100644 --- a/voxygen/src/anim/src/character/equip.rs +++ b/voxygen/src/anim/src/character/equip.rs @@ -10,8 +10,12 @@ impl Animation for EquipAnimation { type Dependency = (Option, f32, f64); type Skeleton = CharacterSkeleton; + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_equip\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_equip")] #[allow(clippy::approx_constant)] // TODO: Pending review in #587 - fn update_skeleton( + fn update_skeleton_inner( skeleton: &Self::Skeleton, (active_tool_kind, velocity, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/glidewield.rs b/voxygen/src/anim/src/character/glidewield.rs new file mode 100644 index 0000000000..8ccb95b7ac --- /dev/null +++ b/voxygen/src/anim/src/character/glidewield.rs @@ -0,0 +1,308 @@ +use super::{super::Animation, CharacterSkeleton, SkeletonAttr}; +use common::comp::item::ToolKind; +use std::{f32::consts::PI, ops::Mul}; +use vek::*; + +pub struct GlideWieldAnimation; + +impl Animation for GlideWieldAnimation { + type Dependency = (Option, Vec3, Vec3, Vec3, f64); + type Skeleton = CharacterSkeleton; + + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_glidewield\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_glidewield")] + #[allow(clippy::identity_conversion)] // TODO: Pending review in #587 + fn update_skeleton_inner( + skeleton: &Self::Skeleton, + (_active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency, + anim_time: f64, + rate: &mut f32, + skeleton_attr: &SkeletonAttr, + ) -> Self::Skeleton { + let mut next = (*skeleton).clone(); + let speed = Vec2::::from(velocity).magnitude(); + *rate = 1.0; + let slow = (anim_time as f32 * 1.0).sin(); + let breathe = ((anim_time as f32 * 0.5).sin()).abs(); + let walkintensity = if speed > 5.0 { 1.0 } else { 0.45 }; + let walk = if speed > 5.0 { 1.0 } else { 0.5 }; + let lower = if speed > 5.0 { 0.0 } else { 1.0 }; + let _snapfoot = if speed > 5.0 { 1.1 } else { 2.0 }; + let lab = 1.0; + let foothoril = (anim_time as f32 * 16.0 * walk * lab as f32 + PI * 1.45).sin(); + let foothorir = (anim_time as f32 * 16.0 * walk * lab as f32 + PI * (0.45)).sin(); + + let footvertl = (anim_time as f32 * 16.0 * walk * lab as f32).sin(); + let footvertr = (anim_time as f32 * 16.0 * walk * lab as f32 + PI).sin(); + + let footrotl = (((5.0) + / (2.5 + + (2.5) + * ((anim_time as f32 * 16.0 * walk * lab as f32 + PI * 1.4).sin()) + .powf(2.0 as f32))) + .sqrt()) + * ((anim_time as f32 * 16.0 * walk * lab as f32 + PI * 1.4).sin()); + + let footrotr = (((5.0) + / (1.0 + + (4.0) + * ((anim_time as f32 * 16.0 * walk * lab as f32 + PI * 0.4).sin()) + .powf(2.0 as f32))) + .sqrt()) + * ((anim_time as f32 * 16.0 * walk * lab as f32 + PI * 0.4).sin()); + + let short = (((5.0) + / (1.5 + + 3.5 * ((anim_time as f32 * lab as f32 * 16.0 * walk).sin()).powf(2.0 as f32))) + .sqrt()) + * ((anim_time as f32 * lab as f32 * 16.0 * walk).sin()); + let noisea = (anim_time as f32 * 11.0 + PI / 6.0).sin(); + let noiseb = (anim_time as f32 * 19.0 + PI / 4.0).sin(); + + let shorte = (((5.0) + / (4.0 + + 1.0 * ((anim_time as f32 * lab as f32 * 16.0 * walk).sin()).powf(2.0 as f32))) + .sqrt()) + * ((anim_time as f32 * lab as f32 * 16.0 * walk).sin()); + + let shortalt = (anim_time as f32 * lab as f32 * 16.0 * walk + PI / 2.0).sin(); + let shortalter = (anim_time as f32 * lab as f32 * 16.0 * walk + PI / -2.0).sin(); + + let wave_stop = (anim_time as f32 * 26.0).min(PI / 2.0 / 2.0).sin(); + + let head_look = Vec2::new( + ((global_time + anim_time) as f32 / 18.0) + .floor() + .mul(7331.0) + .sin() + * 0.2, + ((global_time + anim_time) as f32 / 18.0) + .floor() + .mul(1337.0) + .sin() + * 0.1, + ); + + let ori = Vec2::from(orientation); + let last_ori = Vec2::from(last_ori); + let tilt = if Vec2::new(ori, last_ori) + .map(|o| Vec2::::from(o).magnitude_squared()) + .map(|m| m > 0.001 && m.is_finite()) + .reduce_and() + && ori.angle_between(last_ori).is_finite() + { + ori.angle_between(last_ori).min(0.2) + * last_ori.determine_side(Vec2::zero(), ori).signum() + } else { + 0.0 + } * 1.3; + + next.l_hand.offset = Vec3::new( + -2.0 - skeleton_attr.hand.0, + skeleton_attr.hand.1, + skeleton_attr.hand.2 + 15.0, + ); + next.l_hand.ori = Quaternion::rotation_x(3.35); + next.l_hand.scale = Vec3::one(); + + next.r_hand.offset = Vec3::new( + 2.0 + skeleton_attr.hand.0, + skeleton_attr.hand.1, + skeleton_attr.hand.2 + 15.0, + ); + next.r_hand.ori = Quaternion::rotation_x(3.35); + next.r_hand.scale = Vec3::one(); + + if speed > 0.5 { + next.head.offset = Vec3::new( + 0.0, + -3.0 + skeleton_attr.head.0, + skeleton_attr.head.1 + short * 0.1, + ); + next.head.ori = Quaternion::rotation_z(tilt * -2.5 + head_look.x * 0.2 - short * 0.1) + * Quaternion::rotation_x(head_look.y + 0.45 - lower * 0.35); + next.head.scale = Vec3::one() * skeleton_attr.head_scale; + + next.chest.offset = Vec3::new( + 0.0, + skeleton_attr.chest.0, + skeleton_attr.chest.1 + 2.0 + shortalt * -1.5 - lower, + ); + next.chest.ori = Quaternion::rotation_z(short * 0.10 * walkintensity + tilt * -1.0) + * Quaternion::rotation_y(tilt * 2.2) + * Quaternion::rotation_x( + shortalter * 0.035 + wave_stop * speed * -0.1 + (tilt.abs()), + ); + next.chest.scale = Vec3::one(); + + next.belt.offset = Vec3::new(0.0, skeleton_attr.belt.0, skeleton_attr.belt.1); + next.belt.ori = Quaternion::rotation_z(short * 0.1 + tilt * -1.1) + * Quaternion::rotation_y(tilt * 0.5); + next.belt.scale = Vec3::one(); + + next.glider.ori = Quaternion::rotation_x(0.8); + next.glider.offset = Vec3::new(0.0, -10.0, 15.0); + next.glider.scale = Vec3::one() * 1.0; + + next.back.offset = Vec3::new(0.0, skeleton_attr.back.0, skeleton_attr.back.1); + next.back.ori = + Quaternion::rotation_x(-0.25 + short * 0.1 + noisea * 0.1 + noiseb * 0.1); + next.back.scale = Vec3::one() * 1.02; + + next.shorts.offset = Vec3::new(0.0, skeleton_attr.shorts.0, skeleton_attr.shorts.1); + next.shorts.ori = Quaternion::rotation_z(short * 0.25 + tilt * -1.5) + * Quaternion::rotation_y(tilt * 0.7); + next.shorts.scale = Vec3::one(); + + next.l_foot.offset = Vec3::new( + -skeleton_attr.foot.0, + -1.5 + skeleton_attr.foot.1 + foothoril * -8.5 * walkintensity - lower * 1.0, + 2.0 + skeleton_attr.foot.2 + ((footvertl * -2.7).max(-1.0)) * walkintensity, + ); + next.l_foot.ori = Quaternion::rotation_x(-0.2 + footrotl * -1.2 * walkintensity) + * Quaternion::rotation_y(tilt * 1.8); + next.l_foot.scale = Vec3::one(); + + next.r_foot.offset = Vec3::new( + skeleton_attr.foot.0, + -1.5 + skeleton_attr.foot.1 + foothorir * -8.5 * walkintensity - lower * 1.0, + 2.0 + skeleton_attr.foot.2 + ((footvertr * -2.7).max(-1.0)) * walkintensity, + ); + next.r_foot.ori = Quaternion::rotation_x(-0.2 + footrotr * -1.2 * walkintensity) + * Quaternion::rotation_y(tilt * 1.8); + next.r_foot.scale = Vec3::one(); + + next.l_shoulder.offset = Vec3::new( + -skeleton_attr.shoulder.0, + skeleton_attr.shoulder.1, + skeleton_attr.shoulder.2, + ); + next.l_shoulder.ori = Quaternion::rotation_x(short * 0.15 * walkintensity); + next.l_shoulder.scale = Vec3::one() * 1.1; + + next.r_shoulder.offset = Vec3::new( + skeleton_attr.shoulder.0, + skeleton_attr.shoulder.1, + skeleton_attr.shoulder.2, + ); + next.r_shoulder.ori = Quaternion::rotation_x(short * -0.15 * walkintensity); + next.r_shoulder.scale = Vec3::one() * 1.1; + + next.main.offset = Vec3::new(-7.0, -6.5, 15.0); + next.main.ori = + Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57 + short * 0.25); + next.main.scale = Vec3::one(); + + next.second.scale = Vec3::one() * 0.0; + + next.lantern.offset = Vec3::new( + skeleton_attr.lantern.0, + skeleton_attr.lantern.1, + skeleton_attr.lantern.2, + ); + next.lantern.ori = + Quaternion::rotation_x(shorte * 0.7 + 0.4) * Quaternion::rotation_y(shorte * 0.4); + next.lantern.scale = Vec3::one() * 0.65; + + next.torso.offset = Vec3::new(0.0, 0.0, 0.0) * skeleton_attr.scaler; + next.torso.ori = Quaternion::rotation_y(0.0); + next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; + + next.control.offset = Vec3::new(0.0, 0.0, 0.0); + next.control.ori = Quaternion::rotation_x(0.0); + next.control.scale = Vec3::one(); + + next.l_control.scale = Vec3::one(); + + next.r_control.scale = Vec3::one(); + } else { + next.head.offset = Vec3::new( + 0.0, + -3.0 + skeleton_attr.head.0, + skeleton_attr.head.1 + slow * 0.3 + breathe * -0.05, + ); + next.head.ori = + Quaternion::rotation_z(head_look.x) * Quaternion::rotation_x(head_look.y.abs()); + next.head.scale = Vec3::one() * skeleton_attr.head_scale + breathe * -0.05; + + next.chest.offset = Vec3::new( + 0.0, + skeleton_attr.chest.0, + skeleton_attr.chest.1 + slow * 0.3, + ); + next.chest.ori = Quaternion::rotation_z(head_look.x * 0.6); + next.chest.scale = Vec3::one() * 1.01 + breathe * 0.03; + + next.belt.offset = Vec3::new(0.0, skeleton_attr.belt.0, skeleton_attr.belt.1); + next.belt.ori = Quaternion::rotation_z(head_look.x * -0.1); + next.belt.scale = Vec3::one() + breathe * -0.03; + + next.glider.ori = Quaternion::rotation_x(0.35); + next.glider.offset = Vec3::new(0.0, -9.0, 17.0); + next.glider.scale = Vec3::one() * 1.0; + + next.back.offset = Vec3::new(0.0, skeleton_attr.back.0, skeleton_attr.back.1); + next.back.scale = Vec3::one() * 1.02; + + next.shorts.offset = Vec3::new(0.0, skeleton_attr.shorts.0, skeleton_attr.shorts.1); + next.shorts.ori = Quaternion::rotation_z(head_look.x * -0.2); + next.shorts.scale = Vec3::one() + breathe * -0.03; + + next.l_foot.offset = Vec3::new( + -skeleton_attr.foot.0, + skeleton_attr.foot.1, + skeleton_attr.foot.2, + ); + next.l_foot.scale = Vec3::one(); + + next.r_foot.offset = Vec3::new( + skeleton_attr.foot.0, + skeleton_attr.foot.1, + skeleton_attr.foot.2, + ); + next.r_foot.scale = Vec3::one(); + + next.l_shoulder.offset = Vec3::new( + -skeleton_attr.shoulder.0, + skeleton_attr.shoulder.1, + skeleton_attr.shoulder.2, + ); + next.l_shoulder.scale = (Vec3::one() + breathe * -0.05) * 1.15; + + next.r_shoulder.offset = Vec3::new( + skeleton_attr.shoulder.0, + skeleton_attr.shoulder.1, + skeleton_attr.shoulder.2, + ); + next.r_shoulder.scale = (Vec3::one() + breathe * -0.05) * 1.15; + + next.main.offset = Vec3::new(-7.0, -5.0, 15.0); + next.main.ori = Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57); + next.main.scale = Vec3::one(); + + next.second.offset = Vec3::new(0.0, 0.0, 0.0); + next.second.scale = Vec3::one() * 0.0; + + next.lantern.offset = Vec3::new( + skeleton_attr.lantern.0, + skeleton_attr.lantern.1, + skeleton_attr.lantern.2, + ); + next.lantern.ori = Quaternion::rotation_x(0.1) * Quaternion::rotation_y(0.1); + next.lantern.scale = Vec3::one() * 0.65; + + next.torso.offset = Vec3::new(0.0, 0.0, 0.0) * skeleton_attr.scaler; + next.torso.ori = Quaternion::rotation_x(0.0); + next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; + + next.control.scale = Vec3::one(); + + next.l_control.scale = Vec3::one(); + + next.r_control.scale = Vec3::one(); + } + next + } +} diff --git a/voxygen/src/anim/src/character/gliding.rs b/voxygen/src/anim/src/character/gliding.rs index 4f9a89cdb4..896fba32f8 100644 --- a/voxygen/src/anim/src/character/gliding.rs +++ b/voxygen/src/anim/src/character/gliding.rs @@ -9,8 +9,12 @@ impl Animation for GlidingAnimation { type Dependency = (Option, Vec3, Vec3, Vec3, f64); type Skeleton = CharacterSkeleton; + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_gliding\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_gliding")] #[allow(clippy::identity_conversion)] // TODO: Pending review in #587 - fn update_skeleton( + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/idle.rs b/voxygen/src/anim/src/character/idle.rs index db4fa6093b..f1b8c7c27c 100644 --- a/voxygen/src/anim/src/character/idle.rs +++ b/voxygen/src/anim/src/character/idle.rs @@ -8,7 +8,11 @@ impl Animation for IdleAnimation { type Dependency = f64; type Skeleton = CharacterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_idle\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_idle")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: f64, anim_time: f64, diff --git a/voxygen/src/anim/src/character/jump.rs b/voxygen/src/anim/src/character/jump.rs index 56b56a31f3..7ca28e6e9d 100644 --- a/voxygen/src/anim/src/character/jump.rs +++ b/voxygen/src/anim/src/character/jump.rs @@ -7,8 +7,12 @@ impl Animation for JumpAnimation { type Dependency = (Option, Vec3, Vec3, f64); type Skeleton = CharacterSkeleton; + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_jump\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_jump")] #[allow(clippy::identity_conversion)] // TODO: Pending review in #587 - fn update_skeleton( + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_active_tool_kind, orientation, last_ori, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/mod.rs b/voxygen/src/anim/src/character/mod.rs index 7aefc2f5bf..e4cd029dbd 100644 --- a/voxygen/src/anim/src/character/mod.rs +++ b/voxygen/src/anim/src/character/mod.rs @@ -66,9 +66,14 @@ impl CharacterSkeleton { impl Skeleton for CharacterSkeleton { type Attr = SkeletonAttr; + #[cfg(feature = "use-dyn-lib")] + const COMPUTE_FN: &'static [u8] = b"character_compute_mats\0"; + fn bone_count(&self) -> usize { 16 } - fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_compute_mats")] + + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { let chest_mat = self.chest.compute_base_matrix(); let torso_mat = self.torso.compute_base_matrix(); let l_hand_mat = self.l_hand.compute_base_matrix(); diff --git a/voxygen/src/anim/src/character/roll.rs b/voxygen/src/anim/src/character/roll.rs index 4813aaa4b4..17b2bac556 100644 --- a/voxygen/src/anim/src/character/roll.rs +++ b/voxygen/src/anim/src/character/roll.rs @@ -8,8 +8,12 @@ impl Animation for RollAnimation { type Dependency = (Option, Vec3, Vec3, f64); type Skeleton = CharacterSkeleton; + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_roll\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_roll")] #[allow(clippy::identity_conversion)] // TODO: Pending review in #587 - fn update_skeleton( + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_active_tool_kind, orientation, last_ori, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/run.rs b/voxygen/src/anim/src/character/run.rs index e15e2df631..595010670e 100644 --- a/voxygen/src/anim/src/character/run.rs +++ b/voxygen/src/anim/src/character/run.rs @@ -9,8 +9,12 @@ impl Animation for RunAnimation { type Dependency = (Option, Vec3, Vec3, Vec3, f64); type Skeleton = CharacterSkeleton; + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_run\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_run")] #[allow(clippy::identity_conversion)] // TODO: Pending review in #587 - fn update_skeleton( + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/shoot.rs b/voxygen/src/anim/src/character/shoot.rs index 5dc41d5716..b9d82d5786 100644 --- a/voxygen/src/anim/src/character/shoot.rs +++ b/voxygen/src/anim/src/character/shoot.rs @@ -8,8 +8,12 @@ impl Animation for ShootAnimation { type Dependency = (Option, f32, f64); type Skeleton = CharacterSkeleton; + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_shoot\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_shoot")] #[allow(clippy::approx_constant)] // TODO: Pending review in #587 - fn update_skeleton( + fn update_skeleton_inner( skeleton: &Self::Skeleton, (active_tool_kind, velocity, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/sit.rs b/voxygen/src/anim/src/character/sit.rs index 34ffeb1cb8..bef428103e 100644 --- a/voxygen/src/anim/src/character/sit.rs +++ b/voxygen/src/anim/src/character/sit.rs @@ -9,7 +9,11 @@ impl Animation for SitAnimation { type Dependency = (Option, f64); type Skeleton = CharacterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_sit\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_sit")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_active_tool_kind, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/spin.rs b/voxygen/src/anim/src/character/spin.rs index 92432ac88f..2ab47f316e 100644 --- a/voxygen/src/anim/src/character/spin.rs +++ b/voxygen/src/anim/src/character/spin.rs @@ -12,7 +12,11 @@ impl Animation for SpinAnimation { type Dependency = (Option, f64); type Skeleton = CharacterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_spin\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_spin")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (active_tool_kind, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/stand.rs b/voxygen/src/anim/src/character/stand.rs index c424ff7c86..645ce60f2f 100644 --- a/voxygen/src/anim/src/character/stand.rs +++ b/voxygen/src/anim/src/character/stand.rs @@ -9,7 +9,11 @@ impl Animation for StandAnimation { type Dependency = (Option, f64); type Skeleton = CharacterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_stand\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_stand")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_active_tool_kind, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/swim.rs b/voxygen/src/anim/src/character/swim.rs index 649efbb9fc..71147021fb 100644 --- a/voxygen/src/anim/src/character/swim.rs +++ b/voxygen/src/anim/src/character/swim.rs @@ -9,8 +9,12 @@ impl Animation for SwimAnimation { type Dependency = (Option, Vec3, Vec3, Vec3, f64); type Skeleton = CharacterSkeleton; + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_swim\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_swim")] #[allow(clippy::identity_conversion)] // TODO: Pending review in #587 - fn update_skeleton( + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/character/wield.rs b/voxygen/src/anim/src/character/wield.rs index 2c52c6153a..dbf11016bf 100644 --- a/voxygen/src/anim/src/character/wield.rs +++ b/voxygen/src/anim/src/character/wield.rs @@ -9,8 +9,12 @@ impl Animation for WieldAnimation { type Dependency = (Option, f32, f64); type Skeleton = CharacterSkeleton; + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"character_wield\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "character_wield")] #[allow(clippy::approx_constant)] // TODO: Pending review in #587 - fn update_skeleton( + fn update_skeleton_inner( skeleton: &Self::Skeleton, (active_tool_kind, velocity, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/critter/idle.rs b/voxygen/src/anim/src/critter/idle.rs index fe9827bb4c..68f864ea2d 100644 --- a/voxygen/src/anim/src/critter/idle.rs +++ b/voxygen/src/anim/src/critter/idle.rs @@ -9,7 +9,11 @@ impl Animation for IdleAnimation { type Dependency = f64; type Skeleton = CritterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"critter_idle\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "critter_idle")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, global_time: Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/critter/jump.rs b/voxygen/src/anim/src/critter/jump.rs index 506a6d4309..b4c5a0b57f 100644 --- a/voxygen/src/anim/src/critter/jump.rs +++ b/voxygen/src/anim/src/critter/jump.rs @@ -8,7 +8,11 @@ impl Animation for JumpAnimation { type Dependency = (f32, f64); type Skeleton = CritterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"critter_jump\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "critter_jump")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/critter/mod.rs b/voxygen/src/anim/src/critter/mod.rs index 80b9d3cd12..b83114adc1 100644 --- a/voxygen/src/anim/src/critter/mod.rs +++ b/voxygen/src/anim/src/critter/mod.rs @@ -32,9 +32,14 @@ impl CritterSkeleton { impl Skeleton for CritterSkeleton { type Attr = CritterAttr; + #[cfg(feature = "use-dyn-lib")] + const COMPUTE_FN: &'static [u8] = b"critter_compute_mats\0"; + fn bone_count(&self) -> usize { 5 } - fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { + #[cfg_attr(feature = "be-dyn-lib", export_name = "critter_compute_mats")] + + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { ( [ FigureBoneData::new(self.head.compute_base_matrix()), diff --git a/voxygen/src/anim/src/critter/run.rs b/voxygen/src/anim/src/critter/run.rs index a2918c958e..fac82204cc 100644 --- a/voxygen/src/anim/src/critter/run.rs +++ b/voxygen/src/anim/src/critter/run.rs @@ -9,7 +9,11 @@ impl Animation for RunAnimation { type Dependency = (f32, f64); type Skeleton = CritterSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"critter_run\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "critter_run")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_velocity, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/dragon/fly.rs b/voxygen/src/anim/src/dragon/fly.rs index a996e89775..14379e7a42 100644 --- a/voxygen/src/anim/src/dragon/fly.rs +++ b/voxygen/src/anim/src/dragon/fly.rs @@ -8,7 +8,11 @@ impl Animation for FlyAnimation { type Dependency = (f32, f64); type Skeleton = DragonSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"dragon_fly\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "dragon_fly")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/dragon/idle.rs b/voxygen/src/anim/src/dragon/idle.rs index 9e97adb4c3..f7967928d0 100644 --- a/voxygen/src/anim/src/dragon/idle.rs +++ b/voxygen/src/anim/src/dragon/idle.rs @@ -8,7 +8,11 @@ impl Animation for IdleAnimation { type Dependency = f64; type Skeleton = DragonSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"dragon_idle\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "dragon_idle")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, global_time: Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/dragon/mod.rs b/voxygen/src/anim/src/dragon/mod.rs index e949f44a69..ba01e7a5b9 100644 --- a/voxygen/src/anim/src/dragon/mod.rs +++ b/voxygen/src/anim/src/dragon/mod.rs @@ -35,9 +35,14 @@ impl DragonSkeleton { impl Skeleton for DragonSkeleton { type Attr = SkeletonAttr; + #[cfg(feature = "use-dyn-lib")] + const COMPUTE_FN: &'static [u8] = b"dragon_compute_mats\0"; + fn bone_count(&self) -> usize { 15 } - fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { + #[cfg_attr(feature = "be-dyn-lib", export_name = "dragon_compute_mats")] + + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { let head_upper_mat = self.head_upper.compute_base_matrix(); let head_lower_mat = self.head_lower.compute_base_matrix(); let chest_front_mat = self.chest_front.compute_base_matrix(); diff --git a/voxygen/src/anim/src/dragon/run.rs b/voxygen/src/anim/src/dragon/run.rs index 6bb74df52c..626728d83c 100644 --- a/voxygen/src/anim/src/dragon/run.rs +++ b/voxygen/src/anim/src/dragon/run.rs @@ -8,7 +8,11 @@ impl Animation for RunAnimation { type Dependency = (f32, f64); type Skeleton = DragonSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"dragon_run\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "dragon_run")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_velocity, global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/fish_medium/idle.rs b/voxygen/src/anim/src/fish_medium/idle.rs index b5258b283f..a61c284abd 100644 --- a/voxygen/src/anim/src/fish_medium/idle.rs +++ b/voxygen/src/anim/src/fish_medium/idle.rs @@ -8,7 +8,11 @@ impl Animation for IdleAnimation { type Dependency = f64; type Skeleton = FishMediumSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"fish_medium_idle\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "fish_medium_idle")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/fish_medium/jump.rs b/voxygen/src/anim/src/fish_medium/jump.rs index 2950ea82a4..2858c2ba23 100644 --- a/voxygen/src/anim/src/fish_medium/jump.rs +++ b/voxygen/src/anim/src/fish_medium/jump.rs @@ -8,7 +8,11 @@ impl Animation for JumpAnimation { type Dependency = (f32, f64); type Skeleton = FishMediumSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"fish_medium_jump\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "fish_medium_jump")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/fish_medium/mod.rs b/voxygen/src/anim/src/fish_medium/mod.rs index 04533f5a04..7e3741d4c5 100644 --- a/voxygen/src/anim/src/fish_medium/mod.rs +++ b/voxygen/src/anim/src/fish_medium/mod.rs @@ -36,9 +36,13 @@ impl FishMediumSkeleton { impl Skeleton for FishMediumSkeleton { type Attr = SkeletonAttr; + #[cfg(feature = "use-dyn-lib")] + const COMPUTE_FN: &'static [u8] = b"fish_medium_compute_mats\0"; + fn bone_count(&self) -> usize { 6 } - fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { + #[cfg_attr(feature = "be-dyn-lib", export_name = "fish_medium_compute_mats")] + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { let torso_mat = self.torso.compute_base_matrix(); let rear_mat = self.rear.compute_base_matrix(); diff --git a/voxygen/src/anim/src/fish_medium/run.rs b/voxygen/src/anim/src/fish_medium/run.rs index 6aec82cfed..47219f1b31 100644 --- a/voxygen/src/anim/src/fish_medium/run.rs +++ b/voxygen/src/anim/src/fish_medium/run.rs @@ -8,7 +8,11 @@ impl Animation for RunAnimation { type Dependency = (f32, f64); type Skeleton = FishMediumSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"fish_medium_run\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "fish_medium_run")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/fish_small/idle.rs b/voxygen/src/anim/src/fish_small/idle.rs index fbfe1a3dac..4262a42db9 100644 --- a/voxygen/src/anim/src/fish_small/idle.rs +++ b/voxygen/src/anim/src/fish_small/idle.rs @@ -8,7 +8,11 @@ impl Animation for IdleAnimation { type Dependency = f64; type Skeleton = FishSmallSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"fish_small_idle\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "fish_small_idle")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/fish_small/jump.rs b/voxygen/src/anim/src/fish_small/jump.rs index efeb5927a2..90bca46ade 100644 --- a/voxygen/src/anim/src/fish_small/jump.rs +++ b/voxygen/src/anim/src/fish_small/jump.rs @@ -8,7 +8,11 @@ impl Animation for JumpAnimation { type Dependency = (f32, f64); type Skeleton = FishSmallSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"fish_small_jump\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "fish_small_jump")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/fish_small/mod.rs b/voxygen/src/anim/src/fish_small/mod.rs index d201989b99..7821d8b446 100644 --- a/voxygen/src/anim/src/fish_small/mod.rs +++ b/voxygen/src/anim/src/fish_small/mod.rs @@ -28,9 +28,14 @@ impl FishSmallSkeleton { impl Skeleton for FishSmallSkeleton { type Attr = SkeletonAttr; + #[cfg(feature = "use-dyn-lib")] + const COMPUTE_FN: &'static [u8] = b"fish_small_compute_mats\0"; + fn bone_count(&self) -> usize { 2 } - fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { + #[cfg_attr(feature = "be-dyn-lib", export_name = "fish_small_compute_mats")] + + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { let torso_mat = self.torso.compute_base_matrix(); ( diff --git a/voxygen/src/anim/src/fish_small/run.rs b/voxygen/src/anim/src/fish_small/run.rs index 797e760634..8e93a3ae7c 100644 --- a/voxygen/src/anim/src/fish_small/run.rs +++ b/voxygen/src/anim/src/fish_small/run.rs @@ -8,7 +8,11 @@ impl Animation for RunAnimation { type Dependency = (f32, f64); type Skeleton = FishSmallSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"fish_small_run\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "fish_small_run")] + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_velocity, _global_time): Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/fixture/mod.rs b/voxygen/src/anim/src/fixture/mod.rs index a95bcb9729..40fe3095fc 100644 --- a/voxygen/src/anim/src/fixture/mod.rs +++ b/voxygen/src/anim/src/fixture/mod.rs @@ -14,9 +14,14 @@ impl FixtureSkeleton { impl Skeleton for FixtureSkeleton { type Attr = SkeletonAttr; + #[cfg(feature = "use-dyn-lib")] + const COMPUTE_FN: &'static [u8] = b"fixture_compute_mats\0"; + fn bone_count(&self) -> usize { 1 } - fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { + #[cfg_attr(feature = "be-dyn-lib", export_name = "fixture_compute_mats")] + + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { ( [ FigureBoneData::new(vek::Mat4::identity()), // <-- This is actually a bone! diff --git a/voxygen/src/anim/src/golem/idle.rs b/voxygen/src/anim/src/golem/idle.rs index 6df1b9c34a..cbdfe7b05e 100644 --- a/voxygen/src/anim/src/golem/idle.rs +++ b/voxygen/src/anim/src/golem/idle.rs @@ -8,7 +8,12 @@ impl Animation for IdleAnimation { type Dependency = f64; type Skeleton = GolemSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"golem_idle\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "golem_idle")] + + fn update_skeleton_inner( skeleton: &Self::Skeleton, global_time: Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/golem/jump.rs b/voxygen/src/anim/src/golem/jump.rs index e7ba85f450..ac294f59dc 100644 --- a/voxygen/src/anim/src/golem/jump.rs +++ b/voxygen/src/anim/src/golem/jump.rs @@ -8,7 +8,12 @@ impl Animation for JumpAnimation { type Dependency = (f32, f64); type Skeleton = GolemSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"golem_jump\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "golem_jump")] + + fn update_skeleton_inner( skeleton: &Self::Skeleton, _global_time: Self::Dependency, _anim_time: f64, diff --git a/voxygen/src/anim/src/golem/mod.rs b/voxygen/src/anim/src/golem/mod.rs index 7329bff0e8..5bd5861d1b 100644 --- a/voxygen/src/anim/src/golem/mod.rs +++ b/voxygen/src/anim/src/golem/mod.rs @@ -9,7 +9,7 @@ use super::{Bone, FigureBoneData, Skeleton}; use common::comp::{self}; use vek::Vec3; -#[derive(Clone)] +#[derive(Clone, Default)] pub struct GolemSkeleton { head: Bone, upper_torso: Bone, @@ -25,28 +25,19 @@ pub struct GolemSkeleton { } impl GolemSkeleton { - #[allow(clippy::new_without_default)] // TODO: Pending review in #587 - pub fn new() -> Self { - Self { - head: Bone::default(), - upper_torso: Bone::default(), - shoulder_l: Bone::default(), - shoulder_r: Bone::default(), - hand_l: Bone::default(), - hand_r: Bone::default(), - leg_l: Bone::default(), - leg_r: Bone::default(), - foot_l: Bone::default(), - foot_r: Bone::default(), - torso: Bone::default(), - } - } + pub fn new() -> Self { Self::default() } } impl Skeleton for GolemSkeleton { type Attr = SkeletonAttr; - fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { + #[cfg(feature = "use-dyn-lib")] + const COMPUTE_FN: &'static [u8] = b"golem_compute_mats\0"; + + fn bone_count(&self) -> usize { 15 } + + #[cfg_attr(feature = "be-dyn-lib", export_name = "golem_compute_mats")] + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { let upper_torso_mat = self.upper_torso.compute_base_matrix(); let shoulder_l_mat = self.shoulder_l.compute_base_matrix(); let shoulder_r_mat = self.shoulder_r.compute_base_matrix(); diff --git a/voxygen/src/anim/src/golem/run.rs b/voxygen/src/anim/src/golem/run.rs index 9dc8bd71e7..c5d1c0f6ec 100644 --- a/voxygen/src/anim/src/golem/run.rs +++ b/voxygen/src/anim/src/golem/run.rs @@ -8,7 +8,12 @@ impl Animation for RunAnimation { type Dependency = (f32, f64); type Skeleton = GolemSkeleton; - fn update_skeleton( + #[cfg(feature = "use-dyn-lib")] + const UPDATE_FN: &'static [u8] = b"golem_run\0"; + + #[cfg_attr(feature = "be-dyn-lib", export_name = "golem_run")] + + fn update_skeleton_inner( skeleton: &Self::Skeleton, (_velocity, _global_time): Self::Dependency, anim_time: f64, diff --git a/voxygen/src/anim/src/lib.rs b/voxygen/src/anim/src/lib.rs index 9b8a833ac2..44942a0aa2 100644 --- a/voxygen/src/anim/src/lib.rs +++ b/voxygen/src/anim/src/lib.rs @@ -1,4 +1,3 @@ -// TODO: we could probably avoid the need for this #[cfg(all(feature = "be-dyn-lib", feature = "use-dyn-lib"))] compile_error!("Can't use both \"be-dyn-lib\" and \"use-dyn-lib\" features at once"); @@ -70,10 +69,12 @@ pub trait Skeleton: Send + Sync + 'static { type Attr; #[cfg(feature = "use-dyn-lib")] - const COMPUTE_FN: &'static [u8] = b"\0"; + const COMPUTE_FN: &'static [u8]; fn bone_count(&self) -> usize { 16 } + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3); + fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { #[cfg(not(feature = "use-dyn-lib"))] { @@ -100,13 +101,6 @@ pub trait Skeleton: Send + Sync + 'static { } } - fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { - panic!( - "Neither compute_matrices_inner nor compute_matrices override present in Animation \ - impl" - ) - } - /// Change the current skeleton to be more like `target`. fn interpolate(&mut self, target: &Self, dt: f32); } @@ -116,9 +110,19 @@ pub trait Animation { type Dependency; #[cfg(feature = "use-dyn-lib")] - const UPDATE_FN: &'static [u8] = b"\0"; + const UPDATE_FN: &'static [u8]; /// Returns a new skeleton that is generated by the animation. + fn update_skeleton_inner( + _skeleton: &Self::Skeleton, + _dependency: Self::Dependency, + _anim_time: f64, + _rate: &mut f32, + _skeleton_attr: &<::Skeleton as Skeleton>::Attr, + ) -> Self::Skeleton; + + /// Calls `update_skeleton_inner` either directly or via `libloading` to + /// produce generate the new skeleton. fn update_skeleton( skeleton: &Self::Skeleton, dependency: Self::Dependency, @@ -164,16 +168,4 @@ pub trait Animation { update_fn(skeleton, dependency, anim_time, rate, skeleton_attr) } } - - fn update_skeleton_inner( - _skeleton: &Self::Skeleton, - _dependency: Self::Dependency, - _anim_time: f64, - _rate: &mut f32, - _skeleton_attr: &<::Skeleton as Skeleton>::Attr, - ) -> Self::Skeleton { - panic!( - "Neither update_skeleton_inner nor update_skeleton override present in Animation impl" - ) - } } diff --git a/voxygen/src/anim/src/object/mod.rs b/voxygen/src/anim/src/object/mod.rs index 8b5b213429..398e6d80be 100644 --- a/voxygen/src/anim/src/object/mod.rs +++ b/voxygen/src/anim/src/object/mod.rs @@ -15,9 +15,13 @@ const SCALE: f32 = 1.0 / 11.0; impl Skeleton for ObjectSkeleton { type Attr = SkeletonAttr; - fn bone_count(&self) -> usize { 1 } + #[cfg(feature = "use-dyn-lib")] + const COMPUTE_FN: &'static [u8] = b"object_compute_mats\0"; - fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3) { + fn bone_count(&self) -> usize { 15 } + + #[cfg_attr(feature = "be-dyn-lib", export_name = "object_compute_mats")] + fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3) { ( [ FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),