From 10d0934f82fa4a270d24a5a583588130af0b4fd9 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Mon, 23 Dec 2019 01:27:25 +0200 Subject: [PATCH] GameBoyAdvance: Use dyn traits instead of generic types "Performance hit" is not significient Former-commit-id: 809dea4cdbf9579d8e9d18de95b3c9a05723c68f --- src/core/gba.rs | 28 +++++++++------------------- src/debugger/command.rs | 7 +------ src/debugger/mod.rs | 18 ++++-------------- src/plat/minifb/main.rs | 2 +- src/plat/sdl2/main.rs | 2 +- 5 files changed, 16 insertions(+), 41 deletions(-) diff --git a/src/core/gba.rs b/src/core/gba.rs index 1f69126..8cc68b5 100644 --- a/src/core/gba.rs +++ b/src/core/gba.rs @@ -11,33 +11,23 @@ use super::sysbus::SysBus; use super::super::{AudioInterface, InputInterface, VideoInterface}; -pub struct GameBoyAdvance -where - V: VideoInterface, - A: AudioInterface, - I: InputInterface, -{ +pub struct GameBoyAdvance { pub sysbus: Box, pub cpu: Core, - video_device: Rc>, - audio_device: Rc>, - input_device: Rc>, + video_device: Rc>, + audio_device: Rc>, + input_device: Rc>, } -impl GameBoyAdvance -where - V: VideoInterface, - A: AudioInterface, - I: InputInterface, -{ +impl GameBoyAdvance { pub fn new( cpu: Core, bios_rom: Vec, gamepak: Cartridge, - video_device: Rc>, - audio_device: Rc>, - input_device: Rc>, - ) -> GameBoyAdvance { + video_device: Rc>, + audio_device: Rc>, + input_device: Rc>, + ) -> GameBoyAdvance { let io = IoDevices::new(); GameBoyAdvance { cpu: cpu, diff --git a/src/debugger/command.rs b/src/debugger/command.rs index a0aab9e..ab6836f 100644 --- a/src/debugger/command.rs +++ b/src/debugger/command.rs @@ -63,12 +63,7 @@ pub enum Command { TraceToggle(TraceFlags), } -impl Debugger -where - V: VideoInterface, - A: AudioInterface, - I: InputInterface, -{ +impl Debugger { pub fn run_command(&mut self, command: Command) { use Command::*; match command { diff --git a/src/debugger/mod.rs b/src/debugger/mod.rs index 79f144f..f382196 100644 --- a/src/debugger/mod.rs +++ b/src/debugger/mod.rs @@ -48,25 +48,15 @@ impl From<::std::io::Error> for DebuggerError { type DebuggerResult = Result; -pub struct Debugger -where - V: VideoInterface, - A: AudioInterface, - I: InputInterface, -{ - pub gba: GameBoyAdvance, +pub struct Debugger { + pub gba: GameBoyAdvance, running: bool, pub ctrlc_flag: Arc, pub previous_command: Option, } -impl Debugger -where - V: VideoInterface, - A: AudioInterface, - I: InputInterface, -{ - pub fn new(gba: GameBoyAdvance) -> Debugger { +impl Debugger { + pub fn new(gba: GameBoyAdvance) -> Debugger { let ctrlc_flag = Arc::new(AtomicBool::new(true)); let r = ctrlc_flag.clone(); ctrlc::set_handler(move || { diff --git a/src/plat/minifb/main.rs b/src/plat/minifb/main.rs index b2ad942..e84a4ca 100644 --- a/src/plat/minifb/main.rs +++ b/src/plat/minifb/main.rs @@ -117,7 +117,7 @@ fn main() { })); let mut fps_counter = FpsCounter::default(); - let mut gba: GameBoyAdvance = GameBoyAdvance::new( + let mut gba = GameBoyAdvance::new( cpu, bios_bin, cart, diff --git a/src/plat/sdl2/main.rs b/src/plat/sdl2/main.rs index 547ffa3..c78285c 100644 --- a/src/plat/sdl2/main.rs +++ b/src/plat/sdl2/main.rs @@ -51,7 +51,7 @@ fn main() { let input = Rc::new(RefCell::new(create_input())); let mut fps_counter = FpsCounter::default(); - let mut gba: GameBoyAdvance = GameBoyAdvance::new( + let mut gba = GameBoyAdvance::new( cpu, bios_bin, cart,