Skip to content

Instantly share code, notes, and snippets.

@amarao
Last active May 4, 2019 18:31
Show Gist options
  • Save amarao/57265c4d7cef413b3b666963c37de061 to your computer and use it in GitHub Desktop.
Save amarao/57265c4d7cef413b3b666963c37de061 to your computer and use it in GitHub Desktop.
extern crate minifb;
use std::time::{Duration, Instant};
use std::thread::sleep;
use minifb::{Key, WindowOptions, Window};
fn main() {
let mut buffer: Vec<u32> = vec![0; 2048 * 1024];
let mut window = Window::new("Test - ESC to exit",
2048,
1024,
WindowOptions::default()
).unwrap();
let mut cnt: u32 = 0;
for i in buffer.iter_mut() {
*i = cnt;
cnt+=1;
}
std::thread::sleep(Duration::new(0,15000000));
window.update_with_buffer(&buffer).unwrap();
while window.is_open() && !window.is_key_down(Key::Escape) {
let start = Instant::now();
window.update();
let spend = start.elapsed();
sleep(Duration::new(0,1000000000/60).checked_sub(spend).unwrap_or(Duration::new(0,0)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment