mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Hotreload animations using libloading
This commit is contained in:
parent
a67ea3ec5c
commit
d00e88b804
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -4594,11 +4594,23 @@ dependencies = [
|
||||
"veloren-client",
|
||||
"veloren-common",
|
||||
"veloren-server",
|
||||
"veloren-voxygen-anim",
|
||||
"veloren-world",
|
||||
"winit",
|
||||
"winres",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "veloren-voxygen-anim"
|
||||
version = "0.6.0"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"libloading 0.6.2",
|
||||
"notify",
|
||||
"vek",
|
||||
"veloren-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "veloren-world"
|
||||
version = "0.6.0"
|
||||
|
@ -10,6 +10,7 @@ members = [
|
||||
"voxygen",
|
||||
"world",
|
||||
"network",
|
||||
"voxygen/src/anim"
|
||||
]
|
||||
|
||||
# default profile for devs, fast to compile, okay enough to run, no debug information
|
||||
|
@ -12,6 +12,7 @@ default-run = "veloren-voxygen"
|
||||
gl = ["gfx_device_gl"]
|
||||
singleplayer = ["server"]
|
||||
tweak = ["const-tweaker"]
|
||||
hot-anim = ["anim/use-dyn-lib"]
|
||||
|
||||
default = ["gl", "singleplayer", "msgbox"]
|
||||
|
||||
@ -19,6 +20,8 @@ default = ["gl", "singleplayer", "msgbox"]
|
||||
common = { package = "veloren-common", path = "../common" }
|
||||
client = { package = "veloren-client", path = "../client" }
|
||||
|
||||
anim = { package = "veloren-voxygen-anim", path = "src/anim", default-features = false }
|
||||
|
||||
# Graphics
|
||||
gfx = "0.18.2"
|
||||
gfx_device_gl = { version = "0.16.2", optional = true }
|
||||
|
23
voxygen/src/anim/Cargo.toml
Normal file
23
voxygen/src/anim/Cargo.toml
Normal file
@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "veloren-voxygen-anim"
|
||||
version = "0.6.0"
|
||||
authors = ["Joshua Barretto <joshua.s.barretto@gmail.com>", "Imbris <imbrisf@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "voxygen_anim"
|
||||
crate-type = ["lib", "cdylib"]
|
||||
|
||||
[features]
|
||||
use-dyn-lib = ["libloading", "notify", "lazy_static"]
|
||||
be-dyn-lib = []
|
||||
|
||||
default = ["be-dyn-lib"]
|
||||
|
||||
[dependencies]
|
||||
vek = { version = "0.11.2", features = ["serde"] }
|
||||
common = { package = "veloren-common", path = "../../../common" }
|
||||
libloading = { version = "0.6.2", optional = true }
|
||||
notify = { version = "5.0.0-pre.2", optional = true }
|
||||
lazy_static = { version = "1.4.0", optional = true }
|
||||
|
@ -1,75 +0,0 @@
|
||||
pub mod biped_large;
|
||||
pub mod bird_medium;
|
||||
pub mod bird_small;
|
||||
pub mod character;
|
||||
pub mod critter;
|
||||
pub mod dragon;
|
||||
pub mod fish_medium;
|
||||
pub mod fish_small;
|
||||
pub mod fixture;
|
||||
pub mod golem;
|
||||
pub mod object;
|
||||
pub mod quadruped_medium;
|
||||
pub mod quadruped_small;
|
||||
|
||||
use crate::render::FigureBoneData;
|
||||
use vek::*;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct Bone {
|
||||
pub offset: Vec3<f32>,
|
||||
pub ori: Quaternion<f32>,
|
||||
pub scale: Vec3<f32>,
|
||||
}
|
||||
|
||||
impl Default for Bone {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
offset: Vec3::zero(),
|
||||
ori: Quaternion::identity(),
|
||||
scale: Vec3::broadcast(1.0 / 11.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Bone {
|
||||
pub fn compute_base_matrix(&self) -> Mat4<f32> {
|
||||
Mat4::<f32>::translation_3d(self.offset)
|
||||
* Mat4::scaling_3d(self.scale)
|
||||
* Mat4::from(self.ori)
|
||||
}
|
||||
|
||||
/// Change the current bone to be more like `target`.
|
||||
fn interpolate(&mut self, target: &Bone, dt: f32) {
|
||||
// TODO: Make configurable.
|
||||
let factor = (15.0 * dt).min(1.0);
|
||||
self.offset += (target.offset - self.offset) * factor;
|
||||
self.ori = vek::Slerp::slerp(self.ori, target.ori, factor);
|
||||
self.scale += (target.scale - self.scale) * factor;
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Skeleton: Send + Sync + 'static {
|
||||
type Attr;
|
||||
|
||||
fn bone_count(&self) -> usize { 16 }
|
||||
|
||||
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>);
|
||||
|
||||
/// Change the current skeleton to be more like `target`.
|
||||
fn interpolate(&mut self, target: &Self, dt: f32);
|
||||
}
|
||||
|
||||
pub trait Animation {
|
||||
type Skeleton: Skeleton;
|
||||
type Dependency;
|
||||
|
||||
/// Returns a new skeleton that is generated by the animation.
|
||||
fn update_skeleton(
|
||||
skeleton: &Self::Skeleton,
|
||||
dependency: Self::Dependency,
|
||||
anim_time: f64,
|
||||
rate: &mut f32,
|
||||
skeleton_attr: &<<Self as Animation>::Skeleton as Skeleton>::Attr,
|
||||
) -> Self::Skeleton;
|
||||
}
|
@ -5,8 +5,7 @@ pub mod run;
|
||||
// Reexports
|
||||
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
|
||||
|
||||
use super::{Bone, Skeleton};
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{Bone, FigureBoneData, Skeleton};
|
||||
use common::comp::{self};
|
||||
use vek::Vec3;
|
||||
|
@ -5,8 +5,7 @@ pub mod run;
|
||||
// Reexports
|
||||
pub use self::{fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation};
|
||||
|
||||
use super::{Bone, Skeleton};
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{Bone, FigureBoneData, Skeleton};
|
||||
use common::comp::{self};
|
||||
use vek::Vec3;
|
||||
|
@ -5,8 +5,7 @@ pub mod run;
|
||||
// Reexports
|
||||
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
|
||||
|
||||
use super::{Bone, Skeleton};
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{Bone, FigureBoneData, Skeleton};
|
||||
use common::comp::{self};
|
||||
use vek::Vec3;
|
||||
|
@ -31,8 +31,7 @@ pub use self::{
|
||||
wield::WieldAnimation,
|
||||
};
|
||||
|
||||
use super::{Bone, Skeleton};
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{Bone, FigureBoneData, Skeleton};
|
||||
use common::comp;
|
||||
use vek::{Vec3, Vec4};
|
||||
|
@ -5,8 +5,7 @@ pub mod run;
|
||||
// Reexports
|
||||
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
|
||||
|
||||
use super::{Bone, Skeleton};
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{Bone, FigureBoneData, Skeleton};
|
||||
use common::comp::{self};
|
||||
use vek::Vec3;
|
||||
|
@ -5,8 +5,7 @@ pub mod run;
|
||||
// Reexports
|
||||
pub use self::{fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation};
|
||||
|
||||
use super::{Bone, Skeleton};
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{Bone, FigureBoneData, Skeleton};
|
||||
use common::comp::{self};
|
||||
use vek::Vec3;
|
||||
|
109
voxygen/src/anim/src/dyn_lib.rs
Normal file
109
voxygen/src/anim/src/dyn_lib.rs
Normal file
@ -0,0 +1,109 @@
|
||||
use lazy_static::lazy_static;
|
||||
use libloading::Library;
|
||||
use notify::{
|
||||
event::{AccessKind, AccessMode},
|
||||
immediate_watcher, EventKind, RecursiveMode, Watcher,
|
||||
};
|
||||
use std::{
|
||||
process::{Command, Stdio},
|
||||
sync::Mutex,
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref LIB: Mutex<Option<LoadedLib>> = Mutex::new(Some(LoadedLib::compile_load()));
|
||||
}
|
||||
|
||||
pub struct LoadedLib {
|
||||
pub lib: Library,
|
||||
}
|
||||
|
||||
impl LoadedLib {
|
||||
fn compile_load() -> Self {
|
||||
// Compile
|
||||
let _output = Command::new("cargo")
|
||||
.stderr(Stdio::inherit())
|
||||
.stdout(Stdio::inherit())
|
||||
.arg("build")
|
||||
.arg("--release")
|
||||
.arg("--package")
|
||||
.arg("veloren-voxygen-anim")
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
Self::load()
|
||||
}
|
||||
|
||||
fn load() -> Self {
|
||||
#[cfg(target_os = "windows")]
|
||||
let lib = Library::new("../target/release/libvoxygen_anim.dll").unwrap();
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let lib = Library::new("../target/release/libvoxygen_anim.so").unwrap();
|
||||
|
||||
Self { lib }
|
||||
}
|
||||
}
|
||||
|
||||
// Starts up watcher test test2 test3 test4 test5
|
||||
pub fn init() {
|
||||
// Start watcher
|
||||
let mut watcher = immediate_watcher(event_fn).unwrap();
|
||||
watcher.watch("src/anim", RecursiveMode::Recursive).unwrap();
|
||||
|
||||
// Let the watcher live forever
|
||||
std::mem::forget(watcher);
|
||||
}
|
||||
|
||||
// Recompiles and hotreloads the lib if the source is changed
|
||||
// Note: designed with voxygen dir as working dir, could be made more flexible
|
||||
fn event_fn(res: notify::Result<notify::Event>) {
|
||||
match res {
|
||||
Ok(event) => match event.kind {
|
||||
EventKind::Access(AccessKind::Close(AccessMode::Write)) => {
|
||||
if event
|
||||
.paths
|
||||
.iter()
|
||||
.any(|p| p.extension().map(|e| e == "rs").unwrap_or(false))
|
||||
{
|
||||
println!(
|
||||
"Hot reloading animations because these files were modified:\n{:?}",
|
||||
event.paths
|
||||
);
|
||||
reload();
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
},
|
||||
Err(e) => println!("watch error: {:?}", e),
|
||||
}
|
||||
}
|
||||
|
||||
fn reload() {
|
||||
// Compile
|
||||
let output = Command::new("cargo")
|
||||
.stderr(Stdio::inherit())
|
||||
.stdout(Stdio::inherit())
|
||||
.arg("build")
|
||||
.arg("--release")
|
||||
.arg("--package")
|
||||
.arg("veloren-voxygen-anim")
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
// Stop if recompile failed
|
||||
if !output.status.success() {
|
||||
println!("Failed to compile anim crate");
|
||||
return;
|
||||
}
|
||||
|
||||
println!("Compile Success!!");
|
||||
|
||||
let mut lock = LIB.lock().unwrap();
|
||||
|
||||
// Close lib
|
||||
lock.take().unwrap().lib.close().unwrap();
|
||||
|
||||
// Open new lib
|
||||
*lock = Some(LoadedLib::load());
|
||||
|
||||
println!("Updated");
|
||||
}
|
@ -5,8 +5,7 @@ pub mod run;
|
||||
// Reexports
|
||||
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
|
||||
|
||||
use super::{Bone, Skeleton};
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{Bone, FigureBoneData, Skeleton};
|
||||
use common::comp::{self};
|
||||
use vek::Vec3;
|
||||
|
@ -5,8 +5,7 @@ pub mod run;
|
||||
// Reexports
|
||||
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
|
||||
|
||||
use super::{Bone, Skeleton};
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{Bone, FigureBoneData, Skeleton};
|
||||
use common::comp::{self};
|
||||
use vek::Vec3;
|
||||
|
@ -1,5 +1,4 @@
|
||||
use super::Skeleton;
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{FigureBoneData, Skeleton};
|
||||
use vek::Vec3;
|
||||
|
||||
#[derive(Clone)]
|
@ -5,8 +5,7 @@ pub mod run;
|
||||
// Reexports
|
||||
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
|
||||
|
||||
use super::{Bone, Skeleton};
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{Bone, FigureBoneData, Skeleton};
|
||||
use common::comp::{self};
|
||||
use vek::Vec3;
|
||||
|
158
voxygen/src/anim/src/lib.rs
Normal file
158
voxygen/src/anim/src/lib.rs
Normal file
@ -0,0 +1,158 @@
|
||||
// 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");
|
||||
|
||||
pub mod biped_large;
|
||||
pub mod bird_medium;
|
||||
pub mod bird_small;
|
||||
pub mod character;
|
||||
pub mod critter;
|
||||
pub mod dragon;
|
||||
#[cfg(feature = "use-dyn-lib")] pub mod dyn_lib;
|
||||
pub mod fish_medium;
|
||||
pub mod fish_small;
|
||||
pub mod fixture;
|
||||
pub mod golem;
|
||||
pub mod object;
|
||||
pub mod quadruped_medium;
|
||||
pub mod quadruped_small;
|
||||
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
pub use dyn_lib::init;
|
||||
|
||||
use vek::*;
|
||||
|
||||
// TODO: replace with inner type everywhere
|
||||
pub struct FigureBoneData(pub Mat4<f32>);
|
||||
impl FigureBoneData {
|
||||
pub fn new(mat: Mat4<f32>) -> Self { Self(mat) }
|
||||
|
||||
pub fn default() -> Self { Self(Mat4::identity()) }
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct Bone {
|
||||
pub offset: Vec3<f32>,
|
||||
pub ori: Quaternion<f32>,
|
||||
pub scale: Vec3<f32>,
|
||||
}
|
||||
|
||||
impl Default for Bone {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
offset: Vec3::zero(),
|
||||
ori: Quaternion::identity(),
|
||||
scale: Vec3::broadcast(1.0 / 11.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Bone {
|
||||
pub fn compute_base_matrix(&self) -> Mat4<f32> {
|
||||
Mat4::<f32>::translation_3d(self.offset)
|
||||
* Mat4::scaling_3d(self.scale)
|
||||
* Mat4::from(self.ori)
|
||||
}
|
||||
|
||||
/// Change the current bone to be more like `target`.
|
||||
fn interpolate(&mut self, target: &Bone, dt: f32) {
|
||||
// TODO: Make configurable.
|
||||
let factor = (15.0 * dt).min(1.0);
|
||||
self.offset += (target.offset - self.offset) * factor;
|
||||
self.ori = vek::Slerp::slerp(self.ori, target.ori, factor);
|
||||
self.scale += (target.scale - self.scale) * factor;
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Skeleton: Send + Sync + 'static {
|
||||
type Attr;
|
||||
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
const COMPUTE_FN: &'static [u8] = b"\0";
|
||||
|
||||
fn bone_count(&self) -> usize { 16 }
|
||||
|
||||
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
|
||||
#[cfg(not(feature = "use-dyn-lib"))]
|
||||
{
|
||||
Self::compute_matrices_inner(self)
|
||||
}
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
{
|
||||
let lock = dyn_lib::LIB.lock().unwrap();
|
||||
let lib = &lock.as_ref().unwrap().lib;
|
||||
|
||||
let compute_fn: libloading::Symbol<fn(&Self) -> ([FigureBoneData; 16], Vec3<f32>)> =
|
||||
unsafe { lib.get(Self::COMPUTE_FN).unwrap() };
|
||||
|
||||
compute_fn(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
|
||||
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);
|
||||
}
|
||||
|
||||
pub trait Animation {
|
||||
type Skeleton: Skeleton;
|
||||
type Dependency;
|
||||
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
const UPDATE_FN: &'static [u8] = b"\0";
|
||||
|
||||
/// Returns a new skeleton that is generated by the animation.
|
||||
fn update_skeleton(
|
||||
skeleton: &Self::Skeleton,
|
||||
dependency: Self::Dependency,
|
||||
anim_time: f64,
|
||||
rate: &mut f32,
|
||||
skeleton_attr: &<<Self as Animation>::Skeleton as Skeleton>::Attr,
|
||||
) -> Self::Skeleton {
|
||||
#[cfg(not(feature = "use-dyn-lib"))]
|
||||
{
|
||||
Self::update_skeleton_inner(skeleton, dependency, anim_time, rate, skeleton_attr)
|
||||
}
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
{
|
||||
let lock = dyn_lib::LIB.lock().unwrap();
|
||||
let lib = &lock.as_ref().unwrap().lib;
|
||||
|
||||
let update_fn: libloading::Symbol<
|
||||
fn(
|
||||
&Self::Skeleton,
|
||||
Self::Dependency,
|
||||
f64,
|
||||
&mut f32,
|
||||
&<Self::Skeleton as Skeleton>::Attr,
|
||||
) -> Self::Skeleton,
|
||||
> = unsafe {
|
||||
//let start = std::time::Instant::now();
|
||||
// Overhead of 0.5-5 us (could use hashmap to mitigate if this is an issue)
|
||||
let f = lib.get(Self::UPDATE_FN).unwrap();
|
||||
//println!("{}", start.elapsed().as_nanos());
|
||||
f
|
||||
};
|
||||
|
||||
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: &<<Self as Animation>::Skeleton as Skeleton>::Attr,
|
||||
) -> Self::Skeleton {
|
||||
panic!(
|
||||
"Neither update_skeleton_inner nor update_skeleton override present in Animation impl"
|
||||
)
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
use super::Skeleton;
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{FigureBoneData, Skeleton};
|
||||
use vek::*;
|
||||
|
||||
#[derive(Clone)]
|
@ -8,7 +8,11 @@ impl Animation for IdleAnimation {
|
||||
type Dependency = f64;
|
||||
type Skeleton = QuadrupedMediumSkeleton;
|
||||
|
||||
fn update_skeleton(
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
const UPDATE_FN: &'static [u8] = b"quadruped_medium_idle\0";
|
||||
|
||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_idle")]
|
||||
fn update_skeleton_inner(
|
||||
skeleton: &Self::Skeleton,
|
||||
global_time: Self::Dependency,
|
||||
anim_time: f64,
|
@ -7,7 +7,11 @@ impl Animation for JumpAnimation {
|
||||
type Dependency = (f32, f64);
|
||||
type Skeleton = QuadrupedMediumSkeleton;
|
||||
|
||||
fn update_skeleton(
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
const UPDATE_FN: &'static [u8] = b"quadruped_medium_jump\0";
|
||||
|
||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_jump")]
|
||||
fn update_skeleton_inner(
|
||||
skeleton: &Self::Skeleton,
|
||||
_global_time: Self::Dependency,
|
||||
_anim_time: f64,
|
@ -5,8 +5,7 @@ pub mod run;
|
||||
// Reexports
|
||||
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
|
||||
|
||||
use super::{Bone, Skeleton};
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{Bone, FigureBoneData, Skeleton};
|
||||
use common::comp::{self};
|
||||
use vek::Vec3;
|
||||
|
||||
@ -32,9 +31,13 @@ impl QuadrupedMediumSkeleton {
|
||||
impl Skeleton for QuadrupedMediumSkeleton {
|
||||
type Attr = SkeletonAttr;
|
||||
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
const COMPUTE_FN: &'static [u8] = b"quadruped_medium_compute_mats\0";
|
||||
|
||||
fn bone_count(&self) -> usize { 11 }
|
||||
|
||||
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
|
||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_compute_mats")]
|
||||
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
|
||||
let ears_mat = self.ears.compute_base_matrix();
|
||||
let head_upper_mat = self.head_upper.compute_base_matrix();
|
||||
let head_lower_mat = self.head_lower.compute_base_matrix();
|
@ -8,7 +8,11 @@ impl Animation for RunAnimation {
|
||||
type Dependency = (f32, f64);
|
||||
type Skeleton = QuadrupedMediumSkeleton;
|
||||
|
||||
fn update_skeleton(
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
const UPDATE_FN: &'static [u8] = b"quadruped_medium_run\0";
|
||||
|
||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_run")]
|
||||
fn update_skeleton_inner(
|
||||
skeleton: &Self::Skeleton,
|
||||
(_velocity, global_time): Self::Dependency,
|
||||
anim_time: f64,
|
@ -8,7 +8,11 @@ impl Animation for IdleAnimation {
|
||||
type Dependency = f64;
|
||||
type Skeleton = QuadrupedSmallSkeleton;
|
||||
|
||||
fn update_skeleton(
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
const UPDATE_FN: &'static [u8] = b"quadruped_small_idle\0";
|
||||
|
||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_small_idle")]
|
||||
fn update_skeleton_inner(
|
||||
skeleton: &Self::Skeleton,
|
||||
global_time: Self::Dependency,
|
||||
anim_time: f64,
|
@ -7,7 +7,11 @@ impl Animation for JumpAnimation {
|
||||
type Dependency = (f32, f64);
|
||||
type Skeleton = QuadrupedSmallSkeleton;
|
||||
|
||||
fn update_skeleton(
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
const UPDATE_FN: &'static [u8] = b"quadruped_small_jump\0";
|
||||
|
||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_small_jump")]
|
||||
fn update_skeleton_inner(
|
||||
skeleton: &Self::Skeleton,
|
||||
(_velocity, _global_time): Self::Dependency,
|
||||
_anim_time: f64,
|
@ -5,8 +5,7 @@ pub mod run;
|
||||
// Reexports
|
||||
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
|
||||
|
||||
use super::{Bone, Skeleton};
|
||||
use crate::render::FigureBoneData;
|
||||
use super::{Bone, FigureBoneData, Skeleton};
|
||||
use common::comp::{self};
|
||||
use vek::Vec3;
|
||||
|
||||
@ -28,9 +27,13 @@ impl QuadrupedSmallSkeleton {
|
||||
impl Skeleton for QuadrupedSmallSkeleton {
|
||||
type Attr = SkeletonAttr;
|
||||
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
const COMPUTE_FN: &'static [u8] = b"quadruped_small_compute_mats\0";
|
||||
|
||||
fn bone_count(&self) -> usize { 7 }
|
||||
|
||||
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
|
||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_small_compute_mats")]
|
||||
fn compute_matrices_inner(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
|
||||
let chest_mat = self.chest.compute_base_matrix();
|
||||
(
|
||||
[
|
@ -8,7 +8,11 @@ impl Animation for RunAnimation {
|
||||
type Dependency = (f32, f64);
|
||||
type Skeleton = QuadrupedSmallSkeleton;
|
||||
|
||||
fn update_skeleton(
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
const UPDATE_FN: &'static [u8] = b"quadruped_small_run\0";
|
||||
|
||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_small_run")]
|
||||
fn update_skeleton_inner(
|
||||
skeleton: &Self::Skeleton,
|
||||
(_velocity, _global_time): Self::Dependency,
|
||||
anim_time: f64,
|
@ -5,7 +5,6 @@
|
||||
|
||||
#[macro_use]
|
||||
pub mod ui;
|
||||
pub mod anim;
|
||||
pub mod audio;
|
||||
pub mod controller;
|
||||
mod ecs;
|
||||
|
@ -162,6 +162,10 @@ fn main() {
|
||||
default_hook(panic_info);
|
||||
}));
|
||||
|
||||
// Initialise watcher for animation hotreloading
|
||||
#[cfg(feature = "hot-anim")]
|
||||
anim::init();
|
||||
|
||||
// Set up the initial play state.
|
||||
let mut states: Vec<Box<dyn PlayState>> = vec![Box::new(MainMenuState::new(&mut global_state))];
|
||||
states
|
||||
|
@ -7,7 +7,6 @@ pub mod model;
|
||||
pub mod pipelines;
|
||||
pub mod renderer;
|
||||
pub mod texture;
|
||||
mod util;
|
||||
|
||||
// Reexports
|
||||
pub use self::{
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::{
|
||||
super::{util::arr_to_mat, Pipeline, TgtColorFmt, TgtDepthStencilFmt},
|
||||
super::{Pipeline, TgtColorFmt, TgtDepthStencilFmt},
|
||||
Globals, Light, Shadow,
|
||||
};
|
||||
use gfx::{
|
||||
@ -81,7 +81,7 @@ impl Locals {
|
||||
flags |= is_player as u32;
|
||||
|
||||
Self {
|
||||
model_mat: arr_to_mat(model_mat.into_col_array()),
|
||||
model_mat: model_mat.into_col_arrays(),
|
||||
model_col: col.into_array(),
|
||||
flags,
|
||||
}
|
||||
@ -95,7 +95,7 @@ impl Default for Locals {
|
||||
impl BoneData {
|
||||
pub fn new(bone_mat: Mat4<f32>) -> Self {
|
||||
Self {
|
||||
bone_mat: arr_to_mat(bone_mat.into_col_array()),
|
||||
bone_mat: bone_mat.into_col_arrays(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ pub mod sprite;
|
||||
pub mod terrain;
|
||||
pub mod ui;
|
||||
|
||||
use super::util::arr_to_mat;
|
||||
use crate::scene::camera::CameraMode;
|
||||
use common::terrain::BlockKind;
|
||||
use gfx::{self, gfx_constant_struct_meta, gfx_defines, gfx_impl_struct_meta};
|
||||
@ -64,9 +63,9 @@ impl Globals {
|
||||
sprite_render_distance: f32,
|
||||
) -> Self {
|
||||
Self {
|
||||
view_mat: arr_to_mat(view_mat.into_col_array()),
|
||||
proj_mat: arr_to_mat(proj_mat.into_col_array()),
|
||||
all_mat: arr_to_mat((proj_mat * view_mat).into_col_array()),
|
||||
view_mat: view_mat.into_col_arrays(),
|
||||
proj_mat: proj_mat.into_col_arrays(),
|
||||
all_mat: (proj_mat * view_mat).into_col_arrays(),
|
||||
cam_pos: Vec4::from(cam_pos).into_array(),
|
||||
focus_pos: Vec4::from(focus_pos).into_array(),
|
||||
view_distance: [view_distance; 4],
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::{
|
||||
super::{util::arr_to_mat, Pipeline, TgtColorFmt, TgtDepthStencilFmt},
|
||||
super::{Pipeline, TgtColorFmt, TgtDepthStencilFmt},
|
||||
Globals, Light, Shadow,
|
||||
};
|
||||
use gfx::{
|
||||
@ -67,7 +67,7 @@ impl Vertex {
|
||||
|
||||
impl Instance {
|
||||
pub fn new(mat: Mat4<f32>, col: Rgb<f32>, wind_sway: f32) -> Self {
|
||||
let mat_arr = arr_to_mat(mat.into_col_array());
|
||||
let mat_arr = mat.into_col_arrays();
|
||||
Self {
|
||||
inst_mat0: mat_arr[0],
|
||||
inst_mat1: mat_arr[1],
|
||||
|
@ -1,10 +0,0 @@
|
||||
// TODO: Get rid of this ugliness.
|
||||
#[rustfmt::skip]
|
||||
pub fn arr_to_mat(arr: [f32; 16]) -> [[f32; 4]; 4] {
|
||||
[
|
||||
[arr[ 0], arr[ 1], arr[ 2], arr[ 3]],
|
||||
[arr[ 4], arr[ 5], arr[ 6], arr[ 7]],
|
||||
[arr[ 8], arr[ 9], arr[10], arr[11]],
|
||||
[arr[12], arr[13], arr[14], arr[15]],
|
||||
]
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
use super::load::*;
|
||||
use crate::{
|
||||
anim::{self, Skeleton},
|
||||
mesh::Meshable,
|
||||
render::{FigurePipeline, Mesh, Model, Renderer},
|
||||
scene::camera::CameraMode,
|
||||
};
|
||||
use anim::{Skeleton};
|
||||
use common::{
|
||||
assets::watch::ReloadIndicator,
|
||||
comp::{
|
||||
|
@ -5,13 +5,6 @@ pub use cache::FigureModelCache;
|
||||
pub use load::load_mesh; // TODO: Don't make this public.
|
||||
|
||||
use crate::{
|
||||
anim::{
|
||||
self, biped_large::BipedLargeSkeleton, bird_medium::BirdMediumSkeleton,
|
||||
bird_small::BirdSmallSkeleton, character::CharacterSkeleton, critter::CritterSkeleton,
|
||||
dragon::DragonSkeleton, fish_medium::FishMediumSkeleton, fish_small::FishSmallSkeleton,
|
||||
golem::GolemSkeleton, object::ObjectSkeleton, quadruped_medium::QuadrupedMediumSkeleton,
|
||||
quadruped_small::QuadrupedSmallSkeleton, Animation, Skeleton,
|
||||
},
|
||||
ecs::comp::Interpolated,
|
||||
render::{Consts, FigureBoneData, FigureLocals, Globals, Light, Renderer, Shadow},
|
||||
scene::{
|
||||
@ -19,6 +12,13 @@ use crate::{
|
||||
SceneData,
|
||||
},
|
||||
};
|
||||
use anim::{
|
||||
biped_large::BipedLargeSkeleton, bird_medium::BirdMediumSkeleton,
|
||||
bird_small::BirdSmallSkeleton, character::CharacterSkeleton, critter::CritterSkeleton,
|
||||
dragon::DragonSkeleton, fish_medium::FishMediumSkeleton, fish_small::FishSmallSkeleton,
|
||||
golem::GolemSkeleton, object::ObjectSkeleton, quadruped_medium::QuadrupedMediumSkeleton,
|
||||
quadruped_small::QuadrupedSmallSkeleton, Animation, Skeleton,
|
||||
};
|
||||
use common::{
|
||||
comp::{
|
||||
item::ItemKind, Body, CharacterState, Last, LightAnimation, LightEmitter, Loadout, Ori,
|
||||
@ -2037,7 +2037,8 @@ pub struct FigureState<S: Skeleton> {
|
||||
|
||||
impl<S: Skeleton> FigureState<S> {
|
||||
pub fn new(renderer: &mut Renderer, skeleton: S) -> Self {
|
||||
let (bone_consts, lantern_offset) = skeleton.compute_matrices();
|
||||
let (bone_mats, lantern_offset) = skeleton.compute_matrices();
|
||||
let bone_consts = figure_bone_data_from_anim(bone_mats);
|
||||
Self {
|
||||
bone_consts: renderer.create_consts(&bone_consts).unwrap(),
|
||||
locals: renderer.create_consts(&[FigureLocals::default()]).unwrap(),
|
||||
@ -2081,7 +2082,9 @@ impl<S: Skeleton> FigureState<S> {
|
||||
let locals = FigureLocals::new(mat, col, is_player);
|
||||
renderer.update_consts(&mut self.locals, &[locals]).unwrap();
|
||||
|
||||
let (new_bone_consts, lantern_offset) = self.skeleton.compute_matrices();
|
||||
let (new_bone_mats, lantern_offset) = self.skeleton.compute_matrices();
|
||||
let new_bone_consts = figure_bone_data_from_anim(new_bone_mats);
|
||||
|
||||
renderer
|
||||
.update_consts(
|
||||
&mut self.bone_consts,
|
||||
@ -2097,3 +2100,24 @@ impl<S: Skeleton> FigureState<S> {
|
||||
|
||||
pub fn skeleton_mut(&mut self) -> &mut S { &mut self.skeleton }
|
||||
}
|
||||
|
||||
fn figure_bone_data_from_anim(mats: [anim::FigureBoneData; 16]) -> [FigureBoneData; 16] {
|
||||
[
|
||||
FigureBoneData::new(mats[0].0),
|
||||
FigureBoneData::new(mats[1].0),
|
||||
FigureBoneData::new(mats[2].0),
|
||||
FigureBoneData::new(mats[3].0),
|
||||
FigureBoneData::new(mats[4].0),
|
||||
FigureBoneData::new(mats[5].0),
|
||||
FigureBoneData::new(mats[6].0),
|
||||
FigureBoneData::new(mats[7].0),
|
||||
FigureBoneData::new(mats[8].0),
|
||||
FigureBoneData::new(mats[9].0),
|
||||
FigureBoneData::new(mats[10].0),
|
||||
FigureBoneData::new(mats[11].0),
|
||||
FigureBoneData::new(mats[12].0),
|
||||
FigureBoneData::new(mats[13].0),
|
||||
FigureBoneData::new(mats[14].0),
|
||||
FigureBoneData::new(mats[15].0),
|
||||
]
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use self::{
|
||||
terrain::Terrain,
|
||||
};
|
||||
use crate::{
|
||||
anim::character::SkeletonAttr,
|
||||
audio::{music::MusicMgr, sfx::SfxMgr, AudioFrontend},
|
||||
render::{
|
||||
create_pp_mesh, create_skybox_mesh, Consts, Globals, Light, Model, PostProcessLocals,
|
||||
@ -17,6 +16,7 @@ use crate::{
|
||||
},
|
||||
window::{AnalogGameInput, Event},
|
||||
};
|
||||
use anim::character::SkeletonAttr;
|
||||
use common::{
|
||||
comp,
|
||||
state::State,
|
||||
|
@ -1,9 +1,4 @@
|
||||
use crate::{
|
||||
anim::{
|
||||
character::{CharacterSkeleton, IdleAnimation, SkeletonAttr},
|
||||
fixture::FixtureSkeleton,
|
||||
Animation, Skeleton,
|
||||
},
|
||||
mesh::Meshable,
|
||||
render::{
|
||||
create_pp_mesh, create_skybox_mesh, Consts, FigurePipeline, Globals, Light, Mesh, Model,
|
||||
@ -15,6 +10,11 @@ use crate::{
|
||||
},
|
||||
window::{Event, PressState},
|
||||
};
|
||||
use anim::{
|
||||
character::{CharacterSkeleton, IdleAnimation, SkeletonAttr},
|
||||
fixture::FixtureSkeleton,
|
||||
Animation, Skeleton,
|
||||
};
|
||||
use common::{
|
||||
comp::{humanoid, Body, Loadout},
|
||||
figure::Segment,
|
||||
|
Loading…
Reference in New Issue
Block a user