Basic output system

This commit is contained in:
2024-04-22 19:57:27 -07:00
parent 082fbf3e80
commit aae336ca66
13 changed files with 959 additions and 91 deletions

View File

@ -6,3 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
minifb = "0.25.0"
viperid = { path = "../.." }

View File

@ -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(())
}