ferretro/ferretro_components/src/provided/stdlib.rs

81 lines
2.2 KiB
Rust

use std::path::PathBuf;
use crate::prelude::*;
#[derive(Default)]
pub struct PathBufComponent {
pub sys_path: Option<PathBuf>,
pub libretro_path: Option<PathBuf>,
pub core_assets_path: Option<PathBuf>,
pub save_path: Option<PathBuf>,
}
impl RetroComponent for PathBufComponent {}
impl RetroCallbacks for PathBufComponent {
fn get_system_directory(&mut self) -> Option<PathBuf> {
self.sys_path.clone()
}
fn get_libretro_path(&mut self) -> Option<PathBuf> {
self.libretro_path.clone()
}
fn get_core_assets_directory(&mut self) -> Option<PathBuf> {
self.core_assets_path.clone()
}
fn get_save_directory(&mut self) -> Option<PathBuf> {
self.save_path.clone()
}
}
#[derive(Default)]
pub struct StderrLogComponent {
pub prefix: String,
}
impl RetroComponent for StderrLogComponent {}
impl RetroCallbacks for StderrLogComponent {
fn log_print(&mut self, level: ferretro_base::retro::ffi::LogLevel, msg: &str) {
eprint!("{}[{:?}] {}", self.prefix, level, msg);
}
}
#[derive(Default)]
pub struct StderrSysInfoLogComponent {
pub prefix: String,
}
impl RetroComponent for StderrSysInfoLogComponent {}
impl RetroCallbacks for StderrSysInfoLogComponent {
fn set_input_descriptors(&mut self, descriptors: &Vec<InputDescriptor2>) -> Option<bool> {
for id in descriptors {
eprintln!("{}{:?}", self.prefix, id);
}
Some(true)
}
fn set_variables(&mut self, variables: &Vec<Variable2>) -> Option<bool> {
for v in variables {
eprintln!("{}{:?}", self.prefix, v);
}
Some(true)
}
fn set_subsystem_info(&mut self, subsystem_info: &Vec<SubsystemInfo2>) -> Option<bool> {
for s in subsystem_info {
eprintln!("{}{:?}", self.prefix, s);
}
Some(true)
}
}
#[derive(Default)]
pub struct StderrCallTraceComponent {
pub prefix: String,
}
impl RetroComponent for StderrCallTraceComponent {}
impl RetroCallbacks for StderrCallTraceComponent {
fn audio_sample(&mut self, left: i16, right: i16) {
eprintln!("{}audio_sample({}, {})", self.prefix, left, right);
}
// TODO: etc...
}