Remove dead code
Former-commit-id: 5d5768ca6b73060197d9bacda61cba4c03804ad0
This commit is contained in:
parent
c2ac3c5a10
commit
c9e80f4f60
|
@ -23,7 +23,6 @@ bitfield = "0.13.1"
|
||||||
bitflags = "1.1.0"
|
bitflags = "1.1.0"
|
||||||
zip = "0.5.3"
|
zip = "0.5.3"
|
||||||
ctrlc = "3.1.3"
|
ctrlc = "3.1.3"
|
||||||
cpal="0.10.0"
|
|
||||||
spin_sleep="0.3.7"
|
spin_sleep="0.3.7"
|
||||||
bit-set = "0.5.1"
|
bit-set = "0.5.1"
|
||||||
|
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
extern crate cpal;
|
|
||||||
|
|
||||||
use cpal::traits::{DeviceTrait, EventLoopTrait, HostTrait};
|
|
||||||
use cpal::EventLoop;
|
|
||||||
|
|
||||||
pub struct CpalSoundBackend {
|
|
||||||
event_loop: EventLoop,
|
|
||||||
sample_rate: usize,
|
|
||||||
channels: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CpalSoundBackend {
|
|
||||||
pub fn new() -> CpalSoundBackend {
|
|
||||||
let host = cpal::default_host();
|
|
||||||
let device = host.default_output_device().expect("failed to find a default output device");
|
|
||||||
let format = device.default_output_format()?;
|
|
||||||
let event_loop = host.event_loop();
|
|
||||||
let stream_id = event_loop.build_output_stream(&device, &format)?;
|
|
||||||
|
|
||||||
event_loop.play_stream(stream_id.clone())?;
|
|
||||||
|
|
||||||
CpalSoundBackend {
|
|
||||||
event_loop: event_loop,
|
|
||||||
sample_rate: format.sample_rate.0,
|
|
||||||
channels: format.channels,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn start(&self) {
|
|
||||||
thread::spawn(move || {
|
|
||||||
self.event_loop.run(move |id, result| {
|
|
||||||
let data = match result {
|
|
||||||
Ok(data) => data,
|
|
||||||
Err(err) => {
|
|
||||||
println!("an error occurred on stream {:?}: {}", id, err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match data {
|
|
||||||
cpal::StreamData::Output { buffer: cpal::UnknownTypeOutputBuffer::F32(mut buffer) } => {
|
|
||||||
for sample in buffer.chunks_mut(format.channels as usize) {
|
|
||||||
// TODO get samples from SoundController
|
|
||||||
sample[0] = 0.0;
|
|
||||||
sample[1] = 0.0;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
panic!("expected F32");
|
|
||||||
},
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,94 +0,0 @@
|
||||||
use std::time;
|
|
||||||
|
|
||||||
use crate::bit::BitIndex;
|
|
||||||
|
|
||||||
extern crate minifb;
|
|
||||||
|
|
||||||
use minifb::{Key, Window, WindowOptions};
|
|
||||||
|
|
||||||
use super::EmulatorBackend;
|
|
||||||
use crate::core::gpu::{DISPLAY_HEIGHT, DISPLAY_WIDTH};
|
|
||||||
use crate::core::keypad;
|
|
||||||
|
|
||||||
pub struct MinifbBackend {
|
|
||||||
window: Window,
|
|
||||||
frames_rendered: u32,
|
|
||||||
first_frame_start: time::Instant,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MinifbBackend {
|
|
||||||
pub fn new() -> MinifbBackend {
|
|
||||||
let window = Window::new(
|
|
||||||
"rustboyadvance-ng",
|
|
||||||
DISPLAY_WIDTH,
|
|
||||||
DISPLAY_HEIGHT,
|
|
||||||
WindowOptions {
|
|
||||||
borderless: true,
|
|
||||||
scale: minifb::Scale::X4,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
MinifbBackend {
|
|
||||||
window: window,
|
|
||||||
frames_rendered: 0,
|
|
||||||
first_frame_start: time::Instant::now(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EmulatorBackend for MinifbBackend {
|
|
||||||
fn render(&mut self, buffer: &[u32]) {
|
|
||||||
self.frames_rendered += 1;
|
|
||||||
if self.first_frame_start.elapsed() >= time::Duration::from_secs(1) {
|
|
||||||
let title = format!("rustboyadvance-ng ({} fps)", self.frames_rendered);
|
|
||||||
self.window.set_title(&title);
|
|
||||||
self.first_frame_start = time::Instant::now();
|
|
||||||
self.frames_rendered = 0;
|
|
||||||
}
|
|
||||||
self.window.update_with_buffer(buffer).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_key_state(&mut self) -> u16 {
|
|
||||||
let mut keyinput = keypad::KEYINPUT_ALL_RELEASED;
|
|
||||||
keyinput.set_bit(keypad::Keys::Up as usize, !self.window.is_key_down(Key::Up));
|
|
||||||
keyinput.set_bit(
|
|
||||||
keypad::Keys::Down as usize,
|
|
||||||
!self.window.is_key_down(Key::Down),
|
|
||||||
);
|
|
||||||
keyinput.set_bit(
|
|
||||||
keypad::Keys::Left as usize,
|
|
||||||
!self.window.is_key_down(Key::Left),
|
|
||||||
);
|
|
||||||
keyinput.set_bit(
|
|
||||||
keypad::Keys::Right as usize,
|
|
||||||
!self.window.is_key_down(Key::Right),
|
|
||||||
);
|
|
||||||
keyinput.set_bit(
|
|
||||||
keypad::Keys::ButtonB as usize,
|
|
||||||
!self.window.is_key_down(Key::Z),
|
|
||||||
);
|
|
||||||
keyinput.set_bit(
|
|
||||||
keypad::Keys::ButtonA as usize,
|
|
||||||
!self.window.is_key_down(Key::X),
|
|
||||||
);
|
|
||||||
keyinput.set_bit(
|
|
||||||
keypad::Keys::Start as usize,
|
|
||||||
!self.window.is_key_down(Key::Enter),
|
|
||||||
);
|
|
||||||
keyinput.set_bit(
|
|
||||||
keypad::Keys::Select as usize,
|
|
||||||
!self.window.is_key_down(Key::Space),
|
|
||||||
);
|
|
||||||
keyinput.set_bit(
|
|
||||||
keypad::Keys::ButtonL as usize,
|
|
||||||
!self.window.is_key_down(Key::A),
|
|
||||||
);
|
|
||||||
keyinput.set_bit(
|
|
||||||
keypad::Keys::ButtonR as usize,
|
|
||||||
!self.window.is_key_down(Key::S),
|
|
||||||
);
|
|
||||||
keyinput
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
use super::core::keypad;
|
|
||||||
|
|
||||||
mod minifb_backend;
|
|
||||||
pub use minifb_backend::MinifbBackend;
|
|
||||||
|
|
||||||
mod sdl2_backend;
|
|
||||||
pub use sdl2_backend::Sdl2Backend;
|
|
||||||
|
|
||||||
pub trait EmulatorBackend {
|
|
||||||
fn render(&mut self, buffer: &[u32]);
|
|
||||||
|
|
||||||
fn get_key_state(&mut self) -> u16;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DummyBackend;
|
|
||||||
|
|
||||||
impl DummyBackend {
|
|
||||||
pub fn new() -> DummyBackend {
|
|
||||||
DummyBackend {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EmulatorBackend for DummyBackend {
|
|
||||||
fn get_key_state(&mut self) -> u16 {
|
|
||||||
keypad::KEYINPUT_ALL_RELEASED
|
|
||||||
}
|
|
||||||
fn render(&mut self, _buffer: &[u32]) {}
|
|
||||||
}
|
|
|
@ -1,136 +0,0 @@
|
||||||
use std::time;
|
|
||||||
|
|
||||||
use crate::bit::BitIndex;
|
|
||||||
|
|
||||||
extern crate sdl2;
|
|
||||||
use sdl2::event::Event;
|
|
||||||
use sdl2::keyboard::Keycode;
|
|
||||||
use sdl2::pixels::{Color, PixelFormatEnum};
|
|
||||||
use sdl2::rect::{Point, Rect};
|
|
||||||
use sdl2::render::{TextureCreator, WindowCanvas};
|
|
||||||
use sdl2::video::WindowContext;
|
|
||||||
|
|
||||||
use super::EmulatorBackend;
|
|
||||||
use crate::core::gpu::{DISPLAY_HEIGHT, DISPLAY_WIDTH};
|
|
||||||
use crate::core::keypad;
|
|
||||||
|
|
||||||
pub struct Sdl2Backend {
|
|
||||||
event_pump: sdl2::EventPump,
|
|
||||||
tc: TextureCreator<WindowContext>,
|
|
||||||
canvas: WindowCanvas,
|
|
||||||
frames_rendered: u32,
|
|
||||||
fps_timer: time::Instant,
|
|
||||||
keyinput: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
const SCREEN_WIDTH: u32 = DISPLAY_WIDTH as u32;
|
|
||||||
const SCREEN_HEIGHT: u32 = DISPLAY_HEIGHT as u32;
|
|
||||||
|
|
||||||
impl Sdl2Backend {
|
|
||||||
pub fn new() -> Sdl2Backend {
|
|
||||||
let sdl_context = sdl2::init().unwrap();
|
|
||||||
let video_subsystem = sdl_context.video().unwrap();
|
|
||||||
|
|
||||||
let window = video_subsystem
|
|
||||||
.window("RustBoyAdvance", SCREEN_WIDTH, SCREEN_HEIGHT)
|
|
||||||
.opengl()
|
|
||||||
.position_centered()
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut canvas = window.into_canvas().accelerated().build().unwrap();
|
|
||||||
canvas.set_draw_color(Color::RGB(0, 0, 0));
|
|
||||||
canvas.clear();
|
|
||||||
let tc = canvas.texture_creator();
|
|
||||||
let event_pump = sdl_context.event_pump().unwrap();
|
|
||||||
|
|
||||||
Sdl2Backend {
|
|
||||||
canvas: canvas,
|
|
||||||
event_pump: event_pump,
|
|
||||||
tc: tc,
|
|
||||||
frames_rendered: 0,
|
|
||||||
fps_timer: time::Instant::now(),
|
|
||||||
keyinput: keypad::KEYINPUT_ALL_RELEASED,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EmulatorBackend for Sdl2Backend {
|
|
||||||
fn render(&mut self, buffer: &[u32]) {
|
|
||||||
let mut texture = self
|
|
||||||
.tc
|
|
||||||
.create_texture_target(PixelFormatEnum::RGB24, SCREEN_WIDTH, SCREEN_HEIGHT)
|
|
||||||
.unwrap();
|
|
||||||
self.canvas
|
|
||||||
.with_texture_canvas(&mut texture, |texture_canvas| {
|
|
||||||
for y in 0i32..(SCREEN_HEIGHT as i32) {
|
|
||||||
for x in 0i32..(SCREEN_WIDTH as i32) {
|
|
||||||
let c = buffer[index2d!(x, y, SCREEN_WIDTH as i32) as usize];
|
|
||||||
let color = Color::RGB((c >> 16) as u8, (c >> 8) as u8, c as u8);
|
|
||||||
texture_canvas.set_draw_color(color);
|
|
||||||
let _ = texture_canvas.draw_point(Point::from((x, y)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
self.canvas
|
|
||||||
.copy(
|
|
||||||
&texture,
|
|
||||||
None,
|
|
||||||
Some(Rect::new(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
self.canvas.present();
|
|
||||||
|
|
||||||
self.frames_rendered += 1;
|
|
||||||
if self.fps_timer.elapsed() >= time::Duration::from_secs(1) {
|
|
||||||
self.fps_timer = time::Instant::now();
|
|
||||||
let title = format!("rustboyadvance-ng ({} fps)", self.frames_rendered);
|
|
||||||
self.canvas.window_mut().set_title(&title);
|
|
||||||
self.frames_rendered = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_key_state(&mut self) -> u16 {
|
|
||||||
for event in self.event_pump.poll_iter() {
|
|
||||||
match event {
|
|
||||||
Event::KeyDown {
|
|
||||||
keycode: Some(keycode),
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
if let Some(key) = keycode_to_keypad(keycode) {
|
|
||||||
self.keyinput.set_bit(key as usize, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::KeyUp {
|
|
||||||
keycode: Some(keycode),
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
if let Some(key) = keycode_to_keypad(keycode) {
|
|
||||||
self.keyinput.set_bit(key as usize, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::Quit { .. } => panic!("quit!"),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.keyinput
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn keycode_to_keypad(keycode: Keycode) -> Option<keypad::Keys> {
|
|
||||||
match keycode {
|
|
||||||
Keycode::Up => Some(keypad::Keys::Up),
|
|
||||||
Keycode::Down => Some(keypad::Keys::Down),
|
|
||||||
Keycode::Left => Some(keypad::Keys::Left),
|
|
||||||
Keycode::Right => Some(keypad::Keys::Right),
|
|
||||||
Keycode::Z => Some(keypad::Keys::ButtonB),
|
|
||||||
Keycode::X => Some(keypad::Keys::ButtonA),
|
|
||||||
Keycode::Return => Some(keypad::Keys::Start),
|
|
||||||
Keycode::Space => Some(keypad::Keys::Select),
|
|
||||||
Keycode::A => Some(keypad::Keys::ButtonL),
|
|
||||||
Keycode::S => Some(keypad::Keys::ButtonR),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
Reference in a new issue