Separate timing of rendering and image writing in print out.

This commit is contained in:
Nathan Vegdahl 2016-08-20 16:25:12 -07:00
parent cf49cdbb02
commit c997c55739
2 changed files with 11 additions and 8 deletions

View File

@ -44,6 +44,7 @@ use std::mem;
use std::io; use std::io;
use std::io::Read; use std::io::Read;
use std::fs::File; use std::fs::File;
use std::path::Path;
use docopt::Docopt; use docopt::Docopt;
@ -146,8 +147,12 @@ fn main() {
println!("\tBuilt scene in {:.3}s", t.tick()); println!("\tBuilt scene in {:.3}s", t.tick());
println!("Rendering scene with {} threads...", thread_count); println!("Rendering scene with {} threads...", thread_count);
r.render(thread_count); let mut image = r.render(thread_count);
println!("\tRendered scene in {:.3}s", t.tick()); println!("\tRendered scene in {:.3}s", t.tick());
println!("Writing image to disk...");
let _ = image.write_png(Path::new(&r.output_file));
println!("\tWrote image in {:.3}s", t.tick());
} }
} }
} }

View File

@ -1,6 +1,5 @@
use std::cmp; use std::cmp;
use std::io::{self, Write}; use std::io::{self, Write};
use std::path::Path;
use std::cmp::min; use std::cmp::min;
use std::cell::Cell; use std::cell::Cell;
use std::sync::{RwLock, Mutex}; use std::sync::{RwLock, Mutex};
@ -29,10 +28,10 @@ pub struct Renderer {
} }
impl Renderer { impl Renderer {
pub fn render(&self, thread_count: u32) { pub fn render(&self, thread_count: u32) -> Image {
let mut tpool = Pool::new(thread_count); let mut tpool = Pool::new(thread_count);
let mut image = Image::new(self.resolution.0, self.resolution.1); let image = Image::new(self.resolution.0, self.resolution.1);
let (img_width, img_height) = (image.width(), image.height()); let (img_width, img_height) = (image.width(), image.height());
let all_jobs_queued = RwLock::new(false); let all_jobs_queued = RwLock::new(false);
@ -215,12 +214,11 @@ impl Renderer {
*all_jobs_queued.write().unwrap() = true; *all_jobs_queued.write().unwrap() = true;
}); });
// Write rendered image to disk
let _ = image.write_png(Path::new(&self.output_file));
// Clear percentage progress print // Clear percentage progress print
print!("\r \r"); print!("\r \r");
// Return the rendered image
return image;
} }
} }