roguelike-game/src/systems/dispatcher/multi_thread.rs

45 lines
1.0 KiB
Rust
Raw Normal View History

2022-02-03 10:17:02 -05:00
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);
}
}
}