GameBoyAdvance: Use dyn traits instead of generic types

"Performance hit" is not significient


Former-commit-id: 809dea4cdbf9579d8e9d18de95b3c9a05723c68f
This commit is contained in:
Michel Heily 2019-12-23 01:27:25 +02:00
parent 398e66b723
commit 10d0934f82
5 changed files with 16 additions and 41 deletions

View file

@ -11,33 +11,23 @@ use super::sysbus::SysBus;
use super::super::{AudioInterface, InputInterface, VideoInterface}; use super::super::{AudioInterface, InputInterface, VideoInterface};
pub struct GameBoyAdvance<V, A, I> pub struct GameBoyAdvance {
where
V: VideoInterface,
A: AudioInterface,
I: InputInterface,
{
pub sysbus: Box<SysBus>, pub sysbus: Box<SysBus>,
pub cpu: Core, pub cpu: Core,
video_device: Rc<RefCell<V>>, video_device: Rc<RefCell<dyn VideoInterface>>,
audio_device: Rc<RefCell<A>>, audio_device: Rc<RefCell<dyn AudioInterface>>,
input_device: Rc<RefCell<I>>, input_device: Rc<RefCell<dyn InputInterface>>,
} }
impl<V, A, I> GameBoyAdvance<V, A, I> impl GameBoyAdvance {
where
V: VideoInterface,
A: AudioInterface,
I: InputInterface,
{
pub fn new( pub fn new(
cpu: Core, cpu: Core,
bios_rom: Vec<u8>, bios_rom: Vec<u8>,
gamepak: Cartridge, gamepak: Cartridge,
video_device: Rc<RefCell<V>>, video_device: Rc<RefCell<dyn VideoInterface>>,
audio_device: Rc<RefCell<A>>, audio_device: Rc<RefCell<dyn AudioInterface>>,
input_device: Rc<RefCell<I>>, input_device: Rc<RefCell<dyn InputInterface>>,
) -> GameBoyAdvance<V, A, I> { ) -> GameBoyAdvance {
let io = IoDevices::new(); let io = IoDevices::new();
GameBoyAdvance { GameBoyAdvance {
cpu: cpu, cpu: cpu,

View file

@ -63,12 +63,7 @@ pub enum Command {
TraceToggle(TraceFlags), TraceToggle(TraceFlags),
} }
impl<V, A, I> Debugger<V, A, I> impl Debugger {
where
V: VideoInterface,
A: AudioInterface,
I: InputInterface,
{
pub fn run_command(&mut self, command: Command) { pub fn run_command(&mut self, command: Command) {
use Command::*; use Command::*;
match command { match command {

View file

@ -48,25 +48,15 @@ impl From<::std::io::Error> for DebuggerError {
type DebuggerResult<T> = Result<T, DebuggerError>; type DebuggerResult<T> = Result<T, DebuggerError>;
pub struct Debugger<V, A, I> pub struct Debugger {
where pub gba: GameBoyAdvance,
V: VideoInterface,
A: AudioInterface,
I: InputInterface,
{
pub gba: GameBoyAdvance<V, A, I>,
running: bool, running: bool,
pub ctrlc_flag: Arc<AtomicBool>, pub ctrlc_flag: Arc<AtomicBool>,
pub previous_command: Option<Command>, pub previous_command: Option<Command>,
} }
impl<V, A, I> Debugger<V, A, I> impl Debugger {
where pub fn new(gba: GameBoyAdvance) -> Debugger {
V: VideoInterface,
A: AudioInterface,
I: InputInterface,
{
pub fn new(gba: GameBoyAdvance<V, A, I>) -> Debugger<V, A, I> {
let ctrlc_flag = Arc::new(AtomicBool::new(true)); let ctrlc_flag = Arc::new(AtomicBool::new(true));
let r = ctrlc_flag.clone(); let r = ctrlc_flag.clone();
ctrlc::set_handler(move || { ctrlc::set_handler(move || {

View file

@ -117,7 +117,7 @@ fn main() {
})); }));
let mut fps_counter = FpsCounter::default(); let mut fps_counter = FpsCounter::default();
let mut gba: GameBoyAdvance<MiniFb, MiniFb, MiniFb> = GameBoyAdvance::new( let mut gba = GameBoyAdvance::new(
cpu, cpu,
bios_bin, bios_bin,
cart, cart,

View file

@ -51,7 +51,7 @@ fn main() {
let input = Rc::new(RefCell::new(create_input())); let input = Rc::new(RefCell::new(create_input()));
let mut fps_counter = FpsCounter::default(); let mut fps_counter = FpsCounter::default();
let mut gba: GameBoyAdvance<Sdl2Video, Sdl2AudioPlayer, Sdl2Input> = GameBoyAdvance::new( let mut gba = GameBoyAdvance::new(
cpu, cpu,
bios_bin, bios_bin,
cart, cart,