mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
register plugins before worldgen and support spots in plugins
This commit is contained in:
parent
24c511b5a4
commit
daa78a75ac
@ -623,6 +623,8 @@ impl Client {
|
|||||||
add_local_systems(dispatch_builder);
|
add_local_systems(dispatch_builder);
|
||||||
add_foreign_systems(dispatch_builder);
|
add_foreign_systems(dispatch_builder);
|
||||||
},
|
},
|
||||||
|
#[cfg(feature = "plugins")]
|
||||||
|
common_state::plugin::PluginMgr::from_asset_or_default(),
|
||||||
);
|
);
|
||||||
let mut missing_plugins: Vec<PluginHash> = Vec::new();
|
let mut missing_plugins: Vec<PluginHash> = Vec::new();
|
||||||
let mut local_plugins: Vec<PathBuf> = Vec::new();
|
let mut local_plugins: Vec<PathBuf> = Vec::new();
|
||||||
|
@ -178,6 +178,17 @@ pub struct PluginMgr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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<Self, PluginError> {
|
pub fn from_assets() -> Result<Self, PluginError> {
|
||||||
let mut assets_path = (*ASSETS_PATH).clone();
|
let mut assets_path = (*ASSETS_PATH).clone();
|
||||||
assets_path.push("plugins");
|
assets_path.push("plugins");
|
||||||
|
@ -156,6 +156,7 @@ impl State {
|
|||||||
map_size_lg: MapSizeLg,
|
map_size_lg: MapSizeLg,
|
||||||
default_chunk: Arc<TerrainChunk>,
|
default_chunk: Arc<TerrainChunk>,
|
||||||
add_systems: impl Fn(&mut DispatcherBuilder),
|
add_systems: impl Fn(&mut DispatcherBuilder),
|
||||||
|
#[cfg(feature = "plugins")] plugin_mgr: PluginMgr,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
GameMode::Client,
|
GameMode::Client,
|
||||||
@ -163,6 +164,8 @@ impl State {
|
|||||||
map_size_lg,
|
map_size_lg,
|
||||||
default_chunk,
|
default_chunk,
|
||||||
add_systems,
|
add_systems,
|
||||||
|
#[cfg(feature = "plugins")]
|
||||||
|
plugin_mgr,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,6 +175,7 @@ impl State {
|
|||||||
map_size_lg: MapSizeLg,
|
map_size_lg: MapSizeLg,
|
||||||
default_chunk: Arc<TerrainChunk>,
|
default_chunk: Arc<TerrainChunk>,
|
||||||
add_systems: impl Fn(&mut DispatcherBuilder),
|
add_systems: impl Fn(&mut DispatcherBuilder),
|
||||||
|
#[cfg(feature = "plugins")] plugin_mgr: PluginMgr,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
GameMode::Server,
|
GameMode::Server,
|
||||||
@ -179,6 +183,8 @@ impl State {
|
|||||||
map_size_lg,
|
map_size_lg,
|
||||||
default_chunk,
|
default_chunk,
|
||||||
add_systems,
|
add_systems,
|
||||||
|
#[cfg(feature = "plugins")]
|
||||||
|
plugin_mgr,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,6 +194,7 @@ impl State {
|
|||||||
map_size_lg: MapSizeLg,
|
map_size_lg: MapSizeLg,
|
||||||
default_chunk: Arc<TerrainChunk>,
|
default_chunk: Arc<TerrainChunk>,
|
||||||
add_systems: impl Fn(&mut DispatcherBuilder),
|
add_systems: impl Fn(&mut DispatcherBuilder),
|
||||||
|
#[cfg(feature = "plugins")] plugin_mgr: PluginMgr,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
prof_span!(guard, "create dispatcher");
|
prof_span!(guard, "create dispatcher");
|
||||||
let mut dispatch_builder =
|
let mut dispatch_builder =
|
||||||
@ -201,7 +208,14 @@ impl State {
|
|||||||
drop(guard);
|
drop(guard);
|
||||||
|
|
||||||
Self {
|
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,
|
thread_pool: pools,
|
||||||
dispatcher,
|
dispatcher,
|
||||||
}
|
}
|
||||||
@ -215,6 +229,7 @@ impl State {
|
|||||||
thread_pool: Arc<ThreadPool>,
|
thread_pool: Arc<ThreadPool>,
|
||||||
map_size_lg: MapSizeLg,
|
map_size_lg: MapSizeLg,
|
||||||
default_chunk: Arc<TerrainChunk>,
|
default_chunk: Arc<TerrainChunk>,
|
||||||
|
#[cfg(feature = "plugins")] mut plugin_mgr: PluginMgr,
|
||||||
) -> specs::World {
|
) -> specs::World {
|
||||||
prof_span!("State::setup_ecs_world");
|
prof_span!("State::setup_ecs_world");
|
||||||
let mut ecs = specs::World::new();
|
let mut ecs = specs::World::new();
|
||||||
@ -340,8 +355,7 @@ impl State {
|
|||||||
|
|
||||||
// Load plugins from asset directory
|
// Load plugins from asset directory
|
||||||
#[cfg(feature = "plugins")]
|
#[cfg(feature = "plugins")]
|
||||||
ecs.insert(match PluginMgr::from_assets() {
|
ecs.insert({
|
||||||
Ok(mut plugin_mgr) => {
|
|
||||||
let ecs_world = EcsWorld {
|
let ecs_world = EcsWorld {
|
||||||
entities: &ecs.entities(),
|
entities: &ecs.entities(),
|
||||||
health: ecs.read_component().into(),
|
health: ecs.read_component().into(),
|
||||||
@ -356,12 +370,6 @@ impl State {
|
|||||||
} else {
|
} else {
|
||||||
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()
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ecs
|
ecs
|
||||||
|
@ -37,6 +37,7 @@ mod tests {
|
|||||||
|dispatch_builder| {
|
|dispatch_builder| {
|
||||||
dispatch::<character_behavior::Sys>(dispatch_builder, &[]);
|
dispatch::<character_behavior::Sys>(dispatch_builder, &[]);
|
||||||
},
|
},
|
||||||
|
common_state::plugin::PluginMgr::default(),
|
||||||
);
|
);
|
||||||
let msm = MaterialStatManifest::load().cloned();
|
let msm = MaterialStatManifest::load().cloned();
|
||||||
state.ecs_mut().insert(msm);
|
state.ecs_mut().insert(msm);
|
||||||
|
@ -43,6 +43,7 @@ pub fn setup(add_systems: impl Fn(&mut specs::DispatcherBuilder)) -> State {
|
|||||||
DEFAULT_WORLD_CHUNKS_LG,
|
DEFAULT_WORLD_CHUNKS_LG,
|
||||||
Arc::new(TerrainChunk::water(0)),
|
Arc::new(TerrainChunk::water(0)),
|
||||||
add_systems,
|
add_systems,
|
||||||
|
common_state::plugin::PluginMgr::default(),
|
||||||
);
|
);
|
||||||
state.ecs_mut().insert(MaterialStatManifest::with_empty());
|
state.ecs_mut().insert(MaterialStatManifest::with_empty());
|
||||||
state.ecs_mut().insert(AbilityMap::load().cloned());
|
state.ecs_mut().insert(AbilityMap::load().cloned());
|
||||||
|
@ -280,6 +280,10 @@ impl Server {
|
|||||||
|
|
||||||
let pools = State::pools(GameMode::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")]
|
#[cfg(feature = "worldgen")]
|
||||||
let (world, index) = World::generate(
|
let (world, index) = World::generate(
|
||||||
settings.world_seed,
|
settings.world_seed,
|
||||||
@ -337,6 +341,8 @@ impl Server {
|
|||||||
weather::add_server_systems(dispatcher_builder);
|
weather::add_server_systems(dispatcher_builder);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
#[cfg(feature = "plugins")]
|
||||||
|
plugin_mgr,
|
||||||
);
|
);
|
||||||
register_event_busses(state.ecs_mut());
|
register_event_busses(state.ecs_mut());
|
||||||
state.ecs_mut().insert(battlemode_buffer);
|
state.ecs_mut().insert(battlemode_buffer);
|
||||||
|
@ -4,7 +4,7 @@ use crate::{
|
|||||||
Canvas,
|
Canvas,
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
assets::{Asset, AssetExt, AssetHandle, RonLoader},
|
assets::{Asset, AssetCombined, AssetHandle, Concatenate, RonLoader},
|
||||||
generation::EntityInfo,
|
generation::EntityInfo,
|
||||||
terrain::{BiomeKind, Structure, TerrainChunkSize},
|
terrain::{BiomeKind, Structure, TerrainChunkSize},
|
||||||
vol::RectVolSize,
|
vol::RectVolSize,
|
||||||
@ -686,9 +686,14 @@ impl Asset for RonSpots {
|
|||||||
const EXTENSION: &'static str = "ron";
|
const EXTENSION: &'static str = "ron";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Concatenate for RonSpots {
|
||||||
|
fn concatenate(self, b: Self) -> Self { Self(self.0.concatenate(b.0)) }
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref RON_PROPERTIES: RonSpots = {
|
static ref RON_PROPERTIES: RonSpots = {
|
||||||
let spots: AssetHandle<RonSpots> = AssetExt::load_expect("world.manifests.spots");
|
let spots: AssetHandle<RonSpots> =
|
||||||
|
RonSpots::load_expect_combined_static("world.manifests.spots");
|
||||||
RonSpots(spots.read().0.to_vec())
|
RonSpots(spots.read().0.to_vec())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user