diff --git a/ferretro_base/src/dynamic_borrow.rs b/ferretro_base/src/dynamic_borrow.rs deleted file mode 100644 index 0b0a97a..0000000 --- a/ferretro_base/src/dynamic_borrow.rs +++ /dev/null @@ -1,103 +0,0 @@ -use std::cell::RefCell; -use std::os::raw::c_uint; -use std::rc::Rc; -use std::path::PathBuf; - -use crate::prelude::*; -use crate::retro::ffi::*; - -impl RetroCallbacks for Rc> { - fn video_refresh(&mut self, frame: &VideoFrame) { - RefCell::borrow_mut(self).video_refresh(frame) - } - fn audio_samples(&mut self, stereo_pcm: &[i16]) -> usize { - RefCell::borrow_mut(self).audio_samples(stereo_pcm) - } - fn input_poll(&mut self) { - RefCell::borrow_mut(self).input_poll() - } - fn input_state(&mut self, port: u32, device: InputDeviceId, index: InputIndex) -> i16 { - RefCell::borrow_mut(self).input_state(port, device, index) - } - fn set_rotation(&mut self, rotation: EnvRotation) -> Option { - RefCell::borrow_mut(self).set_rotation(rotation) - } - fn get_overscan(&mut self) -> Option { - RefCell::borrow_mut(self).get_overscan() - } - fn set_message(&mut self, message: &Message) -> Option { - RefCell::borrow_mut(self).set_message(message) - } - fn shutdown(&mut self) -> Option { - RefCell::borrow_mut(self).shutdown() - } - fn set_performance_level(&mut self, level: c_uint) -> Option { - RefCell::borrow_mut(self).set_performance_level(level) - } - fn get_system_directory(&mut self) -> Option { - RefCell::borrow_mut(self).get_system_directory() - } - fn set_pixel_format(&mut self, format: PixelFormat) -> Option { - RefCell::borrow_mut(self).set_pixel_format(format) - } - fn set_input_descriptors(&mut self, input_descriptors: &Vec) -> Option { - RefCell::borrow_mut(self).set_input_descriptors(input_descriptors) - } - fn set_hw_render(&mut self, hw_render_callback: &HwRenderCallback) -> Option { - RefCell::borrow_mut(self).set_hw_render(hw_render_callback) - } - fn get_variable(&mut self, key: &str) -> Option { - RefCell::borrow_mut(self).get_variable(key) - } - fn set_variables(&mut self, variables: &Vec) -> Option { - RefCell::borrow_mut(self).set_variables(variables) - } - fn get_variable_update(&mut self) -> Option { - RefCell::borrow_mut(self).get_variable_update() - } - fn set_support_no_game(&mut self, supports_no_game: bool) -> Option { - RefCell::borrow_mut(self).set_support_no_game(supports_no_game) - } - fn get_libretro_path(&mut self) -> Option { - RefCell::borrow_mut(self).get_libretro_path() - } - fn get_input_device_capabilities(&mut self) -> Option { - RefCell::borrow_mut(self).get_input_device_capabilities() - } - fn get_core_assets_directory(&mut self) -> Option { - RefCell::borrow_mut(self).get_core_assets_directory() - } - fn get_save_directory(&mut self) -> Option { - RefCell::borrow_mut(self).get_save_directory() - } - fn set_system_av_info(&mut self, system_av_info: &SystemAvInfo) -> Option { - RefCell::borrow_mut(self).set_system_av_info(system_av_info) - } - fn set_subsystem_info(&mut self, subsystem_info: &Vec) -> Option { - RefCell::borrow_mut(self).set_subsystem_info(subsystem_info) - } - fn set_controller_info(&mut self, controller_info: &Vec) -> Option { - RefCell::borrow_mut(self).set_controller_info(controller_info) - } - fn set_memory_maps(&mut self, memory_map: &MemoryMap) -> Option { - RefCell::borrow_mut(self).set_memory_maps(memory_map) - } - fn set_geometry(&mut self, game_geometry: &GameGeometry) -> Option { - RefCell::borrow_mut(self).set_geometry(game_geometry) - } - fn get_username(&mut self) -> Option { - RefCell::borrow_mut(self).get_username() - } - fn get_language(&mut self) -> Option { - RefCell::borrow_mut(self).get_language() - } - fn hw_get_current_framebuffer(&mut self) -> Option { - RefCell::borrow_mut(self).hw_get_current_framebuffer() - } - fn hw_get_proc_address(&mut self, sym: &str) -> Option<*const ()> { - RefCell::borrow_mut(self).hw_get_proc_address(sym) - } - // TODO: the rest, dynamically. - // can we proc macro it? - // 's~^\( *\)fn \(.*\)(&mut self\(, \)\?\([^)]*\))\(.*\){$~\1fn \2(\&mut self\3\4)\5{\n\1 RefCell::borrow_mut(self).\2(\4)~' -} diff --git a/ferretro_base/src/lib.rs b/ferretro_base/src/lib.rs index 1307a5e..c280b88 100644 --- a/ferretro_base/src/lib.rs +++ b/ferretro_base/src/lib.rs @@ -8,5 +8,3 @@ pub mod prelude { pub use crate::retro::wrapper::{RetroCallbacks, LibretroWrapper, LibretroWrapperAccess}; pub use crate::retro::ffi::{PixelFormat, GameGeometry, HwContextResetFn, HwRenderCallback, SystemAvInfo, SystemInfo}; } - -mod dynamic_borrow; diff --git a/ferretro_components/src/base/mod.rs b/ferretro_components/src/base/mod.rs index f19a283..d951c1e 100644 --- a/ferretro_components/src/base/mod.rs +++ b/ferretro_components/src/base/mod.rs @@ -1,3 +1,7 @@ +//! Implementation of the [component system](RetroComponentBase) +//! and declaration of the [component trait](RetroComponent) +//! for composable subsets of [RetroCallbacks] implementations. + use crate::prelude::*; use ferretro_base::retro::ffi::*; use std::any::{Any, TypeId}; @@ -255,6 +259,9 @@ impl RetroCallbacks for RetroComponentBase { .unwrap_or_default() } + // TODO: for this, set_pixel_format, and other mutation-themed calls returning Option, + // if any include both Some(false) and Some(true), then re-run with the previous value + // assumed to be supported by all components (to signal to true-returners to revert). fn set_rotation(&mut self, rotation: EnvRotation) -> Option { self.components.iter_mut() .map(|comp| comp.set_rotation(rotation)) diff --git a/ferretro_components/src/dynamic_borrow.rs b/ferretro_components/src/dynamic_borrow.rs deleted file mode 100644 index 2b08967..0000000 --- a/ferretro_components/src/dynamic_borrow.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::cell::RefCell; -use std::rc::Rc; -use std::path::Path; - -use crate::base::ControlFlow; -use crate::base::RetroComponent; -use crate::base::Result; - -use ferretro_base::prelude::*; - -impl RetroComponent for Rc> where - T: RetroComponent, - Rc>: RetroCallbacks, -{ - fn pre_init(&mut self, retro: &mut LibretroWrapper) -> Result<()> { - RefCell::try_borrow_mut(self)?.pre_init(retro) - } - fn post_init(&mut self, retro: &mut LibretroWrapper) -> Result<()> { - RefCell::try_borrow_mut(self)?.post_init(retro) - } - fn pre_load_game(&mut self, retro: &mut LibretroWrapper, rom: &Path) -> Result<()> { - RefCell::try_borrow_mut(self)?.pre_load_game(retro, rom) - } - fn post_load_game(&mut self, retro: &mut LibretroWrapper, rom: &Path) -> Result<()> { - RefCell::try_borrow_mut(self)?.post_load_game(retro, rom) - } - fn pre_run(&mut self, retro: &mut LibretroWrapper) -> ControlFlow { - RefCell::borrow_mut(self).pre_run(retro) - } - fn post_run(&mut self, retro: &mut LibretroWrapper) -> ControlFlow { - RefCell::borrow_mut(self).post_run(retro) - } -} diff --git a/ferretro_components/src/lib.rs b/ferretro_components/src/lib.rs index 87754d8..b486886 100644 --- a/ferretro_components/src/lib.rs +++ b/ferretro_components/src/lib.rs @@ -2,11 +2,10 @@ pub mod provided; pub mod base; pub mod prelude { + //! Re-exports for types likely to be used by consumers of the crate. pub use crate::base::{RetroComponent, RetroComponentBase}; pub use ferretro_base::retro::constants::*; pub use ferretro_base::retro::wrapped_types::*; pub use ferretro_base::retro::wrapper::{RetroCallbacks, LibretroWrapper, LibretroWrapperAccess}; pub use ferretro_base::retro::ffi::{PixelFormat, GameGeometry, HwContextResetFn, HwRenderCallback, SystemAvInfo, SystemInfo, MemoryMap}; } - -mod dynamic_borrow; diff --git a/ferretro_components/src/provided/ffmpeg.rs b/ferretro_components/src/provided/ffmpeg.rs index af400eb..b9eca75 100644 --- a/ferretro_components/src/provided/ffmpeg.rs +++ b/ferretro_components/src/provided/ffmpeg.rs @@ -1,3 +1,5 @@ +//! (Experimental) support for recording a core's video and audio output to an encoded video file. + extern crate ffmpeg_next as ffmpeg; use std::collections::VecDeque; diff --git a/ferretro_components/src/provided/mod.rs b/ferretro_components/src/provided/mod.rs index 41b9467..f59078a 100644 --- a/ferretro_components/src/provided/mod.rs +++ b/ferretro_components/src/provided/mod.rs @@ -1,3 +1,5 @@ +//! Implementations of [RetroComponent](crate::base::RetroComponent) for common emulator use-cases. + #[cfg(feature = "ffmpeg_comp")] pub mod ffmpeg; diff --git a/ferretro_components/src/provided/stdlib.rs b/ferretro_components/src/provided/stdlib.rs index a855d21..8375802 100644 --- a/ferretro_components/src/provided/stdlib.rs +++ b/ferretro_components/src/provided/stdlib.rs @@ -35,10 +35,9 @@ impl RetroCallbacks for PathBufComponent { } /// Write's the core's own log statements to stderr. -/// -/// The public member [Self::prefix] may be set to add a prefix to each logged line. #[derive(Default)] pub struct StderrLogComponent { + /// May be set to add a prefix to each logged line. pub prefix: String, } @@ -51,10 +50,9 @@ impl RetroCallbacks for StderrLogComponent { /// Writes all the input descriptors, variables, and subsystem information to stderr as they are /// provided by the core. -/// -/// The public member [Self::prefix] may be set to add a prefix to each logged line. #[derive(Default)] pub struct StderrSysInfoLogComponent { + /// May be set to add a prefix to each logged line. pub prefix: String, } @@ -83,10 +81,9 @@ impl RetroCallbacks for StderrSysInfoLogComponent { } /// Trace-logs every callback call made and their arguments to stderr. -/// -/// The public member [Self::prefix] may be set to add a prefix to each logged line. #[derive(Default)] pub struct StderrCallTraceComponent { + /// May be set to add a prefix to each logged line. pub prefix: String, }