Merge pull request 'Split into two crates in one workspace: ferretro_core & ferretro_components' (#14) from viv/reorganize into matriarch

Reviewed-on: https://git.vvn.space/cinnabon/rustro/pulls/14
This commit is contained in:
Vivian Lim 2021-08-19 00:03:43 +00:00
commit a3cd71a3b2
23 changed files with 109 additions and 59 deletions

27
.gitignore vendored
View File

@ -1,13 +1,34 @@
# build artifacts
/target /target
**/*.rs.bk **/*.rs.bk
/.idea
/Cargo.lock /Cargo.lock
# editors
/.idea
/.vscode
# cores
*.so *.so
*.dll *.dll
*.dylib *.dylib
*.mp4
*.ogv # roms
*.gb *.gb
*.bin *.bin
*.sfc
*.z64
# save states
*.state*
# media
*.mp4
*.ogv
*.flv
*.flac
# scratch data
/scratch
# desktop.ini.mac
.DS_Store .DS_Store

View File

@ -1,28 +1,5 @@
[package] [workspace]
name = "ferretro" members = [
version = "0.1.0" "ferretro_base",
authors = ["lifning <lifning+git@pm.me>", "viv <vvnl+git@protonmail.com>", "iliana <iliana@buttslol.net>"] "ferretro_components",
edition = "2018" ]
[build-dependencies]
cc = "^1"
[dependencies]
libretro-sys = "0.1"
libloading = "0.5"
num_enum = "0.4"
ffmpeg-next = { version = "4.3.8", optional = true }
sdl2 = { version = "0.32", optional = true }
crossbeam-channel = { version = "0.4", optional = true }
[dev-dependencies]
# example: sdl2_emulator
sdl2 = "0.32"
crossbeam-channel = "0.4"
structopt = "0.3"
# example: ffmpeg_recorder
ffmpeg-next = "4.3.8"
[features]
ffmpeg_comp = ["ffmpeg-next"]
sdl2_comp = ["sdl2", "crossbeam-channel"]

22
ferretro_base/Cargo.toml Normal file
View File

@ -0,0 +1,22 @@
[package]
name = "ferretro_base"
version = "0.1.0"
authors = ["lifning <lifning+git@pm.me>", "viv <vvnl+git@protonmail.com>", "iliana <iliana@buttslol.net>"]
edition = "2018"
[build-dependencies]
cc = "^1"
[dependencies]
libretro-sys = "0.1"
libloading = "0.5"
num_enum = "0.4"
crossbeam-channel = { version = "0.4", optional = true }
[dev-dependencies]
# example: sdl2_emulator
sdl2 = "0.32"
crossbeam-channel = "0.4"
structopt = "0.3"
# example: ffmpeg_recorder
ffmpeg-next = "4.3.8"

View File

@ -1,4 +1,4 @@
extern crate ferretro; extern crate ferretro_base;
extern crate ffmpeg_next as ffmpeg; extern crate ffmpeg_next as ffmpeg;
use std::collections::VecDeque; use std::collections::VecDeque;
@ -8,11 +8,11 @@ use std::pin::Pin;
use structopt::StructOpt; use structopt::StructOpt;
use ferretro::retro; use ferretro_base::retro;
use ferretro::retro::ffi::{PixelFormat, GameGeometry, SystemAvInfo, SystemInfo}; use ferretro_base::retro::ffi::{PixelFormat, GameGeometry, SystemAvInfo, SystemInfo};
use ferretro::retro::wrapper::{LibretroWrapper, RetroCallbacks}; use ferretro_base::retro::wrapper::{LibretroWrapper, RetroCallbacks};
use ferretro::retro::wrapped_types::{Variable2}; use ferretro_base::retro::wrapped_types::{Variable2};
use ffmpeg::{ChannelLayout, Packet, codec, filter, format, frame, media}; use ffmpeg::{ChannelLayout, Packet, codec, filter, format, frame, media};
use ffmpeg::util::rational::Rational; use ffmpeg::util::rational::Rational;
@ -504,7 +504,7 @@ impl retro::wrapper::RetroCallbacks for MyEmulator {
fn get_variable(&mut self, key: &str) -> Option<String> { fn get_variable(&mut self, key: &str) -> Option<String> {
match key { match key {
"beetle_saturn_analog_stick_deadzone" => Some("15%".to_string()), "beetle_saturn_analog_stick_deadzone" => Some("15%".to_string()),
"parallel-n64-gfxplugin" => Some("angrylion".to_string()), //"parallel-n64-gfxplugin" => Some("angrylion".to_string()),
"parallel-n64-astick-deadzone" => Some("15%".to_string()), "parallel-n64-astick-deadzone" => Some("15%".to_string()),
_ => None, _ => None,
} }

View File

@ -1,12 +1,12 @@
extern crate crossbeam_channel; extern crate crossbeam_channel;
extern crate ferretro; extern crate ferretro_base;
extern crate sdl2; extern crate sdl2;
use ferretro::retro; use ferretro_base::retro;
use ferretro::retro::ffi::{GameGeometry, SystemInfo, SystemAvInfo}; use ferretro_base::retro::ffi::{GameGeometry, SystemInfo, SystemAvInfo};
use ferretro::retro::constants::{InputIndex, JoypadButton, AnalogAxis, DeviceType}; use ferretro_base::retro::constants::{InputIndex, JoypadButton, AnalogAxis, DeviceType};
use ferretro::retro::wrapped_types::{ControllerDescription2, InputDescriptor2, InputDeviceId, SubsystemInfo2, Variable2}; use ferretro_base::retro::wrapped_types::{ControllerDescription2, InputDescriptor2, InputDeviceId, SubsystemInfo2, Variable2};
use ferretro::retro::wrapper::LibretroWrapper; use ferretro_base::retro::wrapper::LibretroWrapper;
use std::ffi::CStr; use std::ffi::CStr;
use std::io::Read; use std::io::Read;

View File

@ -1,11 +1,9 @@
extern crate libloading; extern crate libloading;
pub mod retro; pub mod retro;
pub mod components;
pub mod prelude { pub mod prelude {
pub use crate::retro::constants::*; pub use crate::retro::constants::*;
pub use crate::components::{RetroComponent, RetroComponentBase};
pub use crate::retro::wrapped_types::*; pub use crate::retro::wrapped_types::*;
pub use crate::retro::wrapper::{RetroCallbacks, LibretroWrapper, LibretroWrapperAccess}; pub use crate::retro::wrapper::{RetroCallbacks, LibretroWrapper, LibretroWrapperAccess};
pub use crate::retro::ffi::{PixelFormat, GameGeometry, SystemAvInfo, SystemInfo}; pub use crate::retro::ffi::{PixelFormat, GameGeometry, SystemAvInfo, SystemInfo};

View File

@ -0,0 +1,24 @@
[package]
name = "ferretro_components"
version = "0.1.0"
authors = ["lifning <lifning+git@pm.me>", "viv <vvnl+git@protonmail.com>"]
edition = "2018"
[build-dependencies]
cc = "^1"
[dependencies]
ferretro_base = { path = "../ferretro_base"}
libloading = "0.5"
num_enum = "0.4"
ffmpeg-next = { version = "4.3.8", optional = true }
sdl2 = { version = "0.32", optional = true }
crossbeam-channel = { version = "0.4", optional = true }
[dev-dependencies]
crossbeam-channel = "0.4"
structopt = "0.3"
[features]
ffmpeg_comp = ["ffmpeg-next"]
sdl2_comp = ["sdl2", "crossbeam-channel"]

View File

@ -1,20 +1,20 @@
extern crate crossbeam_channel; extern crate crossbeam_channel;
extern crate ferretro; extern crate ferretro_components;
extern crate ffmpeg_next as ffmpeg; extern crate ffmpeg_next as ffmpeg;
extern crate sdl2; extern crate sdl2;
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt; use structopt::StructOpt;
use ferretro::prelude::*; use ferretro_components::prelude::*;
use ferretro::components::provided::{ use ferretro_components::provided::{
ffmpeg::FfmpegComponent, ffmpeg::FfmpegComponent,
sdl2::Sdl2Component, sdl2::Sdl2Component,
stdlib::{PathBufComponent, StderrLogComponent}, stdlib::{PathBufComponent, StderrLogComponent},
}; };
use ferretro::components::ControlFlow; use ferretro_components::base::ControlFlow;
use ferretro::components::provided::stdlib::StderrSysInfoLogComponent; use ferretro_components::provided::stdlib::StderrSysInfoLogComponent;
#[derive(StructOpt)] #[derive(StructOpt)]
struct Opt { struct Opt {

View File

@ -1,7 +1,5 @@
pub mod provided;
use crate::prelude::*; use crate::prelude::*;
use crate::retro::ffi::*; use ferretro_base::retro::ffi::*;
use std::os::raw::c_uint; use std::os::raw::c_uint;
use std::path::{PathBuf, Path}; use std::path::{PathBuf, Path};
use std::pin::Pin; use std::pin::Pin;
@ -48,7 +46,7 @@ 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(); let lib = libloading::Library::new(core_path.as_ref()).unwrap();
let raw_retro = crate::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 {
@ -69,7 +67,7 @@ impl RetroComponentBase {
}; };
let mut pin_emu = Box::pin(emu); let mut pin_emu = Box::pin(emu);
crate::retro::wrapper::set_handler(pin_emu.as_mut()); ferretro_base::retro::wrapper::set_handler(pin_emu.as_mut());
pin_emu.retro.init(); pin_emu.retro.init();
pin_emu pin_emu
} }
@ -495,6 +493,6 @@ impl RetroCallbacks for RetroComponentBase {
impl Drop for RetroComponentBase { impl Drop for RetroComponentBase {
fn drop(&mut self) { fn drop(&mut self) {
crate::retro::wrapper::unset_handler(); ferretro_base::retro::wrapper::unset_handler();
} }
} }

View File

@ -0,0 +1,10 @@
pub mod provided;
pub mod base;
pub mod prelude {
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, SystemAvInfo, SystemInfo};
}

View File

@ -8,7 +8,7 @@ use crate::prelude::*;
use ffmpeg::{ChannelLayout, Packet, filter, format, frame, media}; use ffmpeg::{ChannelLayout, Packet, filter, format, frame, media};
use ffmpeg::util::rational::Rational; use ffmpeg::util::rational::Rational;
use crate::components::ControlFlow; use crate::base::ControlFlow;
enum EncoderToWriteFrom { enum EncoderToWriteFrom {
Video, Video,

View File

@ -4,7 +4,7 @@ use std::path::Path;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use crate::prelude::*; use crate::prelude::*;
use crate::components::ControlFlow; use crate::base::ControlFlow;
use sdl2::audio::{AudioCallback, AudioFormat, AudioSpec, AudioSpecDesired, AudioDevice}; use sdl2::audio::{AudioCallback, AudioFormat, AudioSpec, AudioSpecDesired, AudioDevice};
use sdl2::controller::{GameController, Button, Axis}; use sdl2::controller::{GameController, Button, Axis};

View File

@ -32,7 +32,7 @@ pub struct StderrLogComponent {
impl RetroComponent for StderrLogComponent {} impl RetroComponent for StderrLogComponent {}
impl RetroCallbacks for StderrLogComponent { impl RetroCallbacks for StderrLogComponent {
fn log_print(&mut self, level: crate::retro::ffi::LogLevel, msg: &str) { fn log_print(&mut self, level: ferretro_base::retro::ffi::LogLevel, msg: &str) {
eprint!("{}[{:?}] {}", self.prefix, level, msg); eprint!("{}[{:?}] {}", self.prefix, level, msg);
} }
} }