Make FPS rate configurable, minor cleanup
This commit is contained in:
24
src/main.rs
24
src/main.rs
@@ -25,6 +25,9 @@ const DEFAULT_THREAD_COUNT: usize = 4;
|
||||
const DEFAULT_IMAGE_WIDTH: u32 = 1920;
|
||||
const DEFAULT_IMAGE_HEIGHT: u32 = 1080;
|
||||
|
||||
// The default frames per second rate
|
||||
const DEFAULT_IMAGE_FPS: u32 = 1;
|
||||
|
||||
// The amount of milliseconds to wait for an image, when a painter has no image.
|
||||
const PAINTER_IMAGE_WAIT_DELAY_MILLIS: u64 = 100;
|
||||
|
||||
@@ -80,10 +83,18 @@ fn main() {
|
||||
.parse::<u32>()
|
||||
.expect("Invalid Y offset");
|
||||
|
||||
// Get the FPS rate
|
||||
let fps = matches
|
||||
.value_of("fps")
|
||||
.unwrap_or(&format!("{}", DEFAULT_IMAGE_FPS))
|
||||
.parse::<u32>()
|
||||
.expect("Invalid frames per second rate");
|
||||
|
||||
// Start
|
||||
start(
|
||||
host,
|
||||
image_paths,
|
||||
fps,
|
||||
count,
|
||||
(width, height),
|
||||
(offset_x, offset_y)
|
||||
@@ -139,6 +150,12 @@ fn parse_args<'a>() -> ArgMatches<'a> {
|
||||
.value_name("PIXELS")
|
||||
.help("Drawing Y offset in pixels (def: 0)")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("fps")
|
||||
.short("r")
|
||||
.long("fps")
|
||||
.value_name("RATE")
|
||||
.help("Frames per second with multiple images (def: 1)")
|
||||
.takes_value(true))
|
||||
.get_matches()
|
||||
}
|
||||
|
||||
@@ -146,6 +163,7 @@ fn parse_args<'a>() -> ArgMatches<'a> {
|
||||
fn start(
|
||||
host: &str,
|
||||
image_paths: Vec<&str>,
|
||||
fps: u32,
|
||||
count: usize,
|
||||
size: (u32, u32),
|
||||
offset: (u32, u32)
|
||||
@@ -166,7 +184,11 @@ fn start(
|
||||
image_manager.tick(&mut canvas);
|
||||
|
||||
// Sleep until we need to show the next image
|
||||
thread::sleep(Duration::new(1, 0));
|
||||
thread::sleep(
|
||||
Duration::from_millis(
|
||||
(1000f32 / (fps as f32)) as u64
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user