type params for camera work

This commit is contained in:
Alex Janka 2023-03-19 10:39:57 +11:00
parent db394d663a
commit efcd9877d8
3 changed files with 55 additions and 10 deletions

View file

@ -2,8 +2,8 @@ use async_ringbuf::AsyncHeapConsumer;
use futures::executor;
use gb_emu_lib::{
connect::{
AudioOutput, DownsampleType, EmulatorMessage, EmulatorOptions, JoypadButtons, RomFile,
SerialTarget,
AudioOutput, DownsampleType, EmulatorMessage, EmulatorOptions, JoypadButtons, NoCamera,
RomFile, SerialTarget,
},
EmulatorCore,
};
@ -52,7 +52,7 @@ struct EmuParams {
struct EmuVars {
rx: AsyncHeapConsumer<[f32; 2]>,
sender: Sender<EmulatorMessage>,
emulator_core: EmulatorCore<[u8; 4], EmulatorRenderer>,
emulator_core: EmulatorCore<[u8; 4], EmulatorRenderer, NoCamera>,
serial_tx: Sender<u8>,
}

View file

@ -70,17 +70,27 @@ pub trait PocketCamera {
fn capture_greyscale(&mut self) -> [u8; 128 * 128];
}
pub struct NoCamera;
impl PocketCamera for NoCamera {
fn capture_greyscale(&mut self) -> [u8; 128 * 128] {
[0; 128 * 128]
}
}
#[non_exhaustive]
pub struct EmulatorOptions<ColourFormat, R>
pub struct EmulatorOptions<ColourFormat, R, C>
where
ColourFormat: From<Colour> + Clone,
R: Renderer<ColourFormat>,
C: PocketCamera,
{
pub(crate) window: R,
pub(crate) tile_window: Option<R>,
pub(crate) rom: RomFile,
pub(crate) output: AudioOutput,
pub(crate) save_path: Option<String>,
pub(crate) camera: C,
pub(crate) no_save: bool,
pub(crate) bootrom: Option<RomFile>,
pub(crate) serial_target: SerialTarget,
@ -88,7 +98,7 @@ where
spooky: PhantomData<ColourFormat>,
}
impl<ColourFormat, R> EmulatorOptions<ColourFormat, R>
impl<ColourFormat, R> EmulatorOptions<ColourFormat, R, NoCamera>
where
ColourFormat: From<Colour> + Clone,
R: Renderer<ColourFormat>,
@ -100,6 +110,30 @@ where
rom,
output,
save_path: None,
camera: NoCamera,
no_save: false,
bootrom: None,
serial_target: SerialTarget::None,
verbose: false,
spooky: PhantomData,
}
}
}
impl<ColourFormat, R, C> EmulatorOptions<ColourFormat, R, C>
where
ColourFormat: From<Colour> + Clone,
R: Renderer<ColourFormat>,
C: PocketCamera,
{
pub fn new_with_camera(window: R, rom: RomFile, output: AudioOutput, camera: C) -> Self {
Self {
window,
tile_window: None,
rom,
output,
save_path: None,
camera,
no_save: false,
bootrom: None,
serial_target: SerialTarget::None,

View file

@ -1,7 +1,9 @@
#![feature(exclusive_range_pattern, let_chains, bigint_helper_methods)]
use crate::{processor::memory::Memory, util::pause};
use connect::{AudioOutput, EmulatorMessage, EmulatorOptions, Renderer, RomFile, SerialTarget};
use connect::{
AudioOutput, EmulatorMessage, EmulatorOptions, PocketCamera, Renderer, RomFile, SerialTarget,
};
use once_cell::sync::OnceCell;
use processor::{
memory::{mmio::gpu::Colour, Rom},
@ -10,6 +12,7 @@ use processor::{
use std::{
fs::{self},
io::{stdout, Write},
marker::PhantomData,
path::PathBuf,
process::exit,
str::FromStr,
@ -30,23 +33,26 @@ static VERBOSE: OnceCell<bool> = OnceCell::new();
pub const WIDTH: usize = 160;
pub const HEIGHT: usize = 144;
pub struct EmulatorCore<ColourFormat, R>
pub struct EmulatorCore<ColourFormat, R, C>
where
ColourFormat: From<Colour> + Clone,
R: Renderer<ColourFormat>,
C: PocketCamera,
{
receiver: Receiver<EmulatorMessage>,
cpu: Cpu<ColourFormat, R>,
spooky: PhantomData<C>,
}
impl<ColourFormat, R> EmulatorCore<ColourFormat, R>
impl<ColourFormat, R, C> EmulatorCore<ColourFormat, R, C>
where
ColourFormat: From<Colour> + Clone,
R: Renderer<ColourFormat>,
C: PocketCamera,
{
pub fn init(
receiver: Receiver<EmulatorMessage>,
mut options: EmulatorOptions<ColourFormat, R>,
mut options: EmulatorOptions<ColourFormat, R, C>,
) -> Self {
if options.verbose {
VERBOSE.set(true).unwrap();
@ -109,7 +115,11 @@ where
}
fn new(receiver: Receiver<EmulatorMessage>, cpu: Cpu<ColourFormat, R>) -> Self {
Self { receiver, cpu }
Self {
receiver,
cpu,
spooky: PhantomData,
}
}
pub fn replace_output(&mut self, new: AudioOutput) {
@ -190,6 +200,7 @@ where
Self {
receiver,
cpu: Cpu::from_save_state(state, data, window, output, serial_target),
spooky: PhantomData,
}
}
}