diff --git a/ferretro_components/examples/multifunction_emulator.rs b/ferretro_components/examples/multifunction_emulator.rs index 99c8a96..abd9049 100644 --- a/ferretro_components/examples/multifunction_emulator.rs +++ b/ferretro_components/examples/multifunction_emulator.rs @@ -57,12 +57,11 @@ pub fn main() -> Result<(), Box> { let sdl2_ogl = SimpleSdl2OpenglComponent::new(&mut sdl_context, emu.libretro_core())?; emu.register_component(sdl2_ogl)?; - let sdl2_audio = SimpleSdl2AudioComponent::new(&mut sdl_context, emu.libretro_core())?; - emu.register_component(sdl2_audio)?; + emu.register_component(SimpleSdl2AudioComponent::new(&mut sdl_context)?)?; emu.register_component(SimpleSdl2GamepadComponent::new(&mut sdl_context))?; - emu.register_component(SleepFramerateLimitComponent::new())?; + emu.register_component(SleepFramerateLimitComponent::default())?; emu.register_component(PathBufComponent { sys_path: opt.system.clone(), diff --git a/ferretro_components/src/provided/sdl2/audio.rs b/ferretro_components/src/provided/sdl2/audio.rs index afd0396..6495b24 100644 --- a/ferretro_components/src/provided/sdl2/audio.rs +++ b/ferretro_components/src/provided/sdl2/audio.rs @@ -75,7 +75,7 @@ impl RetroComponent for SimpleSdl2AudioComponent { } impl SimpleSdl2AudioComponent { - pub fn new(sdl_context: &mut Sdl, _retro: &LibretroWrapper) -> Result> { + pub fn new(sdl_context: &mut Sdl) -> Result> { let audio = sdl_context.audio().unwrap(); let desired_spec = AudioSpecDesired { freq: None, diff --git a/ferretro_components/src/provided/sdl2/canvas.rs b/ferretro_components/src/provided/sdl2/canvas.rs index 5e6c803..0ea222b 100644 --- a/ferretro_components/src/provided/sdl2/canvas.rs +++ b/ferretro_components/src/provided/sdl2/canvas.rs @@ -1,6 +1,7 @@ use crate::prelude::*; use std::ffi::CStr; +use std::path::Path; use sdl2::Sdl; use sdl2::rect::Rect; @@ -23,12 +24,11 @@ impl SimpleSdl2CanvasComponent { unsafe { CStr::from_ptr(sys_info.library_name) }.to_string_lossy() ); - let geometry = retro.get_system_av_info().geometry; let pixel_format = sdl2::pixels::PixelFormatEnum::ARGB1555; let window = sdl_context .video()? - .window(title.as_str(), geometry.base_width, geometry.base_height) + .window(title.as_str(), 256, 224) .build()?; let canvas = window.into_canvas().build()?; @@ -40,7 +40,13 @@ impl SimpleSdl2CanvasComponent { } } -impl RetroComponent for SimpleSdl2CanvasComponent {} +impl RetroComponent for SimpleSdl2CanvasComponent { + fn post_load_game(&mut self, retro: &mut LibretroWrapper, _rom: &Path) -> crate::base::Result<()> { + self.set_geometry(&retro.get_system_av_info().geometry); + Ok(()) + } +} + impl RetroCallbacks for SimpleSdl2CanvasComponent { fn video_refresh(&mut self, frame: &VideoFrame) { match frame { diff --git a/ferretro_components/src/provided/sdl2/opengl.rs b/ferretro_components/src/provided/sdl2/opengl.rs index 8162456..04113c8 100644 --- a/ferretro_components/src/provided/sdl2/opengl.rs +++ b/ferretro_components/src/provided/sdl2/opengl.rs @@ -2,11 +2,11 @@ use crate::prelude::*; use std::ffi::CStr; use std::os::raw::c_uint; +use std::path::Path; use sdl2::Sdl; use sdl2::rect::Rect; use sdl2::render::WindowCanvas; -use std::path::Path; /// Create a root window in SDL2 with an OpenGL context and attaches libretro's /// `hw_get_proc_address` calls to that of the [sdl2::VideoSubsystem]. diff --git a/ferretro_components/src/provided/sdl2/surface.rs b/ferretro_components/src/provided/sdl2/surface.rs index e80174d..0cab588 100644 --- a/ferretro_components/src/provided/sdl2/surface.rs +++ b/ferretro_components/src/provided/sdl2/surface.rs @@ -9,15 +9,11 @@ pub struct Sdl2SurfaceComponent { } impl Sdl2SurfaceComponent { - pub fn new(retro: &LibretroWrapper) -> Result> { - let geometry = retro.get_system_av_info().geometry; + pub fn new() -> Result> { let pixel_format = sdl2::pixels::PixelFormatEnum::ARGB1555; - let surface = Surface::new( - geometry.base_width, - geometry.base_height, - pixel_format, - )?; + // automatically replaced in video_refresh whenever size doesn't match + let surface = Surface::new(1, 1, pixel_format)?; Ok(Sdl2SurfaceComponent { surface, diff --git a/ferretro_components/src/provided/stdlib/fps.rs b/ferretro_components/src/provided/stdlib/fps.rs index a47c1a1..c34086c 100644 --- a/ferretro_components/src/provided/stdlib/fps.rs +++ b/ferretro_components/src/provided/stdlib/fps.rs @@ -42,8 +42,8 @@ impl RetroCallbacks for SleepFramerateLimitComponent { } } -impl SleepFramerateLimitComponent { - pub fn new() -> Self { +impl Default for SleepFramerateLimitComponent { + fn default() -> Self { SleepFramerateLimitComponent { did_sleep: false, started_video: false, @@ -51,7 +51,9 @@ impl SleepFramerateLimitComponent { frame_begin: Instant::now(), } } +} +impl SleepFramerateLimitComponent { pub fn do_sleep(&mut self) { // similar hack to the sample rate, make sure we don't divide by zero. let mut spf = 1.0 / self.fps;