feat: Dispatcher constructor separates render_rx

The dispatcher no longer owns the render results message channel, and
instead passes it out as a separate item during construction.
This commit is contained in:
2023-06-25 09:11:12 -05:00
parent 65185c7996
commit 995cfdf391
2 changed files with 10 additions and 11 deletions

View File

@@ -66,8 +66,7 @@ fn main() {
};
thread::scope(|s| {
let mut dispatcher = thread_utils::Dispatcher::new(&small_rng);
let scanline_receiver = dispatcher.render_rx;
let (mut dispatcher, mut scanline_receiver) = thread_utils::Dispatcher::new(&small_rng);
s.spawn(move || {
for y in (0..image.1).rev() {

View File

@@ -30,11 +30,10 @@ pub struct Dispatcher{
handles: Vec<thread::JoinHandle<()>>,
command_transmitters: Vec<mpsc::SyncSender<RenderCommand>>,
next_to_feed: usize, // gonna do a round-robin style dispatch, ig.
pub render_rx: mpsc::Receiver<RenderResult>,
}
impl Dispatcher {
pub fn new(srng: &SmallRng) -> Dispatcher {
pub fn new(srng: &SmallRng) -> (Dispatcher, mpsc::Receiver<RenderResult> ) {
let mut handles = Vec::new();
let mut command_transmitters = Vec::<mpsc::SyncSender<RenderCommand>>::new();
@@ -67,13 +66,14 @@ impl Dispatcher {
command_transmitters.push(command_tx);
}
// finally, stash everything in the Dispatcher struct and return.
Dispatcher{
handles,
command_transmitters,
next_to_feed: 0,
render_rx,
}
(
Dispatcher{
handles,
command_transmitters,
next_to_feed: 0,
},
render_rx
)
}
//TODO: Reconsider round-robin dispatch