Skip to content

Commit

Permalink
letsplay_retro_frontend: Split the libretro_sys additions to a new crate
Browse files Browse the repository at this point in the history
More refactoring. Must shave more yak.
  • Loading branch information
modeco80 committed Jan 29, 2025
1 parent 9207d73 commit 01fe982
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 33 deletions.
10 changes: 9 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"crates/letsplay_av_ffmpeg",

# Libretro frontend library
"crates/letsplay_libretro_sys",
"crates/letsplay_retro_frontend",
"crates/retrodemo",

Expand Down
12 changes: 12 additions & 0 deletions crates/letsplay_libretro_sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "letsplay_libretro_sys"
description = "Selective updates on top of the libretro-sys crate (which was last updated 2016)"
publish.workspace = true
version.workspace = true
edition.workspace = true

[dependencies]
libretro-sys = "0.1.1"

[build-dependencies]
cc = "1.0.99"
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
//! Selective additional (2019+) updates on top of the existing libretro_sys crate.
//! This was created since newer cores do use this stuff; it's annoying, but meh.
//! Maybe later on we can rid ourselves of a 2016 crate and just bindgen off libretro
//! directly; for now, this is fine enough.
pub use libretro_sys::*;
use std::ffi;

/// This "button" represents a bitmask that describes the state of all [DEVICE_JOYPAD] button constants,
/// rather than the state of a single button.
pub const DEVICE_ID_JOYPAD_MASK: libc::c_uint = 256;
pub const DEVICE_ID_JOYPAD_MASK: ffi::c_uint = 256;

/// Defines overrides which modify frontend handling of specific content file types.
/// An array of [SystemContentInfoOverride] is passed to [RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE]
Expand Down
2 changes: 1 addition & 1 deletion crates/letsplay_retro_frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition.workspace = true
[dependencies]
libc.workspace = true
libloading.workspace = true
libretro-sys = "0.1.1"
letsplay_libretro_sys.path = "../letsplay_libretro_sys"
thiserror.workspace = true

anyhow.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/letsplay_retro_frontend/src/frontend/callbacks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Callbacks for libretro
use crate::libretro_sys_new::*;
use letsplay_libretro_sys::*;
use crate::{frontend::*, libretro_log, util};

