actually load multiple separate instances of the core (OS will deduplicate by path)
This commit is contained in:
parent
53642557a0
commit
aa33f331f0
|
@ -11,4 +11,4 @@ cc = "^1"
|
||||||
libretro-sys = "0.1"
|
libretro-sys = "0.1"
|
||||||
libloading = "0.5"
|
libloading = "0.5"
|
||||||
num_enum = "0.4"
|
num_enum = "0.4"
|
||||||
once_cell = "1.8"
|
once_cell = "1"
|
||||||
|
|
|
@ -15,6 +15,7 @@ ffmpeg-next = { version = "4.3.8", optional = true }
|
||||||
sdl2 = { version = "0.32", optional = true, features = ["gfx"] }
|
sdl2 = { version = "0.32", optional = true, features = ["gfx"] }
|
||||||
gl = { version = "0.14", optional = true }
|
gl = { version = "0.14", optional = true }
|
||||||
crossbeam-channel = { version = "0.4", optional = true }
|
crossbeam-channel = { version = "0.4", optional = true }
|
||||||
|
tempfile = "3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
crossbeam-channel = "0.4"
|
crossbeam-channel = "0.4"
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use ferretro_base::retro::ffi::*;
|
use ferretro_base::retro::ffi::*;
|
||||||
|
use ferretro_base::prelude::{LibretroWrapperAccess, RetroHandlerId};
|
||||||
|
|
||||||
use core::any::{Any, TypeId};
|
use core::any::{Any, TypeId};
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
|
@ -13,7 +14,6 @@ use std::path::{PathBuf, Path};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
use ferretro_base::prelude::{LibretroWrapperAccess, RetroHandlerId};
|
|
||||||
|
|
||||||
pub struct RetroComponentBase {
|
pub struct RetroComponentBase {
|
||||||
retro: LibretroWrapper,
|
retro: LibretroWrapper,
|
||||||
|
@ -37,6 +37,7 @@ pub struct RetroComponentBase {
|
||||||
cached_geometry: Option<GameGeometry>,
|
cached_geometry: Option<GameGeometry>,
|
||||||
|
|
||||||
handler_id: Option<RetroHandlerId>,
|
handler_id: Option<RetroHandlerId>,
|
||||||
|
_temp_dir: tempfile::TempDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: replace with std::ops::ControlFlow when it becomes stable
|
// TODO: replace with std::ops::ControlFlow when it becomes stable
|
||||||
|
@ -61,13 +62,18 @@ pub trait RetroComponent: RetroCallbacks + Any {
|
||||||
impl RetroComponentBase {
|
impl RetroComponentBase {
|
||||||
// TODO: constructor & wrapper that uses a statically linked libretro?
|
// TODO: constructor & wrapper that uses a statically linked libretro?
|
||||||
pub fn new(core_path: impl AsRef<Path>) -> Pin<Box<Self>> {
|
pub fn new(core_path: impl AsRef<Path>) -> Pin<Box<Self>> {
|
||||||
let lib = libloading::Library::new(core_path.as_ref()).unwrap();
|
// allow multiple copies of same lib, possibly?
|
||||||
|
let temp_dir = tempfile::tempdir().unwrap();
|
||||||
|
let libretro_path = temp_dir.path().join(core_path.as_ref().file_name().unwrap());
|
||||||
|
std::fs::copy(core_path.as_ref(), &libretro_path).unwrap();
|
||||||
|
|
||||||
|
let lib = libloading::Library::new(&libretro_path).unwrap();
|
||||||
let raw_retro = ferretro_base::retro::loading::LibretroApi::from_library(lib).unwrap();
|
let raw_retro = ferretro_base::retro::loading::LibretroApi::from_library(lib).unwrap();
|
||||||
let retro = LibretroWrapper::from(raw_retro);
|
let retro = LibretroWrapper::from(raw_retro);
|
||||||
|
|
||||||
let emu = RetroComponentBase {
|
let emu = RetroComponentBase {
|
||||||
retro,
|
retro,
|
||||||
libretro_path: core_path.as_ref().to_path_buf(),
|
libretro_path,
|
||||||
components: Default::default(),
|
components: Default::default(),
|
||||||
component_ptrs: Default::default(),
|
component_ptrs: Default::default(),
|
||||||
cached_rom_path: None,
|
cached_rom_path: None,
|
||||||
|
@ -82,6 +88,7 @@ impl RetroComponentBase {
|
||||||
cached_memory_map: None,
|
cached_memory_map: None,
|
||||||
cached_geometry: None,
|
cached_geometry: None,
|
||||||
handler_id: None,
|
handler_id: None,
|
||||||
|
_temp_dir: temp_dir,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut pin_emu = Box::pin(emu);
|
let mut pin_emu = Box::pin(emu);
|
||||||
|
|
Loading…
Reference in New Issue