diff --git a/plugin/derive/src/lib.rs b/plugin/derive/src/lib.rs index 3a7ce33f8b..ae4a985191 100644 --- a/plugin/derive/src/lib.rs +++ b/plugin/derive/src/lib.rs @@ -14,7 +14,7 @@ pub fn global_state(_args: TokenStream, item: TokenStream) -> TokenStream { static mut PLUGIN_STATE: Option = None; - static PLUGIN_STATE_GUARD: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); + static PLUGIN_STATE_GUARD: core::sync::atomic::AtomicBool = core::sync::atomic::AtomicBool::new(false); }; out.into() } @@ -57,17 +57,13 @@ pub fn event_handler(_args: TokenStream, item: TokenStream) -> TokenStream { } // Artificially force the event handler to be type-correct fn force_event(event: E, inner: fn(E, &mut PLUGIN_STATE_TYPE) -> E::Response) -> E::Response { - //let mut plugin_state = PLUGIN_STATE.lock().unwrap(); - - assert_eq!(PLUGIN_STATE_GUARD.swap(true, std::sync::atomic::Ordering::Acquire), false); - unsafe { - if PLUGIN_STATE.is_none() { - PLUGIN_STATE = Some(PLUGIN_STATE_TYPE::default()); - } - } - let out = inner(event, unsafe {PLUGIN_STATE.as_mut().unwrap()}); - PLUGIN_STATE_GUARD.store(false, std::sync::atomic::Ordering::Release); - out + assert_eq!(PLUGIN_STATE_GUARD.swap(true, std::sync::atomic::Ordering::Acquire), false); + let out = inner( + event, + unsafe { PLUGIN_STATE.get_or_insert_with(core::default::Default::default) }, + ); + PLUGIN_STATE_GUARD.store(false, std::sync::atomic::Ordering::Release); + out } ::veloren_plugin_rt::write_output(&force_event(input, inner)) diff --git a/server-cli/Cargo.toml b/server-cli/Cargo.toml index 193fe74446..ca234a7a56 100644 --- a/server-cli/Cargo.toml +++ b/server-cli/Cargo.toml @@ -16,7 +16,7 @@ This package includes the official server CLI. [features] worldgen = ["server/worldgen"] -default = ["worldgen"] +default = ["worldgen", "plugins"] tracy = ["common/tracy", "server/tracy", "common-net/tracy", "common-frontend/tracy"] plugins = ["server/plugins"] diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index b84a19dcb5..33a757bac6 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -26,7 +26,7 @@ hot-anim = ["anim/use-dyn-lib"] singleplayer = ["server"] simd = ["vek/platform_intrinsics"] tracy = ["profiling", "profiling/profile-with-tracy", "common/tracy", "common-ecs/tracy", "common-frontend/tracy", "common-net/tracy", "common-systems/tracy", "common-state/tracy", "client/tracy"] -plugins = ["client/plugins"] +plugins = ["client/plugins", "server/plugins"] default = ["singleplayer", "native-dialog", "plugins", "simd"]