use std::ffi;
Expand Down
6 changes: 3 additions & 3 deletions crates/letsplay_retro_frontend/src/frontend/frontend_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::CoreVariable;
use crate::input_devices::InputDevice;
use crate::libretro_sys_new::*;
use letsplay_libretro_sys::*;
use crate::result::{Error, Result};
use ffi::CString;
use libloading::Library;
Expand Down Expand Up @@ -272,13 +272,13 @@ impl Frontend {
// Let's sanity check the libretro API version against bindings to make sure we can actually use this core.
// If we can't, then fail the load.
let api_version = (core_api.retro_api_version)();
if api_version != libretro_sys::API_VERSION {
if api_version != letsplay_libretro_sys::API_VERSION {
error!(
"Core {} has invalid API version {api_version}; refusing to continue loading",
path.as_ref().display()
);
return Err(Error::InvalidLibRetroAPI {
expected: libretro_sys::API_VERSION,
expected: letsplay_libretro_sys::API_VERSION,
got: api_version,
});
}
Expand Down
30 changes: 14 additions & 16 deletions crates/letsplay_retro_frontend/src/input_devices/analog_retropad.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::libretro_sys_new;

use super::{InputDevice, RetroPad};

// private helper type for packaging up the stick data
Expand Down Expand Up @@ -45,7 +43,7 @@ impl AnalogRetroPad {

impl InputDevice for AnalogRetroPad {
fn device_type(&self) -> u32 {
libretro_sys_new::DEVICE_ANALOG
letsplay_libretro_sys::DEVICE_ANALOG
}

fn device_type_compatible(&self, id: u32) -> bool {
Expand All @@ -54,7 +52,7 @@ impl InputDevice for AnalogRetroPad {
true
} else {
// Check for the analog type
id == libretro_sys_new::DEVICE_ANALOG
id == letsplay_libretro_sys::DEVICE_ANALOG
}
}

Expand All @@ -68,14 +66,14 @@ impl InputDevice for AnalogRetroPad {
// Nasty but you can blame libretro.
let fallback = self.pad.get_index(0, id);
return match index {
libretro_sys_new::DEVICE_INDEX_ANALOG_LEFT => match id {
libretro_sys_new::DEVICE_ID_ANALOG_X => self.left_stick.x,
libretro_sys_new::DEVICE_ID_ANALOG_Y => self.left_stick.y,
letsplay_libretro_sys::DEVICE_INDEX_ANALOG_LEFT => match id {
letsplay_libretro_sys::DEVICE_ID_ANALOG_X => self.left_stick.x,
letsplay_libretro_sys::DEVICE_ID_ANALOG_Y => self.left_stick.y,
_ => fallback,
},
libretro_sys_new::DEVICE_INDEX_ANALOG_RIGHT => match id {
libretro_sys_new::DEVICE_ID_ANALOG_X => self.right_stick.x,
libretro_sys_new::DEVICE_ID_ANALOG_Y => self.right_stick.y,
letsplay_libretro_sys::DEVICE_INDEX_ANALOG_RIGHT => match id {
letsplay_libretro_sys::DEVICE_ID_ANALOG_X => self.right_stick.x,
letsplay_libretro_sys::DEVICE_ID_ANALOG_Y => self.right_stick.y,
_ => fallback,
},

Expand All @@ -97,15 +95,15 @@ impl InputDevice for AnalogRetroPad {
};

match index {
libretro_sys_new::DEVICE_INDEX_ANALOG_LEFT => match id {
libretro_sys_new::DEVICE_ID_ANALOG_X => self.left_stick.x = pressure,
libretro_sys_new::DEVICE_ID_ANALOG_Y => self.left_stick.y = pressure,
letsplay_libretro_sys::DEVICE_INDEX_ANALOG_LEFT => match id {
letsplay_libretro_sys::DEVICE_ID_ANALOG_X => self.left_stick.x = pressure,
letsplay_libretro_sys::DEVICE_ID_ANALOG_Y => self.left_stick.y = pressure,
_ => {}
},

libretro_sys_new::DEVICE_INDEX_ANALOG_RIGHT => match id {
libretro_sys_new::DEVICE_ID_ANALOG_X => self.right_stick.x = pressure,
libretro_sys_new::DEVICE_ID_ANALOG_Y => self.right_stick.y = pressure,
letsplay_libretro_sys::DEVICE_INDEX_ANALOG_RIGHT => match id {
letsplay_libretro_sys::DEVICE_ID_ANALOG_X => self.right_stick.x = pressure,
letsplay_libretro_sys::DEVICE_ID_ANALOG_Y => self.right_stick.y = pressure,
_ => {}
},

Expand Down
3 changes: 1 addition & 2 deletions crates/letsplay_retro_frontend/src/input_devices/mouse.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Mouse
use super::InputDevice;
use crate::libretro_sys_new;

/// Implementation of the [InputDevice] trait for the Libretro mouse.
pub struct Mouse {
Expand All @@ -21,7 +20,7 @@ impl Mouse {

impl InputDevice for Mouse {
fn device_type(&self) -> u32 {
libretro_sys_new::DEVICE_MOUSE
letsplay_libretro_sys::DEVICE_MOUSE
}

fn device_type_compatible(&self, id: u32) -> bool {
Expand Down
6 changes: 3 additions & 3 deletions crates/letsplay_retro_frontend/src/input_devices/retropad.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! RetroPad
use super::InputDevice;
use crate::libretro_sys_new;
use letsplay_libretro_sys;

/// Implementation of the [InputDevice] trait for the Libretro
/// RetroPad; which is essentially a standard PS1 controller,
Expand Down Expand Up @@ -45,7 +45,7 @@ impl RetroPad {

impl InputDevice for RetroPad {
fn device_type(&self) -> u32 {
libretro_sys_new::DEVICE_JOYPAD
letsplay_libretro_sys::DEVICE_JOYPAD
}

fn device_type_compatible(&self, id: u32) -> bool {
Expand All @@ -55,7 +55,7 @@ impl InputDevice for RetroPad {
fn get_index(&self, index: u32, id: u32) -> i16 {
return match index {
0 => {
if id == libretro_sys_new::DEVICE_ID_JOYPAD_MASK {
if id == letsplay_libretro_sys::DEVICE_ID_JOYPAD_MASK {
return self.button_mask();
}

Expand Down
5 changes: 2 additions & 3 deletions crates/letsplay_retro_frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
mod libretro_log;

pub mod libretro_sys_new;

pub mod input_devices;
pub mod util;
mod util;

pub mod frontend;
pub mod result;

// re-export some of our useful interface
pub use frontend::{CoreVariable, Frontend, FrontendInterface};
pub use result::*;
2 changes: 1 addition & 1 deletion crates/letsplay_retro_frontend/src/libretro_log.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::libretro_sys_new::*;
use letsplay_libretro_sys::*;
use std::ffi;
use tracing::*;

Expand Down
2 changes: 1 addition & 1 deletion crates/letsplay_retro_frontend/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::libretro_sys_new::*;
use letsplay_libretro_sys::*;

pub fn bytes_per_pixel_from_libretro(pf: PixelFormat) -> u32 {
match pf {
Expand Down

0 comments on commit 01fe982

Please sign in to comment.