Make system dispatching multi-threaded
This commit is contained in:
parent
097b8afb8a
commit
3a9ad932e4
@ -15,17 +15,17 @@ mod trigger_system;
|
|||||||
mod visibility_system;
|
mod visibility_system;
|
||||||
|
|
||||||
// System imports
|
// System imports
|
||||||
pub use ai::*;
|
use ai::*;
|
||||||
pub use hunger_system::HungerSystem;
|
use hunger_system::HungerSystem;
|
||||||
pub use inventory_system::*;
|
use inventory_system::*;
|
||||||
pub use lighting_system::LightingSystem;
|
use lighting_system::LightingSystem;
|
||||||
pub use map_indexing_system::MapIndexingSystem;
|
use map_indexing_system::MapIndexingSystem;
|
||||||
pub use melee_combat_system::MeleeCombatSystem;
|
use melee_combat_system::MeleeCombatSystem;
|
||||||
pub use movement_system::MovementSystem;
|
use movement_system::MovementSystem;
|
||||||
pub use particle_system::ParticleSpawnSystem;
|
use particle_system::ParticleSpawnSystem;
|
||||||
pub use ranged_combat_system::RangedCombatSystem;
|
use ranged_combat_system::RangedCombatSystem;
|
||||||
pub use trigger_system::TriggerSystem;
|
use trigger_system::TriggerSystem;
|
||||||
pub use visibility_system::VisibilitySystem;
|
use visibility_system::VisibilitySystem;
|
||||||
|
|
||||||
pub fn build() -> Box<dyn UnifiedDispatcher + 'static> {
|
pub fn build() -> Box<dyn UnifiedDispatcher + 'static> {
|
||||||
dispatcher::new()
|
dispatcher::new()
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod single_thread;
|
mod single_thread;
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[macro_use]
|
||||||
|
mod multi_thread;
|
||||||
|
|
||||||
use ::specs::prelude::World;
|
use ::specs::prelude::World;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub use multi_thread::*;
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub use single_thread::*;
|
pub use single_thread::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
44
src/systems/dispatcher/multi_thread.rs
Normal file
44
src/systems/dispatcher/multi_thread.rs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
|
use super::UnifiedDispatcher;
|
||||||
|
|
||||||
|
macro_rules! construct_dispatcher {
|
||||||
|
(
|
||||||
|
$(
|
||||||
|
(
|
||||||
|
$type:ident,
|
||||||
|
$name:expr,
|
||||||
|
$deps:expr
|
||||||
|
)
|
||||||
|
),*
|
||||||
|
) => {
|
||||||
|
fn new_dispatch() -> Box<dyn UnifiedDispatcher + 'static> {
|
||||||
|
use ::specs::DispatcherBuilder;
|
||||||
|
|
||||||
|
let dispatcher = DispatcherBuilder::new()
|
||||||
|
$(
|
||||||
|
.with($type{}, $name, $deps)
|
||||||
|
)*
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let dispatch = MultiThreadedDispatcher {
|
||||||
|
dispatcher: dispatcher
|
||||||
|
};
|
||||||
|
|
||||||
|
return Box::new(dispatch);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct MultiThreadedDispatcher {
|
||||||
|
pub dispatcher: ::specs::Dispatcher<'static, 'static>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> UnifiedDispatcher for MultiThreadedDispatcher {
|
||||||
|
fn run_now(&mut self, ecs: *mut World) {
|
||||||
|
unsafe {
|
||||||
|
self.dispatcher.dispatch(&mut *ecs);
|
||||||
|
crate::effects::run_effects_queue(&mut *ecs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use super::super::*;
|
|
||||||
use super::UnifiedDispatcher;
|
use super::UnifiedDispatcher;
|
||||||
|
|
||||||
macro_rules! construct_dispatcher {
|
macro_rules! construct_dispatcher {
|
||||||
|
Loading…
Reference in New Issue
Block a user