diff --git a/Cargo.lock b/Cargo.lock index 3e40057f2e..e572ded28b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2289,9 +2289,9 @@ dependencies = [ "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "shred 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", "sphynx 0.1.0 (git+https://gitlab.com/veloren/sphynx.git)", "threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/assets/voxygen b/assets/voxygen index cff10b010d..7ebb1a9205 160000 --- a/assets/voxygen +++ b/assets/voxygen @@ -1 +1 @@ -Subproject commit cff10b010db25ce9af5edbdfb5ef0af889dd741a +Subproject commit 7ebb1a92057e6c0b9d989ffb7a5fe321599ddd6e diff --git a/common/Cargo.toml b/common/Cargo.toml index da924061fd..7c6a403538 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -7,8 +7,7 @@ edition = "2018" [dependencies] sphynx = { git = "https://gitlab.com/veloren/sphynx.git", features = ["serde1"] } -specs = { version = "0.14", features = ["serde"] } -shred = { version = "0.7", features = ["nightly"] } +specs = { version = "0.14", features = ["serde", "nightly"] } vek = { version = "0.9", features = ["serde"] } dot_vox = "4.0" threadpool = "1.7" @@ -19,3 +18,4 @@ serde_derive = "1.0" bincode = "1.0" log = "0.4" rand = "0.5" +rayon = "1.0" diff --git a/common/src/state.rs b/common/src/state.rs index 9e7646a988..447c9117e4 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -7,14 +7,15 @@ use crate::{ sys, terrain::{TerrainChunk, TerrainMap}, }; -use shred::{Fetch, FetchMut}; +use rayon::{ThreadPool, ThreadPoolBuilder}; use specs::{ saveload::{MarkedBuilder, MarkerAllocator}, + shred::{Fetch, FetchMut}, storage::{MaskedStorage as EcsMaskedStorage, Storage as EcsStorage}, Builder, Component, DispatcherBuilder, Entity as EcsEntity, EntityBuilder as EcsEntityBuilder, }; use sphynx; -use std::{collections::HashSet, time::Duration}; +use std::{collections::HashSet, sync::Arc, time::Duration}; use vek::*; /// How much faster should an in-game day be compared to a real day? @@ -57,6 +58,8 @@ impl Changes { /// things like entity components, terrain data, and global state like weather, time of day, etc. pub struct State { ecs: sphynx::World, + // Avoid lifetime annotation by storing a thread pool instead of the whole dispatcher + thread_pool: Arc, changes: Changes, } @@ -65,6 +68,7 @@ impl State { pub fn new() -> Self { Self { ecs: sphynx::World::new(specs::World::new(), Self::setup_sphynx_world), + thread_pool: Arc::new(ThreadPoolBuilder::new().build().unwrap()), changes: Changes::default(), } } @@ -77,6 +81,7 @@ impl State { Self::setup_sphynx_world, state_package, ), + thread_pool: Arc::new(ThreadPoolBuilder::new().build().unwrap()), changes: Changes::default(), } } @@ -197,7 +202,7 @@ impl State { self.ecs.write_resource::().0 = dt.as_secs_f64(); // Create and run dispatcher for ecs systems - let mut dispatch_builder = DispatcherBuilder::new(); + let mut dispatch_builder = DispatcherBuilder::new().with_pool(self.thread_pool.clone()); sys::add_local_systems(&mut dispatch_builder); // This dispatches all the systems in parallel dispatch_builder.build().dispatch(&self.ecs.res);