mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
keyboard input is working for cpu window again
This commit is contained in:
@@ -35,12 +35,25 @@ pub fn run(mut update: Box<dyn FnMut(&mut dyn Framebuffer, u32, bool) -> Instant
|
||||
if let Some(sleep) = next_frame.checked_duration_since(Instant::now()) {
|
||||
std::thread::sleep(sleep);
|
||||
}
|
||||
|
||||
let mut gamepad = 0;
|
||||
for key in window.get_keys() {
|
||||
if let Some(index) = GAMEPAD_KEYS
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, &k)| k == key)
|
||||
.map(|(i, _)| i)
|
||||
{
|
||||
gamepad |= 1 << index;
|
||||
}
|
||||
}
|
||||
|
||||
next_frame = update(
|
||||
&mut CpuFramebuffer {
|
||||
buffer: &mut buffer,
|
||||
},
|
||||
0,
|
||||
false,
|
||||
gamepad,
|
||||
window.is_key_pressed(Key::R, minifb::KeyRepeat::No),
|
||||
);
|
||||
window.update_with_buffer(&buffer, 320, 240).unwrap();
|
||||
}
|
||||
|
||||
@@ -3,13 +3,18 @@ use std::time::Instant;
|
||||
mod cpu;
|
||||
mod gpu;
|
||||
|
||||
pub fn run<F: 'static + FnMut(&mut dyn Framebuffer, u32, bool) -> Instant>(update: F) -> ! {
|
||||
match gpu::Window::new() {
|
||||
Ok(window) => window.run(Box::new(update)),
|
||||
Err(err) => eprintln!(
|
||||
"Failed to create gpu window: {}\nFalling back to cpu window",
|
||||
err
|
||||
),
|
||||
pub fn run<F: 'static + FnMut(&mut dyn Framebuffer, u32, bool) -> Instant>(
|
||||
gpu: bool,
|
||||
update: F,
|
||||
) -> ! {
|
||||
if gpu {
|
||||
match gpu::Window::new() {
|
||||
Ok(window) => window.run(Box::new(update)),
|
||||
Err(err) => eprintln!(
|
||||
"Failed to create gpu window: {}\nFalling back to cpu window",
|
||||
err
|
||||
),
|
||||
}
|
||||
}
|
||||
cpu::run(Box::new(update));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user