diff --git a/Cargo.lock b/Cargo.lock index 89d57d4ede..8581e7288a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -223,7 +223,7 @@ checksum = "792c2eca2af86c76ffd3e72ca564c33b5a5551d5ac3f4f87dce8c0b7c6434061" dependencies = [ "ahash 0.7.2", "bincode", - "crossbeam-channel", + "crossbeam-channel 0.5.0", "log", "notify 4.0.15", "parking_lot 0.11.1", @@ -1021,13 +1021,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd01a6eb3daaafa260f6fc94c3a6c36390abc2080e38e3e34ced87393fb77d80" dependencies = [ "cfg-if 1.0.0", - "crossbeam-channel", + "crossbeam-channel 0.5.0", "crossbeam-deque 0.8.0", "crossbeam-epoch 0.9.3", "crossbeam-queue", "crossbeam-utils 0.8.3", ] +[[package]] +name = "crossbeam-channel" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa" +dependencies = [ + "crossbeam-utils 0.6.6", +] + [[package]] name = "crossbeam-channel" version = "0.5.0" @@ -1098,6 +1107,16 @@ dependencies = [ "crossbeam-utils 0.8.3", ] +[[package]] +name = "crossbeam-utils" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" +dependencies = [ + "cfg-if 0.1.10", + "lazy_static", +] + [[package]] name = "crossbeam-utils" version = "0.7.2" @@ -2107,7 +2126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac2c82074cafb68b9e459c50c655f7eedcb92d6ee7166813802934bc6fc29fa3" dependencies = [ "ab_glyph", - "crossbeam-channel", + "crossbeam-channel 0.5.0", "crossbeam-deque 0.8.0", "linked-hash-map", "rayon", @@ -3183,7 +3202,7 @@ checksum = "e5fd82b93434edb9c00ae65ee741e0e081cdc8c63346ab9f687935a629aaf4c3" dependencies = [ "anymap", "bitflags", - "crossbeam-channel", + "crossbeam-channel 0.5.0", "filetime", "fsevent 2.0.2", "fsevent-sys 3.0.2", @@ -4020,7 +4039,7 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" dependencies = [ - "crossbeam-channel", + "crossbeam-channel 0.5.0", "crossbeam-deque 0.8.0", "crossbeam-utils 0.8.3", "lazy_static", @@ -5057,7 +5076,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9965507e507f12c8901432a33e31131222abac31edd90cabbcf85cf544b7127a" dependencies = [ "chrono", - "crossbeam-channel", + "crossbeam-channel 0.5.0", "tracing-subscriber", ] @@ -5299,6 +5318,17 @@ dependencies = [ "serde", ] +[[package]] +name = "uvth" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e5910f9106b96334c6cae1f1d77a764bda66ac4ca9f507f73259f184fe1bb6b" +dependencies = [ + "crossbeam-channel 0.3.9", + "log", + "num_cpus", +] + [[package]] name = "vcpkg" version = "0.2.11" @@ -5345,6 +5375,7 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", + "uvth", "vek", "veloren-common", "veloren-common-base", @@ -5362,7 +5393,7 @@ dependencies = [ "arraygen", "assets_manager", "criterion", - "crossbeam-channel", + "crossbeam-channel 0.5.0", "crossbeam-utils 0.8.3", "csv", "dot_vox", @@ -5465,7 +5496,7 @@ dependencies = [ "bytes", "clap", "criterion", - "crossbeam-channel", + "crossbeam-channel 0.5.0", "futures-core", "futures-util", "lazy_static", @@ -5531,7 +5562,7 @@ version = "0.9.0" dependencies = [ "authc", "chrono", - "crossbeam-channel", + "crossbeam-channel 0.5.0", "diesel", "diesel_migrations", "dotenv", @@ -5555,6 +5586,7 @@ dependencies = [ "specs-idvs", "tokio", "tracing", + "uvth", "vek", "veloren-common", "veloren-common-base", @@ -5574,6 +5606,7 @@ dependencies = [ "clap", "crossterm 0.19.0", "lazy_static", + "num_cpus", "ron", "serde", "signal-hook 0.3.7", @@ -5583,6 +5616,7 @@ dependencies = [ "tracing-subscriber", "tracing-tracy", "tui", + "uvth", "veloren-common", "veloren-common-base", "veloren-common-net", @@ -5644,6 +5678,7 @@ dependencies = [ "tracing-subscriber", "tracing-tracy", "treeculler", + "uvth", "vek", "veloren-client", "veloren-common", diff --git a/client/Cargo.toml b/client/Cargo.toml index 6c17fd38a0..0e78a77302 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -30,6 +30,7 @@ specs = { git = "https://github.com/amethyst/specs.git", rev = "5a9b71035007be0e vek = { version = "=0.14.1", features = ["serde"] } hashbrown = { version = "0.9", features = ["rayon", "serde", "nightly"] } authc = { git = "https://gitlab.com/veloren/auth.git", rev = "fb3dcbc4962b367253f8f2f92760ef44d2679c9a" } +uvth = "4.0.1" #bot only async-channel = { version = "1.6", optional = true } diff --git a/client/src/lib.rs b/client/src/lib.rs index 2b6019d3a4..2575e20d0d 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -138,6 +138,7 @@ pub struct Client { registered: bool, presence: Option, runtime: Arc, + background_threadpool: Arc, server_info: ServerInfo, world_data: WorldData, player_list: HashMap, @@ -197,6 +198,7 @@ impl Client { addr: ConnectionArgs, view_distance: Option, runtime: Arc, + background_threadpool: Arc, ) -> Result { let network = Network::new(Pid::new(), &runtime); @@ -443,6 +445,7 @@ impl Client { registered: false, presence: None, runtime, + background_threadpool, server_info, world_data: WorldData { lod_base, @@ -1850,12 +1853,14 @@ impl Client { * 1000.0 } - /// Get a reference to the client's runtime thread pool. This pool should be - /// used for any computationally expensive operations that run outside - /// of the main thread (i.e., threads that block on I/O operations are - /// exempt). + /// Get a reference to the client's async runtime. pub fn runtime(&self) -> &Arc { &self.runtime } + /// Get a reference to the client's background task threadpool. + /// This pool should be used for any computationally expensive operations that run outside + /// of the main thread (i.e., threads that block on I/O operations are exempt). + pub fn background_threadpool(&self) -> &Arc { &self.background_threadpool } + /// Get a reference to the client's game state. pub fn state(&self) -> &State { &self.state } diff --git a/common/src/lib.rs b/common/src/lib.rs index c78e861453..c9c6622a21 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -61,7 +61,7 @@ pub mod resources; #[cfg(not(target_arch = "wasm32"))] pub mod rtsim; #[cfg(not(target_arch = "wasm32"))] pub mod skillset_builder; -pub mod slowjob; +//pub mod slowjob; #[cfg(not(target_arch = "wasm32"))] pub mod spiral; #[cfg(not(target_arch = "wasm32"))] diff --git a/common/sys/src/state.rs b/common/sys/src/state.rs index ca31775284..fc26a97b22 100644 --- a/common/sys/src/state.rs +++ b/common/sys/src/state.rs @@ -11,7 +11,6 @@ use common::{ outcome::Outcome, region::RegionMap, resources::{DeltaTime, GameMode, PlayerEntity, Time, TimeOfDay}, - slowjob::SlowJobPool, terrain::{Block, TerrainChunk, TerrainGrid}, time::DayPeriod, trade::Trades, @@ -129,7 +128,7 @@ impl State { .unwrap(), ); Self { - ecs: Self::setup_ecs_world(game_mode, &thread_pool), + ecs: Self::setup_ecs_world(game_mode), thread_pool, } } @@ -137,7 +136,7 @@ impl State { /// Creates ecs world and registers all the common components and resources // TODO: Split up registering into server and client (e.g. move // EventBus to the server) - fn setup_ecs_world(game_mode: GameMode, thread_pool: &Arc) -> specs::World { + fn setup_ecs_world(game_mode: GameMode) -> specs::World { let mut ecs = specs::World::new(); // Uids for sync ecs.register_sync_marker(); @@ -227,10 +226,10 @@ impl State { ecs.insert(game_mode); ecs.insert(Vec::::new()); - let slow_limit = thread_pool.current_num_threads().max(2) as u64; - let slow_limit = slow_limit / 2 + slow_limit / 4; - tracing::trace!(?slow_limit, "Slow Thread limit"); - ecs.insert(SlowJobPool::new(slow_limit, Arc::clone(&thread_pool))); + //let slow_limit = thread_pool.current_num_threads().max(2) as u64; + //let slow_limit = slow_limit / 2 + slow_limit / 4; + //tracing::trace!(?slow_limit, "Slow Thread limit"); + //ecs.insert(SlowJobPool::new(slow_limit, Arc::clone(&thread_pool))); // TODO: only register on the server ecs.insert(EventBus::::default()); @@ -344,7 +343,7 @@ impl State { pub fn terrain(&self) -> Fetch { self.ecs.read_resource() } /// Get a reference to this state's terrain. - pub fn slow_job_pool(&self) -> Fetch { self.ecs.read_resource() } + //pub fn slow_job_pool(&self) -> Fetch { self.ecs.read_resource() } /// Get a writable reference to this state's terrain. pub fn terrain_mut(&self) -> FetchMut { self.ecs.write_resource() } diff --git a/server-cli/Cargo.toml b/server-cli/Cargo.toml index d7c22484fb..6deae39582 100644 --- a/server-cli/Cargo.toml +++ b/server-cli/Cargo.toml @@ -27,6 +27,8 @@ tracing = { version = "0.1", default-features = false } tracing-subscriber = { version = "0.2.3", default-features = false, features = ["env-filter", "fmt", "chrono", "ansi", "smallvec"] } ron = {version = "0.6", default-features = false} serde = {version = "1.0", features = [ "rc", "derive" ]} +uvth = "4.0.1" +num_cpus = "1.0" # Tracy tracing-tracy = { version = "0.6.0", optional = true } diff --git a/server-cli/src/main.rs b/server-cli/src/main.rs index 9258a71c82..1fba5f182d 100644 --- a/server-cli/src/main.rs +++ b/server-cli/src/main.rs @@ -108,6 +108,14 @@ fn main() -> io::Result<()> { .unwrap(), ); + let cores = num_cpus::get(); + let background_threadpool = Arc::new( + uvth::ThreadPoolBuilder::new() + .num_threads(cores.max(2) / 2 + cores / 4) + .name("background_threadpool".into()) + .build(), + ); + // Load server settings let mut server_settings = server::Settings::load(&server_data_dir); let mut editable_settings = server::EditableSettings::load(&server_data_dir); @@ -152,6 +160,7 @@ fn main() -> io::Result<()> { editable_settings, &server_data_dir, runtime, + background_threadpool, ) .expect("Failed to create server instance!"); diff --git a/server/Cargo.toml b/server/Cargo.toml index 3866cc5b55..806158d01e 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -49,6 +49,7 @@ diesel = { version = "1.4.3", features = ["sqlite"] } diesel_migrations = "1.4.0" dotenv = "0.15.0" slab = "0.4" +uvth = "4.0.1" # Plugins plugin-api = { package = "veloren-plugin-api", path = "../plugin/api"} diff --git a/server/src/chunk_generator.rs b/server/src/chunk_generator.rs index 06f27de086..f0fd7f4e84 100644 --- a/server/src/chunk_generator.rs +++ b/server/src/chunk_generator.rs @@ -1,7 +1,7 @@ use crate::metrics::ChunkGenMetrics; #[cfg(not(feature = "worldgen"))] use crate::test_world::{IndexOwned, World}; -use common::{generation::ChunkSupplement, slowjob::SlowJobPool, terrain::TerrainChunk}; +use common::{generation::ChunkSupplement, terrain::TerrainChunk}; use hashbrown::{hash_map::Entry, HashMap}; use specs::Entity as EcsEntity; use std::sync::{ @@ -39,7 +39,8 @@ impl ChunkGenerator { &mut self, entity: Option, key: Vec2, - slowjob_pool: &SlowJobPool, + //slowjob_pool: &SlowJobPool, + background_threadpool: &uvth::ThreadPool, world: Arc, index: IndexOwned, ) { @@ -52,7 +53,8 @@ impl ChunkGenerator { v.insert(Arc::clone(&cancel)); let chunk_tx = self.chunk_tx.clone(); self.metrics.chunks_requested.inc(); - slowjob_pool.spawn("CHUNK_GENERATOR", move || { + //slowjob_pool.spawn("CHUNK_GENERATOR", move || { + background_threadpool.execute(move || { let index = index.as_index_ref(); let payload = world .generate_chunk(index, key, || cancel.load(Ordering::Relaxed)) diff --git a/server/src/lib.rs b/server/src/lib.rs index 3869da74eb..3233fa2120 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -63,7 +63,6 @@ use common::{ recipe::default_recipe_book, resources::TimeOfDay, rtsim::RtSimEntity, - slowjob::SlowJobPool, terrain::TerrainChunkSize, uid::UidAllocator, }; @@ -137,6 +136,7 @@ pub struct Server { connection_handler: ConnectionHandler, runtime: Arc, + background_threadpool: Arc, metrics_shutdown: Arc, } @@ -150,6 +150,7 @@ impl Server { editable_settings: EditableSettings, data_dir: &std::path::Path, runtime: Arc, + background_threadpool: Arc, ) -> Result { info!("Server is data dir is: {}", data_dir.display()); if settings.auth_server_address.is_none() { @@ -196,10 +197,10 @@ impl Server { state.ecs_mut().insert(ecs_system_metrics); state.ecs_mut().insert(tick_metrics); state.ecs_mut().insert(physics_metrics); - state - .ecs_mut() - .write_resource::() - .configure("CHUNK_GENERATOR", |n| n / 2 + n / 4); + //state + // .ecs_mut() + // .write_resource::() + // .configure("CHUNK_GENERATOR", |n| n / 2 + n / 4); state .ecs_mut() .insert(ChunkGenerator::new(chunk_gen_metrics)); @@ -368,6 +369,7 @@ impl Server { connection_handler, runtime, + background_threadpool, metrics_shutdown, }; @@ -629,7 +631,8 @@ impl Server { let index = &mut self.index; let world = &mut self.world; let ecs = self.state.ecs_mut(); - let slow_jobs = ecs.write_resource::(); + //let slow_jobs = ecs.write_resource::(); + let background_threadpool = &self.background_threadpool; index.reload_colors_if_changed(|index| { let mut chunk_generator = ecs.write_resource::(); @@ -648,7 +651,8 @@ impl Server { chunk_generator.generate_chunk( None, pos, - &slow_jobs, + //&slow_jobs, + &background_threadpool, Arc::clone(&world), index.clone(), ); @@ -790,11 +794,12 @@ impl Server { pub fn generate_chunk(&mut self, entity: EcsEntity, key: Vec2) { let ecs = self.state.ecs(); - let slow_jobs = ecs.write_resource::(); + //let slow_jobs = ecs.write_resource::(); ecs.write_resource::().generate_chunk( Some(entity), key, - &slow_jobs, + //&slow_jobs, + &self.background_threadpool, Arc::clone(&self.world), self.index.clone(), ); @@ -982,7 +987,7 @@ impl Server { // rng.gen_range(-e/2..e/2 + 1)); let pos = comp::Pos(Vec3::from(world_dims_blocks.map(|e| e as f32 / 2.0))); self.state - .create_persister(pos, view_distance, &self.world, &self.index) + .create_persister(pos, view_distance, &self.world, &self.index, &self.background_threadpool) .build(); } } diff --git a/server/src/state_ext.rs b/server/src/state_ext.rs index 3a3dd43a81..c6bbd28896 100644 --- a/server/src/state_ext.rs +++ b/server/src/state_ext.rs @@ -11,7 +11,6 @@ use common::{ Inventory, }, effect::Effect, - slowjob::SlowJobPool, uid::{Uid, UidAllocator}, }; use common_net::{ @@ -80,6 +79,7 @@ pub trait StateExt { view_distance: u32, world: &std::sync::Arc, index: &world::IndexOwned, + background_threadpool: &uvth::ThreadPool, ) -> EcsEntityBuilder; /// Insert common/default components for a new character joining the server fn initialize_character_data(&mut self, entity: EcsEntity, character_id: CharacterId); @@ -324,13 +324,14 @@ impl StateExt for State { view_distance: u32, world: &std::sync::Arc, index: &world::IndexOwned, + background_threadpool: &uvth::ThreadPool, ) -> EcsEntityBuilder { use common::{terrain::TerrainChunkSize, vol::RectVolSize}; use std::sync::Arc; // Request chunks { let ecs = self.ecs(); - let slow_jobs = ecs.write_resource::(); + //let slow_jobs = ecs.write_resource::(); let mut chunk_generator = ecs.write_resource::(); let chunk_pos = self.terrain().pos_key(pos.0.map(|e| e as i32)); @@ -348,7 +349,7 @@ impl StateExt for State { * TerrainChunkSize::RECT_SIZE.x as f64 }) .for_each(|chunk_key| { - chunk_generator.generate_chunk(None, chunk_key, &slow_jobs, Arc::clone(world), index.clone()); + chunk_generator.generate_chunk(None, chunk_key, /*&slow_jobs,*/ background_threadpool, Arc::clone(world), index.clone()); }); } diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index ed8979c9bb..12f1c1cb6e 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -88,6 +88,7 @@ num_cpus = "1.0" # vec_map = { version = "0.8.2" } inline_tweak = "1.0.2" itertools = "0.10.0" +uvth = "4.0.1" # Tracy tracing-tracy = { version = "0.6.0", optional = true } diff --git a/voxygen/src/ecs/mod.rs b/voxygen/src/ecs/mod.rs index 701dbb334b..9d75a23fdf 100644 --- a/voxygen/src/ecs/mod.rs +++ b/voxygen/src/ecs/mod.rs @@ -2,7 +2,7 @@ pub mod comp; pub mod sys; use crate::audio::sfx::SfxEventItem; -use common::{event::EventBus, slowjob::SlowJobPool}; +use common::event::EventBus; use specs::{World, WorldExt}; pub fn init(world: &mut World) { @@ -10,9 +10,9 @@ pub fn init(world: &mut World) { world.register::(); { - let pool = world.read_resource::(); - pool.configure("FIGURE_MESHING", |n| n / 2); - pool.configure("TERRAIN_MESHING", |n| n / 2); + //let pool = world.read_resource::(); + //pool.configure("FIGURE_MESHING", |n| n / 2); + //pool.configure("TERRAIN_MESHING", |n| n / 2); } // Voxygen event buses diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index b51f4bfdd1..7ba5f28f30 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -148,7 +148,8 @@ impl PlayState for CharSelectionState { time: client.state().get_time(), delta_time: client.state().ecs().read_resource::().0, tick: client.get_tick(), - slow_job_pool: &client.state().slow_job_pool(), + //slow_job_pool: &client.state().slow_job_pool(), + background_threadpool: &client.background_threadpool(), body: humanoid_body, gamma: global_state.settings.graphics.gamma, exposure: global_state.settings.graphics.exposure, diff --git a/voxygen/src/menu/main/client_init.rs b/voxygen/src/menu/main/client_init.rs index d6574ff2ab..50da492a58 100644 --- a/voxygen/src/menu/main/client_init.rs +++ b/voxygen/src/menu/main/client_init.rs @@ -50,16 +50,17 @@ impl ClientInit { username: String, view_distance: Option, password: String, - runtime: Option>, + // Threadpool resources shared with the singleplayer server + shared_resources: Option<(Arc, Arc)>, ) -> Self { let (tx, rx) = unbounded(); let (trust_tx, trust_rx) = unbounded(); let cancel = Arc::new(AtomicBool::new(false)); let cancel2 = Arc::clone(&cancel); - let runtime = runtime.unwrap_or_else(|| { + let (runtime, background_threadpool) = shared_resources.unwrap_or_else(|| { let cores = num_cpus::get(); - Arc::new( + let runtime = Arc::new( runtime::Builder::new_multi_thread() .enable_all() .worker_threads(if cores > 4 { cores - 1 } else { cores }) @@ -70,7 +71,16 @@ impl ClientInit { }) .build() .unwrap(), - ) + + ); + + let threadpool = Arc::new(uvth::ThreadPoolBuilder::new() + .num_threads(cores.max(2) / 2 + cores / 4) + .name("background_threadpool".into()) + .build()); + + (runtime, threadpool) + }); let runtime2 = Arc::clone(&runtime); @@ -106,6 +116,7 @@ impl ClientInit { connection_args.clone(), view_distance, Arc::clone(&runtime2), + Arc::clone(&background_threadpool), ) .await { diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index f6d147177d..0bf266d5bc 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -69,7 +69,7 @@ impl PlayState for MainMenuState { { if let Some(singleplayer) = &global_state.singleplayer { match singleplayer.receiver.try_recv() { - Ok(Ok(runtime)) => { + Ok(Ok(shared_resources)) => { // Attempt login after the server is finished initializing attempt_login( &mut global_state.settings, @@ -78,7 +78,7 @@ impl PlayState for MainMenuState { "".to_owned(), ClientConnArgs::Resolved(ConnectionArgs::Mpsc(14004)), &mut self.client_init, - Some(runtime), + Some(shared_resources), ); }, Ok(Err(e)) => { @@ -339,7 +339,7 @@ fn attempt_login( password: String, connection_args: ClientConnArgs, client_init: &mut Option, - runtime: Option>, + shared_resources: Option<(Arc, Arc)>, ) { if comp::Player::alias_is_valid(&username) { // Don't try to connect if there is already a connection in progress. @@ -349,7 +349,7 @@ fn attempt_login( username, Some(settings.graphics.view_distance), password, - runtime, + shared_resources, )); } } else { diff --git a/voxygen/src/scene/figure/cache.rs b/voxygen/src/scene/figure/cache.rs index 8ac24de101..3d8599da33 100644 --- a/voxygen/src/scene/figure/cache.rs +++ b/voxygen/src/scene/figure/cache.rs @@ -21,7 +21,6 @@ use common::{ CharacterState, }, figure::Segment, - slowjob::SlowJobPool, vol::BaseVol, }; use core::{hash::Hash, ops::Range}; @@ -338,7 +337,8 @@ where tick: u64, camera_mode: CameraMode, character_state: Option<&CharacterState>, - slow_jobs: &SlowJobPool, + //slow_jobs: &SlowJobPool, + background_threadpool: &uvth::ThreadPool, ) -> (FigureModelEntryLod<'c>, &'c Skel::Attr) where for<'a> &'a Skel::Body: Into, @@ -404,7 +404,8 @@ where let manifests = self.manifests; let slot_ = Arc::clone(&slot); - slow_jobs.spawn("FIGURE_MESHING", move || { + //slow_jobs.spawn("FIGURE_MESHING", move || { + background_threadpool.execute(move || { // First, load all the base vertex data. let manifests = &*manifests.read(); let meshes = ::bone_meshes(&key, manifests); diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index c34009b23b..40539ad858 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -561,7 +561,8 @@ impl FigureMgr { }; let camera_mode = camera.get_mode(); let character_state_storage = state.read_storage::(); - let slow_jobs = state.slow_job_pool(); + //let slow_jobs = state.slow_job_pool(); + let background_threadpool = scene_data.background_threadpool; let character_state = character_state_storage.get(scene_data.player_entity); let focus_pos = anim::vek::Vec3::::from(camera.get_focus_pos()); @@ -757,7 +758,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self @@ -1566,7 +1567,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self @@ -1768,7 +1769,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self @@ -2095,7 +2096,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self @@ -2454,7 +2455,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self @@ -2564,7 +2565,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self @@ -2653,7 +2654,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self @@ -3001,7 +3002,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = @@ -3095,7 +3096,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self @@ -3282,7 +3283,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self @@ -3373,7 +3374,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self @@ -3462,7 +3463,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self @@ -3954,7 +3955,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = @@ -4138,7 +4139,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = @@ -4266,7 +4267,7 @@ impl FigureMgr { tick, player_camera_mode, player_character_state, - &slow_jobs, + background_threadpool, ); let state = self diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index ca08799cfd..20ae5fbd4b 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -109,6 +109,7 @@ pub struct Scene { pub struct SceneData<'a> { pub state: &'a State, + pub background_threadpool: &'a uvth::ThreadPool, pub player_entity: specs::Entity, pub target_entity: Option, pub loaded_distance: f32, diff --git a/voxygen/src/scene/simple.rs b/voxygen/src/scene/simple.rs index 4901a5972c..60b234dbae 100644 --- a/voxygen/src/scene/simple.rs +++ b/voxygen/src/scene/simple.rs @@ -26,7 +26,6 @@ use common::{ item::ItemKind, }, figure::Segment, - slowjob::SlowJobPool, terrain::BlockKind, vol::{BaseVol, ReadVol}, }; @@ -97,7 +96,8 @@ pub struct SceneData<'a> { pub time: f64, pub delta_time: f32, pub tick: u64, - pub slow_job_pool: &'a SlowJobPool, + //pub slow_job_pool: &'a SlowJobPool, + pub background_threadpool: &'a uvth::ThreadPool, pub body: Option, pub gamma: f32, pub exposure: f32, @@ -357,7 +357,7 @@ impl Scene { scene_data.tick, CameraMode::default(), None, - scene_data.slow_job_pool, + scene_data.background_threadpool, ) .0; let mut buf = [Default::default(); anim::MAX_BONE_COUNT]; diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 85a1db5dce..d6393bbc04 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -800,9 +800,9 @@ impl Terrain { let cnt = Arc::clone(&self.mesh_todos_active); cnt.fetch_add(1, Ordering::Relaxed); scene_data - .state - .slow_job_pool() - .spawn("TERRAIN_MESHING", move || { + .background_threadpool + //.spawn("TERRAIN_MESHING", move || { + .execute(move || { let sprite_data = sprite_data; let _ = send.send(mesh_worker( pos, diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 8a5a66be2d..8421d71a8c 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -1511,6 +1511,7 @@ impl PlayState for SessionState { let client = self.client.borrow(); let scene_data = SceneData { state: client.state(), + background_threadpool: &client.background_threadpool(), player_entity: client.entity(), // Only highlight if interactable target_entity: self.interactable.and_then(Interactable::entity), @@ -1578,6 +1579,7 @@ impl PlayState for SessionState { let scene_data = SceneData { state: client.state(), + background_threadpool: &client.background_threadpool(), player_entity: client.entity(), // Only highlight if interactable target_entity: self.interactable.and_then(Interactable::entity), diff --git a/voxygen/src/singleplayer.rs b/voxygen/src/singleplayer.rs index 3e994d1361..c7d066b375 100644 --- a/voxygen/src/singleplayer.rs +++ b/voxygen/src/singleplayer.rs @@ -19,7 +19,7 @@ const TPS: u64 = 30; pub struct Singleplayer { _server_thread: JoinHandle<()>, stop_server_s: Sender<()>, - pub receiver: Receiver, ServerError>>, + pub receiver: Receiver, Arc), ServerError>>, // Wether the server is stopped or not paused: Arc, // Settings that the server was started with @@ -93,6 +93,13 @@ impl Singleplayer { .unwrap(), ); + let background_threadpool = Arc::new( + uvth::ThreadPoolBuilder::new() + .num_threads(cores.max(2) / 2 + cores / 4) + .name("background_threadpool".into()) + .build(), + ); + let settings2 = settings.clone(); let paused = Arc::new(AtomicBool::new(false)); @@ -111,10 +118,11 @@ impl Singleplayer { editable_settings, &server_data_dir, Arc::clone(&runtime), + Arc::clone(&background_threadpool), ) { Ok(s) => { server = Some(s); - Ok(runtime) + Ok((runtime, background_threadpool)) }, Err(e) => Err(e), },