From efcd9877d8e0704fd4b1e49f4f9d54e6f913d0e4 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sun, 19 Mar 2023 10:39:57 +1100 Subject: [PATCH] type params for camera work --- gb-vst/src/lib.rs | 6 +++--- lib/src/connect/mod.rs | 38 ++++++++++++++++++++++++++++++++++++-- lib/src/lib.rs | 21 ++++++++++++++++----- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/gb-vst/src/lib.rs b/gb-vst/src/lib.rs index 73acde5..16f60df 100644 --- a/gb-vst/src/lib.rs +++ b/gb-vst/src/lib.rs @@ -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, - emulator_core: EmulatorCore<[u8; 4], EmulatorRenderer>, + emulator_core: EmulatorCore<[u8; 4], EmulatorRenderer, NoCamera>, serial_tx: Sender, } diff --git a/lib/src/connect/mod.rs b/lib/src/connect/mod.rs index 640ce64..0d90a29 100644 --- a/lib/src/connect/mod.rs +++ b/lib/src/connect/mod.rs @@ -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 +pub struct EmulatorOptions where ColourFormat: From + Clone, R: Renderer, + C: PocketCamera, { pub(crate) window: R, pub(crate) tile_window: Option, pub(crate) rom: RomFile, pub(crate) output: AudioOutput, pub(crate) save_path: Option, + pub(crate) camera: C, pub(crate) no_save: bool, pub(crate) bootrom: Option, pub(crate) serial_target: SerialTarget, @@ -88,7 +98,7 @@ where spooky: PhantomData, } -impl EmulatorOptions +impl EmulatorOptions where ColourFormat: From + Clone, R: Renderer, @@ -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 EmulatorOptions +where + ColourFormat: From + Clone, + R: Renderer, + 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, diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 4877029..11fcd1f 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -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 = OnceCell::new(); pub const WIDTH: usize = 160; pub const HEIGHT: usize = 144; -pub struct EmulatorCore +pub struct EmulatorCore where ColourFormat: From + Clone, R: Renderer, + C: PocketCamera, { receiver: Receiver, cpu: Cpu, + spooky: PhantomData, } -impl EmulatorCore +impl EmulatorCore where ColourFormat: From + Clone, R: Renderer, + C: PocketCamera, { pub fn init( receiver: Receiver, - mut options: EmulatorOptions, + mut options: EmulatorOptions, ) -> Self { if options.verbose { VERBOSE.set(true).unwrap(); @@ -109,7 +115,11 @@ where } fn new(receiver: Receiver, cpu: Cpu) -> 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, } } }