feat: Output ordering!

As results come from the dispatcher('s return channel) they are pushed
into a vector to be reordered. They're sorted in reverse-order so that
they can be popped from the vector. Upon receipt and buffering of a
scanline, a loop checks the tail of the buffer to see if it's the
next-to-write element. Since the tail is popped off, this loop can run
until this condition is not met.
This commit is contained in:
2023-06-25 12:11:30 -05:00
parent 995cfdf391
commit 9873c5596d
2 changed files with 77 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ use crate::RenderContext;
use crate::Vec3;
use crate::render_line;
use core::cmp::Ordering;
use std::thread;
use std::sync::mpsc;
use rand::rngs::SmallRng;
@@ -17,6 +18,32 @@ pub struct RenderResult {
pub line: Vec<Vec3>,
}
impl Ord for RenderResult {
fn cmp(&self, other: &Self) -> Ordering {
if self.line_num > other.line_num {
Ordering::Less
} else if self.line_num < other.line_num {
Ordering::Greater
} else {
Ordering::Equal
}
}
}
impl PartialOrd for RenderResult {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl PartialEq for RenderResult {
fn eq(&self, other: &Self) -> bool {
self.line_num == other.line_num
}
}
impl Eq for RenderResult {}
/*
* The dispatcher will hold a list of threads, and a list of command input channels to match.
* Helper functions exist to input jobs serially, and then dispatch them to an open thread.