Basic output system
This commit is contained in:
@ -0,0 +1,27 @@
|
||||
use minifb::{Window, WindowOptions};
|
||||
use viperid::{Device, VResult, SCREEN_H, SCREEN_W};
|
||||
|
||||
pub fn host(
|
||||
device: Device,
|
||||
mut update: impl FnMut() -> VResult<()>
|
||||
) -> VResult<()> {
|
||||
let mut window = Window::new(
|
||||
"viperid",
|
||||
SCREEN_W,
|
||||
SCREEN_H,
|
||||
WindowOptions::default()
|
||||
)?;
|
||||
|
||||
// limit to 60FPS
|
||||
window.limit_update_rate(Some(std::time::Duration::from_micros(16600)));
|
||||
|
||||
let mut buffer: Vec<u32> = vec![0; SCREEN_W * SCREEN_H];
|
||||
while window.is_open() {
|
||||
update()?;
|
||||
device.shared.screen.to_bitmap(&mut buffer);
|
||||
|
||||
window.update_with_buffer(&buffer, SCREEN_W, SCREEN_H)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user