rewrite it in rust #1

Merged
SonicSwordcane merged 20 commits from riir into main 2024-11-10 23:34:55 +00:00
1 changed files with 15 additions and 1 deletions
Showing only changes of commit 99d6970323 - Show all commits

View File

@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf},
sync::{
atomic::{AtomicBool, Ordering},
mpsc::{self, TryRecvError},
mpsc::{self, RecvError, TryRecvError},
Arc,
},
};
@ -94,19 +94,33 @@ impl Emulator {
let mut eye_contents = vec![0u8; 384 * 224 * 2];
let mut audio_samples = vec![];
loop {
let mut idle = true;
if self.running.load(Ordering::Acquire) {
idle = false;
self.sim.emulate_frame();
}
if let Some(renderer) = &mut self.renderer {
if self.sim.read_pixels(&mut eye_contents) {
idle = false;
renderer.render(&eye_contents);
}
}
self.sim.read_samples(&mut audio_samples);
if !audio_samples.is_empty() {
idle = false;
self.audio.update(&audio_samples);
audio_samples.clear();
}
if idle {
// The game is paused, and we have output all the video/audio we have.
// Block the thread until a new command comes in.
match self.commands.recv() {
Ok(command) => self.handle_command(command),
Err(RecvError) => {
return;
}
}
}
loop {
match self.commands.try_recv() {
Ok(command) => self.handle_command(command),