constructor for RetroComponentBase

This commit is contained in:
lifning 2021-08-11 01:08:22 -07:00
parent 47d7113b03
commit 7b06ed61d1
3 changed files with 50 additions and 33 deletions

View File

@ -285,7 +285,7 @@ impl retro::wrapper::RetroCallbacks for MyEmulator {
} }
} }
fn set_variables(&mut self, variables: Vec<Variable2>) -> bool { fn set_variables(&mut self, variables: &Vec<Variable2>) -> bool {
for v in variables { for v in variables {
eprintln!("{:?}", v); eprintln!("{:?}", v);
} }
@ -311,12 +311,12 @@ impl retro::wrapper::RetroCallbacks for MyEmulator {
true true
} }
fn set_subsystem_info(&mut self, subsystem_info: Vec<SubsystemInfo2>) -> bool { fn set_subsystem_info(&mut self, subsystem_info: &Vec<SubsystemInfo2>) -> bool {
println!("subsystem info: {:?}", subsystem_info); println!("subsystem info: {:?}", subsystem_info);
true true
} }
fn set_controller_info(&mut self, controller_info: Vec<ControllerDescription2>) -> bool { fn set_controller_info(&mut self, controller_info: &Vec<ControllerDescription2>) -> bool {
for ci in controller_info { for ci in controller_info {
// so we can have analog support in beetle/mednafen saturn // so we can have analog support in beetle/mednafen saturn
if ci.name.as_str() == "3D Control Pad" { if ci.name.as_str() == "3D Control Pad" {
@ -327,7 +327,7 @@ impl retro::wrapper::RetroCallbacks for MyEmulator {
true true
} }
fn set_input_descriptors(&mut self, descriptors: Vec<InputDescriptor2>) -> bool { fn set_input_descriptors(&mut self, descriptors: &Vec<InputDescriptor2>) -> bool {
for id in descriptors { for id in descriptors {
println!("{:?}", id); println!("{:?}", id);
} }

View File

@ -1,13 +1,32 @@
use crate::prelude::*; use crate::prelude::*;
use crate::retro::ffi::*; use crate::retro::ffi::*;
use std::os::raw::c_uint; use std::os::raw::c_uint;
use std::path::PathBuf; use std::path::{PathBuf, Path};
use std::pin::Pin;
pub struct RetroComponentBase { pub struct RetroComponentBase {
retro: LibretroWrapper, retro: LibretroWrapper,
pub components: Vec<Box<dyn RetroCallbacks>>, pub components: Vec<Box<dyn RetroCallbacks>>,
} }
impl RetroComponentBase {
pub fn new(core_path: impl AsRef<Path>) -> Pin<Box<Self>> {
let lib = libloading::Library::new(core_path.as_ref()).unwrap();
let raw_retro = crate::retro::loading::LibretroApi::from_library(lib).unwrap();
let retro = LibretroWrapper::from(raw_retro);
let emu = RetroComponentBase {
retro,
components: Vec::new(),
};
let mut pin_emu = Box::pin(emu);
crate::retro::wrapper::set_handler(pin_emu.as_mut());
pin_emu.retro.init();
pin_emu
}
}
impl LibretroWrapperAccess for RetroComponentBase { impl LibretroWrapperAccess for RetroComponentBase {
fn libretro_core(&mut self) -> &mut LibretroWrapper { fn libretro_core(&mut self) -> &mut LibretroWrapper {
&mut self.retro &mut self.retro

View File

@ -49,7 +49,7 @@ impl LibretroApi {
pub fn set_environment(&self, cb: EnvironmentFn) { pub fn set_environment(&self, cb: EnvironmentFn) {
unsafe { (&self.core_api.retro_set_environment)(cb) } unsafe { (&self.core_api.retro_set_environment)(cb) }
} }
/// video_refresh() must be called before run(). /// set_video_refresh() must be called before run().
pub fn set_video_refresh(&self, cb: VideoRefreshFn) { pub fn set_video_refresh(&self, cb: VideoRefreshFn) {
unsafe { (&self.core_api.retro_set_video_refresh)(cb) } unsafe { (&self.core_api.retro_set_video_refresh)(cb) }
} }
@ -85,11 +85,11 @@ impl LibretroApi {
info info
} }
} }
/** Gets information about system audio/video timings and geometry. /// Gets information about system audio/video timings and geometry.
* Can be called only after load_game() has successfully completed. /// Can be called only after load_game() has successfully completed.
* NOTE: The implementation of this function might not initialize every variable if needed. /// NOTE: The implementation of this function might not initialize every variable if needed.
* E.g. geom.aspect_ratio might not be initialized if core doesn't /// E.g. geom.aspect_ratio might not be initialized if core doesn't
* desire a particular aspect ratio. */ /// desire a particular aspect ratio.
pub fn get_system_av_info(&self) -> SystemAvInfo { pub fn get_system_av_info(&self) -> SystemAvInfo {
unsafe { unsafe {
let mut av_info = ::std::mem::zeroed::<SystemAvInfo>(); let mut av_info = ::std::mem::zeroed::<SystemAvInfo>();
@ -97,20 +97,19 @@ impl LibretroApi {
av_info av_info
} }
} }
/** Sets device to be used for player 'port'. /// Sets device to be used for player 'port'.
* By default, RETRO_DEVICE_JOYPAD is assumed to be plugged into all /// By default, RETRO_DEVICE_JOYPAD is assumed to be plugged into all
* available ports. /// available ports.
* Setting a particular device type is not a guarantee that libretro cores /// Setting a particular device type is not a guarantee that libretro cores
* will only poll input based on that particular device type. It is only a /// will only poll input based on that particular device type. It is only a
* hint to the libretro core when a core cannot automatically detect the /// hint to the libretro core when a core cannot automatically detect the
* appropriate input device type on its own. It is also relevant when a /// appropriate input device type on its own. It is also relevant when a
* core can change its behavior depending on device type. /// core can change its behavior depending on device type.
* ///
* As part of the core's implementation of retro_set_controller_port_device, /// As part of the core's implementation of retro_set_controller_port_device,
* the core should call RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS to notify the /// the core should call RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS to notify the
* frontend if the descriptions for any controls have changed as a /// frontend if the descriptions for any controls have changed as a
* result of changing the device type. /// result of changing the device type.
*/
pub fn set_controller_port_device(&self, port: u32, device: u32) { pub fn set_controller_port_device(&self, port: u32, device: u32) {
unsafe { (&self.core_api.retro_set_controller_port_device)(port, device) } unsafe { (&self.core_api.retro_set_controller_port_device)(port, device) }
} }
@ -118,14 +117,13 @@ impl LibretroApi {
pub fn reset(&self) { pub fn reset(&self) {
unsafe { (&self.core_api.retro_reset)() } unsafe { (&self.core_api.retro_reset)() }
} }
/** Runs the game for one video frame. /// Runs the game for one video frame.
* During retro_run(), input_poll callback must be called at least once. /// During retro_run(), input_poll callback must be called at least once.
* ///
* If a frame is not rendered for reasons where a game "dropped" a frame, /// If a frame is not rendered for reasons where a game "dropped" a frame,
* this still counts as a frame, and retro_run() should explicitly dupe /// this still counts as a frame, and retro_run() should explicitly dupe
* a frame if GET_CAN_DUPE returns true. /// a frame if GET_CAN_DUPE returns true.
* In this case, the video callback can take a NULL argument for data. /// In this case, the video callback can take a NULL argument for data.
*/
pub fn run(&self) { pub fn run(&self) {
unsafe { (&self.core_api.retro_run)() } unsafe { (&self.core_api.retro_run)() }
} }