27 lines
664 B
Rust
27 lines
664 B
Rust
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(())
|
|
} |