From daa78a75acc4a7b00b4a94b8106387984f5c295a Mon Sep 17 00:00:00 2001 From: Isse Date: Sat, 24 Feb 2024 15:22:17 +0100 Subject: [PATCH 1/3] register plugins before worldgen and support spots in plugins --- client/src/lib.rs | 2 + common/state/src/plugin/mod.rs | 11 ++++++ common/state/src/state.rs | 50 ++++++++++++++----------- common/systems/tests/character_state.rs | 1 + common/systems/tests/phys/utils.rs | 1 + server/src/lib.rs | 6 +++ world/src/layer/spot.rs | 9 ++++- 7 files changed, 57 insertions(+), 23 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index c08cb3a0bc..2d544a7809 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -623,6 +623,8 @@ impl Client { add_local_systems(dispatch_builder); add_foreign_systems(dispatch_builder); }, + #[cfg(feature = "plugins")] + common_state::plugin::PluginMgr::from_asset_or_default(), ); let mut missing_plugins: Vec = Vec::new(); let mut local_plugins: Vec = Vec::new(); diff --git a/common/state/src/plugin/mod.rs b/common/state/src/plugin/mod.rs index d4ce8dcf0c..097d7ac040 100644 --- a/common/state/src/plugin/mod.rs +++ b/common/state/src/plugin/mod.rs @@ -178,6 +178,17 @@ pub struct PluginMgr { } impl PluginMgr { + pub fn from_asset_or_default() -> Self { + match Self::from_assets() { + Ok(plugin_mgr) => plugin_mgr, + Err(e) => { + tracing::debug!(?e, "Failed to read plugins from assets"); + tracing::info!("Plugins disabled, enable debug logging for more information."); + PluginMgr::default() + }, + } + } + pub fn from_assets() -> Result { let mut assets_path = (*ASSETS_PATH).clone(); assets_path.push("plugins"); diff --git a/common/state/src/state.rs b/common/state/src/state.rs index 2111e3f768..0d1b98438f 100644 --- a/common/state/src/state.rs +++ b/common/state/src/state.rs @@ -156,6 +156,7 @@ impl State { map_size_lg: MapSizeLg, default_chunk: Arc, add_systems: impl Fn(&mut DispatcherBuilder), + #[cfg(feature = "plugins")] plugin_mgr: PluginMgr, ) -> Self { Self::new( GameMode::Client, @@ -163,6 +164,8 @@ impl State { map_size_lg, default_chunk, add_systems, + #[cfg(feature = "plugins")] + plugin_mgr, ) } @@ -172,6 +175,7 @@ impl State { map_size_lg: MapSizeLg, default_chunk: Arc, add_systems: impl Fn(&mut DispatcherBuilder), + #[cfg(feature = "plugins")] plugin_mgr: PluginMgr, ) -> Self { Self::new( GameMode::Server, @@ -179,6 +183,8 @@ impl State { map_size_lg, default_chunk, add_systems, + #[cfg(feature = "plugins")] + plugin_mgr, ) } @@ -188,6 +194,7 @@ impl State { map_size_lg: MapSizeLg, default_chunk: Arc, add_systems: impl Fn(&mut DispatcherBuilder), + #[cfg(feature = "plugins")] plugin_mgr: PluginMgr, ) -> Self { prof_span!(guard, "create dispatcher"); let mut dispatch_builder = @@ -201,7 +208,14 @@ impl State { drop(guard); Self { - ecs: Self::setup_ecs_world(game_mode, Arc::clone(&pools), map_size_lg, default_chunk), + ecs: Self::setup_ecs_world( + game_mode, + Arc::clone(&pools), + map_size_lg, + default_chunk, + #[cfg(feature = "plugins")] + plugin_mgr, + ), thread_pool: pools, dispatcher, } @@ -215,6 +229,7 @@ impl State { thread_pool: Arc, map_size_lg: MapSizeLg, default_chunk: Arc, + #[cfg(feature = "plugins")] mut plugin_mgr: PluginMgr, ) -> specs::World { prof_span!("State::setup_ecs_world"); let mut ecs = specs::World::new(); @@ -340,28 +355,21 @@ impl State { // Load plugins from asset directory #[cfg(feature = "plugins")] - ecs.insert(match PluginMgr::from_assets() { - Ok(mut plugin_mgr) => { - let ecs_world = EcsWorld { - entities: &ecs.entities(), - health: ecs.read_component().into(), - uid: ecs.read_component().into(), - id_maps: &ecs.read_resource::().into(), - player: ecs.read_component().into(), - }; - if let Err(e) = plugin_mgr.load_event(&ecs_world, game_mode) { - tracing::debug!(?e, "Failed to run plugin init"); - tracing::info!("Plugins disabled, enable debug logging for more information."); - PluginMgr::default() - } else { - plugin_mgr - } - }, - Err(e) => { - tracing::debug!(?e, "Failed to read plugins from assets"); + ecs.insert({ + let ecs_world = EcsWorld { + entities: &ecs.entities(), + health: ecs.read_component().into(), + uid: ecs.read_component().into(), + id_maps: &ecs.read_resource::().into(), + player: ecs.read_component().into(), + }; + if let Err(e) = plugin_mgr.load_event(&ecs_world, game_mode) { + tracing::debug!(?e, "Failed to run plugin init"); tracing::info!("Plugins disabled, enable debug logging for more information."); PluginMgr::default() - }, + } else { + plugin_mgr + } }); ecs diff --git a/common/systems/tests/character_state.rs b/common/systems/tests/character_state.rs index 74cc50fd77..87d80cb2af 100644 --- a/common/systems/tests/character_state.rs +++ b/common/systems/tests/character_state.rs @@ -37,6 +37,7 @@ mod tests { |dispatch_builder| { dispatch::(dispatch_builder, &[]); }, + common_state::plugin::PluginMgr::default(), ); let msm = MaterialStatManifest::load().cloned(); state.ecs_mut().insert(msm); diff --git a/common/systems/tests/phys/utils.rs b/common/systems/tests/phys/utils.rs index 6ab734812a..82347f3e35 100644 --- a/common/systems/tests/phys/utils.rs +++ b/common/systems/tests/phys/utils.rs @@ -43,6 +43,7 @@ pub fn setup(add_systems: impl Fn(&mut specs::DispatcherBuilder)) -> State { DEFAULT_WORLD_CHUNKS_LG, Arc::new(TerrainChunk::water(0)), add_systems, + common_state::plugin::PluginMgr::default(), ); state.ecs_mut().insert(MaterialStatManifest::with_empty()); state.ecs_mut().insert(AbilityMap::load().cloned()); diff --git a/server/src/lib.rs b/server/src/lib.rs index b2d74f8a0d..2d0c06848b 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -280,6 +280,10 @@ impl Server { let pools = State::pools(GameMode::Server); + // Load plugins before generating the world. + #[cfg(feature = "plugins")] + let plugin_mgr = PluginMgr::from_asset_or_default(); + #[cfg(feature = "worldgen")] let (world, index) = World::generate( settings.world_seed, @@ -337,6 +341,8 @@ impl Server { weather::add_server_systems(dispatcher_builder); } }, + #[cfg(feature = "plugins")] + plugin_mgr, ); register_event_busses(state.ecs_mut()); state.ecs_mut().insert(battlemode_buffer); diff --git a/world/src/layer/spot.rs b/world/src/layer/spot.rs index 1ae8cc01d6..47aa69eb55 100644 --- a/world/src/layer/spot.rs +++ b/world/src/layer/spot.rs @@ -4,7 +4,7 @@ use crate::{ Canvas, }; use common::{ - assets::{Asset, AssetExt, AssetHandle, RonLoader}, + assets::{Asset, AssetCombined, AssetHandle, Concatenate, RonLoader}, generation::EntityInfo, terrain::{BiomeKind, Structure, TerrainChunkSize}, vol::RectVolSize, @@ -686,9 +686,14 @@ impl Asset for RonSpots { const EXTENSION: &'static str = "ron"; } +impl Concatenate for RonSpots { + fn concatenate(self, b: Self) -> Self { Self(self.0.concatenate(b.0)) } +} + lazy_static! { static ref RON_PROPERTIES: RonSpots = { - let spots: AssetHandle = AssetExt::load_expect("world.manifests.spots"); + let spots: AssetHandle = + RonSpots::load_expect_combined_static("world.manifests.spots"); RonSpots(spots.read().0.to_vec()) }; } From 5abc8e3a1d37cc59433f579432b709f12685655d Mon Sep 17 00:00:00 2001 From: Isse Date: Sat, 24 Feb 2024 15:55:48 +0100 Subject: [PATCH 2/3] fix voxygen disabling plugins on server even if plugins are on --- voxygen/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index c8a372ea9e..bc609b402f 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -27,7 +27,7 @@ singleplayer = ["server"] simd = ["vek/platform_intrinsics"] tracy = ["common-frontend/tracy", "client/tracy"] tracy-memory = ["tracy"] # enables heap profiling with tracy -plugins = ["client/plugins", "common-assets/plugins"] +plugins = ["client/plugins", "common-assets/plugins", "server/plugins"] egui-ui = ["voxygen-egui", "egui", "egui_wgpu_backend", "egui_winit_platform"] shaderc-from-source = ["shaderc/build-from-source"] discord = ["discord-sdk"] From 189158447717bae9ea14c5402046086c800fa7ca Mon Sep 17 00:00:00 2001 From: Isse Date: Tue, 27 Feb 2024 13:49:48 +0100 Subject: [PATCH 3/3] add to changelog --- CHANGELOG.md | 1 + common/state/src/plugin/mod.rs | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abfa5e9cba..2dc7876d7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - In commands that reference assets you can now use `#name` and press tab to cycle through assets with that name. - Allow moving and resizing the chat with left and right mouse button respectively - Missing plugins are requested from the server and cached locally +- Support for adding spots in plugins ### Changed diff --git a/common/state/src/plugin/mod.rs b/common/state/src/plugin/mod.rs index 097d7ac040..cf0aa4a1ec 100644 --- a/common/state/src/plugin/mod.rs +++ b/common/state/src/plugin/mod.rs @@ -182,8 +182,7 @@ impl PluginMgr { match Self::from_assets() { Ok(plugin_mgr) => plugin_mgr, Err(e) => { - tracing::debug!(?e, "Failed to read plugins from assets"); - tracing::info!("Plugins disabled, enable debug logging for more information."); + tracing::error!(?e, "Failed to read plugins from assets"); PluginMgr::default() }, }