ferretro/examples/multifunction_emulator.rs

67 lines
2.1 KiB
Rust

extern crate crossbeam_channel;
extern crate ferretro;
extern crate ffmpeg_next as ffmpeg;
extern crate sdl2;
use std::path::PathBuf;
use structopt::StructOpt;
use ferretro::prelude::*;
use ferretro::components::provided::{
ffmpeg::FfmpegComponent,
sdl2::Sdl2Component,
stdlib::{PathBufComponent, StderrLogComponent},
};
use ferretro::components::ControlFlow;
use ferretro::components::provided::stdlib::StderrSysInfoLogComponent;
#[derive(StructOpt)]
struct Opt {
/// Core module to use.
#[structopt(short, long, parse(from_os_str))]
core: PathBuf,
/// ROM to load using the core.
#[structopt(short, long, parse(from_os_str))]
rom: PathBuf,
/// Save state to load at startup.
#[structopt(long, parse(from_os_str))]
state: Option<PathBuf>,
/// System directory, often containing BIOS files
#[structopt(short, long, parse(from_os_str))]
system: Option<PathBuf>,
/// Recorded video to write.
#[structopt(short, long, parse(from_os_str))]
video: Option<PathBuf>,
}
pub fn main() {
let opt: Opt = Opt::from_args();
let mut emu = RetroComponentBase::new(&opt.core);
let sdl2_comp = Sdl2Component::new(emu.libretro_core());
emu.register_component(sdl2_comp);
emu.register_component(StderrLogComponent::default());
emu.register_component(StderrSysInfoLogComponent::default());
emu.register_component(PathBufComponent {
sys_path: opt.system.clone(),
libretro_path: Some(opt.core.to_path_buf()),
core_assets_path: None,
save_path: Some(std::env::temp_dir()),
});
if let Some(video) = opt.video {
ffmpeg::log::set_level(ffmpeg::log::Level::Info);
ffmpeg::init().unwrap();
let ffmpeg_comp = FfmpegComponent::new(emu.libretro_core(), video);
emu.register_component(ffmpeg_comp);
}
emu.load_game(&opt.rom).unwrap();
if let Some(state) = opt.state {
emu.unserialize_path(state).unwrap();
}
let mut frame = 0;
while let ControlFlow::Continue = emu.run() {
frame += 1;
}
eprintln!("Ran for {} frames.", frame);
}