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};
pub struct GameBoyAdvance<V, A, I>
where
V: VideoInterface,
A: AudioInterface,
I: InputInterface,
{
pub struct GameBoyAdvance {
pub sysbus: Box<SysBus>,
pub cpu: Core,
video_device: Rc<RefCell<V>>,
audio_device: Rc<RefCell<A>>,
input_device: Rc<RefCell<I>>,
video_device: Rc<RefCell<dyn VideoInterface>>,
audio_device: Rc<RefCell<dyn AudioInterface>>,
input_device: Rc<RefCell<dyn InputInterface>>,
}
impl<V, A, I> GameBoyAdvance<V, A, I>
where
V: VideoInterface,
A: AudioInterface,
I: InputInterface,
{
impl GameBoyAdvance {
pub fn new(
cpu: Core,
bios_rom: Vec<u8>,
gamepak: Cartridge,
video_device: Rc<RefCell<V>>,
audio_device: Rc<RefCell<A>>,
input_device: Rc<RefCell<I>>,
) -> GameBoyAdvance<V, A, I> {
video_device: Rc<RefCell<dyn VideoInterface>>,
audio_device: Rc<RefCell<dyn AudioInterface>>,
input_device: Rc<RefCell<dyn InputInterface>>,
) -> GameBoyAdvance {
let io = IoDevices::new();
GameBoyAdvance {
cpu: cpu,

View file

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

View file

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

View file

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

View file

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