Reworked veloren_dynlib initialisation

This commit is contained in:
Ben Wallis 2021-06-20 18:52:28 +01:00
parent 9fd5c6e124
commit 1612b36753
4 changed files with 12 additions and 24 deletions

View File

@ -91,18 +91,12 @@ pub type Bone = Transform<f32, f32, f32>;
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
lazy_static! { lazy_static! {
static ref LIB: Arc<Mutex<Option<LoadedLib>>> = Arc::new(Mutex::new(None)); static ref LIB: Arc<Mutex<Option<LoadedLib>>> =
voxygen_dynlib::init("veloren-voxygen-anim", "veloren-voxygen-anim-dyn", "anim");
} }
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
pub fn init() { pub fn init() { lazy_static::initialize(&LIB); }
voxygen_dynlib::init(
Arc::clone(&LIB),
"veloren-voxygen-anim",
"veloren-voxygen-anim-dyn",
"anim",
);
}
pub trait Skeleton: Send + Sync + 'static { pub trait Skeleton: Send + Sync + 'static {
type Attr; type Attr;

View File

@ -120,12 +120,11 @@ impl LoadedLib {
/// This will search for the directory named `package_source_dir` and watch the /// This will search for the directory named `package_source_dir` and watch the
/// files within it for any changes. /// files within it for any changes.
pub fn init( pub fn init(
lib_storage: Arc<Mutex<Option<LoadedLib>>>,
package: &'static str, package: &'static str,
dyn_package: &'static str, dyn_package: &'static str,
package_source_dir: &'static str, package_source_dir: &'static str,
) { ) -> Arc<Mutex<Option<LoadedLib>>> {
*lib_storage.lock().unwrap() = Some(LoadedLib::compile_load(dyn_package)); let lib_storage = Arc::new(Mutex::new(Some(LoadedLib::compile_load(dyn_package))));
// TODO: use crossbeam // TODO: use crossbeam
let (reload_send, reload_recv) = mpsc::channel(); let (reload_send, reload_recv) = mpsc::channel();
@ -148,6 +147,7 @@ pub fn init(
// Start reloader that watcher signals // Start reloader that watcher signals
// "Debounces" events since I can't find the option to do this in the latest // "Debounces" events since I can't find the option to do this in the latest
// `notify` // `notify`
let lib_storage_clone = Arc::clone(&lib_storage);
std::thread::Builder::new() std::thread::Builder::new()
.name(format!("{}_hotreload_watcher", package)) .name(format!("{}_hotreload_watcher", package))
.spawn(move || { .spawn(move || {
@ -164,13 +164,15 @@ pub fn init(
"Hot reloading {} because files in `{}` modified.", package, package_source_dir "Hot reloading {} because files in `{}` modified.", package, package_source_dir
); );
hotreload(dyn_package, &lib_storage); hotreload(dyn_package, &lib_storage_clone);
} }
}) })
.unwrap(); .unwrap();
// Let the watcher live forever // Let the watcher live forever
std::mem::forget(watcher); std::mem::forget(watcher);
lib_storage
} }
fn compiled_file(dyn_package: &str) -> String { dyn_lib_file(dyn_package, false) } fn compiled_file(dyn_package: &str) -> String { dyn_lib_file(dyn_package, false) }

View File

@ -35,7 +35,8 @@ use {
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
lazy_static! { lazy_static! {
static ref LIB: Arc<Mutex<Option<LoadedLib>>> = Arc::new(Mutex::new(None)); static ref LIB: Arc<Mutex<Option<LoadedLib>>> =
voxygen_dynlib::init("veloren-voxygen-egui", "veloren-voxygen-egui-dyn", "egui");
} }
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
@ -103,14 +104,7 @@ pub struct EguiActions {
} }
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
pub fn init() { pub fn init() { lazy_static::initialize(&LIB); }
voxygen_dynlib::init(
Arc::clone(&LIB),
"veloren-voxygen-egui",
"veloren-voxygen-egui-dyn",
"egui",
);
}
pub fn maintain( pub fn maintain(
platform: &mut Platform, platform: &mut Platform,

View File

@ -19,8 +19,6 @@ use common::{
clock::Clock, clock::Clock,
}; };
use std::panic; use std::panic;
#[cfg(any(feature = "hot-anim", feature = "hot-egui"))]
use std::sync::Arc;
use tracing::{error, info, warn}; use tracing::{error, info, warn};
#[cfg(feature = "egui-ui")] #[cfg(feature = "egui-ui")]
use veloren_voxygen::ui::egui::EguiState; use veloren_voxygen::ui::egui::EguiState;