mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'dispatcher' into 'master'
Store a thread pool in State for the Dispatcher Closes #63 See merge request veloren/veloren!98 Former-commit-id: 948c18e3c902901505d8f7136f151971d47a7072
This commit is contained in:
commit
042d5bb571
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -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)",
|
||||
|
@ -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"
|
||||
|
@ -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<EcsPacket>,
|
||||
// Avoid lifetime annotation by storing a thread pool instead of the whole dispatcher
|
||||
thread_pool: Arc<ThreadPool>,
|
||||
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::<DeltaTime>().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);
|
||||
|
Loading…
Reference in New Issue
Block a user