implement ENVIRONMENT_GET_PROC_ADDRESS

This commit is contained in:
lif 2019-11-18 01:01:33 -08:00
parent 7f36723025
commit 7b50e6b975
1 changed files with 13 additions and 1 deletions

View File

@ -248,7 +248,11 @@ impl StaticCallbacks {
EnvCmd::GetCoreAssetsDirectory => Self::path_into_void(data, handler.get_core_assets_directory()?)?,
EnvCmd::GetSaveDirectory => Self::path_into_void(data, handler.get_save_directory()?)?,
EnvCmd::SetSystemAvInfo => handler.set_system_av_info(Self::from_void::<SystemAvInfo>(data)?.clone()),
// TODO EnvCmd::SetProcAddressCallback => {},
EnvCmd::SetProcAddressCallback => {
let gpa = Self::from_void::<GetProcAddressInterface>(data)?;
handler.libretro_core().get_proc_address_cb.replace(gpa.get_proc_address);
true
},
// TODO EnvCmd::SetSubsystemInfo => {},
EnvCmd::SetControllerInfo => {
let info = unsafe { (data as *const ControllerInfo).as_ref() }?;
@ -377,6 +381,7 @@ pub struct LibretroWrapper {
disk_add_image_index_cb: Option<AddImageIndexFn>,
hw_context_reset_cb: Option<HwContextResetFn>,
hw_context_destroy_cb: Option<HwContextResetFn>, // same signature, libretro-sys deduplicated...
get_proc_address_cb: Option<GetProcAddressFn>,
}
impl From<LibretroApi> for LibretroWrapper {
@ -396,6 +401,7 @@ impl From<LibretroApi> for LibretroWrapper {
disk_add_image_index_cb: None,
hw_context_reset_cb: None,
hw_context_destroy_cb: None,
get_proc_address_cb: None,
}
}
}
@ -447,6 +453,12 @@ impl LibretroWrapper {
pub fn hw_context_destroy(&self) -> Option<()> {
self.hw_context_destroy_cb.map(|f| unsafe { f() })
}
pub fn get_proc_address(&self, sym: &str) -> Option<ProcAddressFn> {
self.get_proc_address_cb.and_then(|f| unsafe {
let csym = CString::new(sym).ok()?;
Some(f(csym.as_ptr()))
})
}
}
impl Deref for LibretroWrapper {