more fixes for invalid calls to get_system_av_info

This commit is contained in:
lifning 2021-11-03 18:31:40 -07:00
parent 344d88f26b
commit 41e3352927
6 changed files with 20 additions and 17 deletions

View File

@ -57,12 +57,11 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let sdl2_ogl = SimpleSdl2OpenglComponent::new(&mut sdl_context, emu.libretro_core())?; let sdl2_ogl = SimpleSdl2OpenglComponent::new(&mut sdl_context, emu.libretro_core())?;
emu.register_component(sdl2_ogl)?; emu.register_component(sdl2_ogl)?;
let sdl2_audio = SimpleSdl2AudioComponent::new(&mut sdl_context, emu.libretro_core())?; emu.register_component(SimpleSdl2AudioComponent::new(&mut sdl_context)?)?;
emu.register_component(sdl2_audio)?;
emu.register_component(SimpleSdl2GamepadComponent::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 { emu.register_component(PathBufComponent {
sys_path: opt.system.clone(), sys_path: opt.system.clone(),

View File

@ -75,7 +75,7 @@ impl RetroComponent for SimpleSdl2AudioComponent {
} }
impl SimpleSdl2AudioComponent { impl SimpleSdl2AudioComponent {
pub fn new(sdl_context: &mut Sdl, _retro: &LibretroWrapper) -> Result<Self, Box<dyn std::error::Error>> { pub fn new(sdl_context: &mut Sdl) -> Result<Self, Box<dyn std::error::Error>> {
let audio = sdl_context.audio().unwrap(); let audio = sdl_context.audio().unwrap();
let desired_spec = AudioSpecDesired { let desired_spec = AudioSpecDesired {
freq: None, freq: None,

View File

@ -1,6 +1,7 @@
use crate::prelude::*; use crate::prelude::*;
use std::ffi::CStr; use std::ffi::CStr;
use std::path::Path;
use sdl2::Sdl; use sdl2::Sdl;
use sdl2::rect::Rect; use sdl2::rect::Rect;
@ -23,12 +24,11 @@ impl SimpleSdl2CanvasComponent {
unsafe { CStr::from_ptr(sys_info.library_name) }.to_string_lossy() 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 pixel_format = sdl2::pixels::PixelFormatEnum::ARGB1555;
let window = sdl_context let window = sdl_context
.video()? .video()?
.window(title.as_str(), geometry.base_width, geometry.base_height) .window(title.as_str(), 256, 224)
.build()?; .build()?;
let canvas = window.into_canvas().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 { impl RetroCallbacks for SimpleSdl2CanvasComponent {
fn video_refresh(&mut self, frame: &VideoFrame) { fn video_refresh(&mut self, frame: &VideoFrame) {
match frame { match frame {

View File

@ -2,11 +2,11 @@ use crate::prelude::*;
use std::ffi::CStr; use std::ffi::CStr;
use std::os::raw::c_uint; use std::os::raw::c_uint;
use std::path::Path;
use sdl2::Sdl; use sdl2::Sdl;
use sdl2::rect::Rect; use sdl2::rect::Rect;
use sdl2::render::WindowCanvas; use sdl2::render::WindowCanvas;
use std::path::Path;
/// Create a root window in SDL2 with an OpenGL context and attaches libretro's /// 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]. /// `hw_get_proc_address` calls to that of the [sdl2::VideoSubsystem].

View File

@ -9,15 +9,11 @@ pub struct Sdl2SurfaceComponent {
} }
impl Sdl2SurfaceComponent { impl Sdl2SurfaceComponent {
pub fn new(retro: &LibretroWrapper) -> Result<Self, Box<dyn std::error::Error>> { pub fn new() -> Result<Self, Box<dyn std::error::Error>> {
let geometry = retro.get_system_av_info().geometry;
let pixel_format = sdl2::pixels::PixelFormatEnum::ARGB1555; let pixel_format = sdl2::pixels::PixelFormatEnum::ARGB1555;
let surface = Surface::new( // automatically replaced in video_refresh whenever size doesn't match
geometry.base_width, let surface = Surface::new(1, 1, pixel_format)?;
geometry.base_height,
pixel_format,
)?;
Ok(Sdl2SurfaceComponent { Ok(Sdl2SurfaceComponent {
surface, surface,

View File

@ -42,8 +42,8 @@ impl RetroCallbacks for SleepFramerateLimitComponent {
} }
} }
impl SleepFramerateLimitComponent { impl Default for SleepFramerateLimitComponent {
pub fn new() -> Self { fn default() -> Self {
SleepFramerateLimitComponent { SleepFramerateLimitComponent {
did_sleep: false, did_sleep: false,
started_video: false, started_video: false,
@ -51,7 +51,9 @@ impl SleepFramerateLimitComponent {
frame_begin: Instant::now(), frame_begin: Instant::now(),
} }
} }
}
impl SleepFramerateLimitComponent {
pub fn do_sleep(&mut self) { pub fn do_sleep(&mut self) {
// similar hack to the sample rate, make sure we don't divide by zero. // similar hack to the sample rate, make sure we don't divide by zero.
let mut spf = 1.0 / self.fps; let mut spf = 1.0 / self.fps;