Skip to content

Commit

Permalink
Release 0.2.0
Browse files Browse the repository at this point in the history
rust-libretro@0.2.0
rust-libretro-example-core@0.2.0
rust-libretro-proc@0.2.0
rust-libretro-sys@0.2.0
rust-libretro-sys-proc@0.2.0

Generated by cargo-workspaces
  • Loading branch information
max-m committed Dec 31, 2022
1 parent 83e1afa commit 2cf0599
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 52 deletions.
4 changes: 2 additions & 2 deletions rust-libretro-example-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-libretro-example-core"
version = "0.1.9"
version = "0.2.0"
edition = "2021"
authors = [ "Maximilian Mader" ]
description = "libretro example core"
Expand All @@ -20,7 +20,7 @@ libc = "0.2.119"
log = "0.4.14"

[dependencies.rust-libretro]
version = "0.1.9"
version = "0.2.0"
path = "../rust-libretro"
features = [ "log", "unstable-env-commands" ]

Expand Down
2 changes: 1 addition & 1 deletion rust-libretro-example-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Core for ExampleCore {
chunk.fill(color);
}

ctx.draw_frame(self.pixels.as_ref(), width, height, width as u64 * 4);
ctx.draw_frame(self.pixels.as_ref(), width, height, width as usize * 4);
} else if ctx.can_dupe() {
ctx.dupe_frame();
}
Expand Down
4 changes: 2 additions & 2 deletions rust-libretro-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-libretro-sys"
version = "0.1.9"
version = "0.2.0"
edition = "2021"
authors = [ "Maximilian Mader" ]
description = "libretro API bindings generated via bindgen"
Expand All @@ -14,7 +14,7 @@ repository = "https://github.com/max-m/rust-libretro/"

[dependencies]
libc = "0.2.119"
rust-libretro-sys-proc = { version = "0.1.9", path = "rust-libretro-sys-proc" }
rust-libretro-sys-proc = { version = "0.2.0", path = "rust-libretro-sys-proc" }

[build-dependencies]
bindgen = "0.63.0"
2 changes: 1 addition & 1 deletion rust-libretro-sys/rust-libretro-sys-proc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-libretro-sys-proc"
version = "0.1.9"
version = "0.2.0"
edition = "2021"
authors = [ "Maximilian Mader" ]
description = "Procedural macros for rust-libretro-sys"
Expand Down
6 changes: 3 additions & 3 deletions rust-libretro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-libretro"
version = "0.1.9"
version = "0.2.0"
edition = "2021"
authors = [ "Maximilian Mader" ]
description = "libretro API abstractions"
Expand All @@ -21,8 +21,8 @@ rustdoc-args = [ "--document-private-items" ]
unstable-env-commands = []

[dependencies]
rust-libretro-sys = { version = "0.1.9", path = "../rust-libretro-sys" }
rust-libretro-proc = { version = "0.1.9", path = "rust-libretro-proc" }
rust-libretro-sys = { version = "0.2.0", path = "../rust-libretro-sys" }
rust-libretro-proc = { version = "0.2.0", path = "rust-libretro-proc" }

cfg-if = "1.0.0"
bitflags = "1.3.2"
Expand Down
2 changes: 1 addition & 1 deletion rust-libretro/examples/input/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl Core for InputTestCore {

let width = fb.width;
let height = fb.height;
let pitch = fb.pitch as u64;
let pitch = fb.pitch;
ctx.draw_frame(data, width, height, pitch);
}
}
Expand Down
6 changes: 3 additions & 3 deletions rust-libretro/examples/test-advanced/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ impl Core for AdvancedTestCore {

let width = fb.width;
let height = fb.height;
let pitch = fb.pitch as u64;
let pitch = fb.pitch;
ctx.draw_frame(data, width, height, pitch);
}

Expand All @@ -1007,8 +1007,8 @@ impl Core for AdvancedTestCore {
ctx.batch_audio_samples(&samples);
}

fn get_serialize_size(&mut self, _ctx: &mut GetSerializeSizeContext) -> size_t {
std::mem::size_of::<State>() as u64
fn get_serialize_size(&mut self, _ctx: &mut GetSerializeSizeContext) -> usize {
std::mem::size_of::<State>()
}

fn on_serialize(&mut self, slice: &mut [u8], _ctx: &mut SerializeContext) -> bool {
Expand Down
8 changes: 4 additions & 4 deletions rust-libretro/examples/test/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ impl TestCore {

let width = fb.width;
let height = fb.height;
let pitch = fb.pitch as u64;
let pitch = fb.pitch;
ctx.draw_frame(data, width, height, pitch);
}

Expand Down Expand Up @@ -645,7 +645,7 @@ impl Core for TestCore {
&mut self,
game_type: std::os::raw::c_uint,
_info: *const retro_game_info,
num_info: size_t,
num_info: usize,
ctx: &mut LoadGameSpecialContext,
) -> Result<(), Box<dyn std::error::Error>> {
log::info!("Loading special content!");
Expand Down Expand Up @@ -864,8 +864,8 @@ impl Core for TestCore {
log::info!("Keyboard:\n\tDown: {down}\n\tCode: {keycode:?}\n\tChar: {character}\n\tMod: {key_modifiers:?}");
}

fn get_serialize_size(&mut self, _ctx: &mut GetSerializeSizeContext) -> size_t {
(std::mem::size_of_val(&self.x_coord) + std::mem::size_of_val(&self.y_coord)) as size_t
fn get_serialize_size(&mut self, _ctx: &mut GetSerializeSizeContext) -> usize {
std::mem::size_of_val(&self.x_coord) + std::mem::size_of_val(&self.y_coord)
}

fn on_serialize(&mut self, slice: &mut [u8], _ctx: &mut SerializeContext) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions rust-libretro/rust-libretro-proc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-libretro-proc"
version = "0.1.9"
version = "0.2.0"
edition = "2021"
authors = [ "Maximilian Mader" ]
description = "Procedural macros for rust-libretro"
Expand All @@ -16,7 +16,7 @@ repository = "https://github.com/max-m/rust-libretro/"
proc-macro = true

[dependencies]
rust-libretro-sys = { version = "0.1.9", path = "../../rust-libretro-sys" }
rust-libretro-sys = { version = "0.2.0", path = "../../rust-libretro-sys" }
proc-macro2 = "1.0.36"
quote = "1.0.15"
syn = { version = "1.0.86", features = [ "extra-traits", "full", "parsing" ] }
7 changes: 2 additions & 5 deletions rust-libretro/rust-libretro-proc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,11 +834,8 @@ pub fn context(args: TokenStream, input: TokenStream) -> TokenStream {
}

// Remove the `context` attribute
fun.attrs = fun
.attrs
.into_iter()
.filter(|attr| attr.path.segments.last().unwrap().ident != "context")
.collect();
fun.attrs
.retain(|attr| attr.path.segments.last().unwrap().ident != "context");

// Replace the function arguments
fun.sig.inputs = inputs;
Expand Down
14 changes: 7 additions & 7 deletions rust-libretro/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ impl AudioContext<'_> {
/// Only one of the audio callbacks must ever be used.
pub fn batch_audio_samples(&self, samples: &[i16]) {
if let Some(callback) = self.audio_sample_batch_callback {
let len = samples.len() as u64;
let len = samples.len();

unsafe {
(callback)(samples.as_ptr(), len / 2);
Expand Down Expand Up @@ -1165,7 +1165,7 @@ pub struct RunContext<'a> {
pub(crate) had_frame: &'a mut bool,
pub(crate) last_width: &'a mut u32,
pub(crate) last_height: &'a mut u32,
pub(crate) last_pitch: &'a mut u64,
pub(crate) last_pitch: &'a mut usize,

pub(crate) supports_bitmasks: bool,
}
Expand All @@ -1184,7 +1184,7 @@ impl<'a> From<&mut RunContext<'a>> for AudioContext<'a> {
}
}

impl<'a> RunContext<'_> {
impl RunContext<'_> {
#[inline(always)]
pub fn can_dupe(&self) -> bool {
self.can_dupe
Expand Down Expand Up @@ -1352,12 +1352,12 @@ impl<'a> RunContext<'_> {
// Thus we cannot pass the `FrameBuffer` to `Self::draw_frame` for example.
return Ok(Framebuffer {
data: fb.data as *mut u8,
data_len: fb.height as usize * fb.pitch as usize,
data_len: fb.height as usize * fb.pitch,
phantom: ::core::marker::PhantomData,

width: fb.width,
height: fb.height,
pitch: fb.pitch as usize,
pitch: fb.pitch,
format: fb.format.into(),
access_flags: MemoryAccess::from_bits_unchecked(fb.access_flags),
memory_flags: MemoryType::from_bits_unchecked(fb.memory_flags),
Expand Down Expand Up @@ -1405,7 +1405,7 @@ impl<'a> RunContext<'_> {
}

/// Draws a new frame if [`RunContext::video_refresh_callback`] has been set
pub fn draw_frame(&mut self, data: &[u8], width: u32, height: u32, pitch: u64) {
pub fn draw_frame(&mut self, data: &[u8], width: u32, height: u32, pitch: usize) {
if let Some(callback) = self.video_refresh_callback {
*self.had_frame = true;
*self.last_width = width;
Expand Down Expand Up @@ -1456,7 +1456,7 @@ impl<'a> RunContext<'_> {
}
}

pub fn draw_hardware_frame(&mut self, width: u32, height: u32, pitch: u64) {
pub fn draw_hardware_frame(&mut self, width: u32, height: u32, pitch: usize) {
if let Some(callback) = self.video_refresh_callback {
*self.had_frame = true;
*self.last_width = width;
Expand Down
6 changes: 3 additions & 3 deletions rust-libretro/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub trait Core: CoreOptions {
/// Between calls to [`Core::on_load_game`] and [`Core::on_unload_game`], the
/// returned size is never allowed to be larger than a previous returned
/// value, to ensure that the frontend can allocate a save state buffer once.
fn get_serialize_size(&mut self, _ctx: &mut GetSerializeSizeContext) -> size_t {
fn get_serialize_size(&mut self, _ctx: &mut GetSerializeSizeContext) -> usize {
// Tell the frontend that we don’t support serialization
0
}
Expand Down Expand Up @@ -111,7 +111,7 @@ pub trait Core: CoreOptions {
&mut self,
_game_type: std::os::raw::c_uint,
_info: *const retro_game_info,
_num_info: size_t,
_num_info: usize,
_ctx: &mut LoadGameSpecialContext,
) -> Result<(), Box<dyn std::error::Error>> {
Err("on_load_game_special is not implemented".into())
Expand Down Expand Up @@ -163,7 +163,7 @@ pub trait Core: CoreOptions {
&mut self,
_id: std::os::raw::c_uint,
_ctx: &mut GetMemorySizeContext,
) -> size_t {
) -> usize {
// Tell the frontend that we don’t support direct memory access
0
}
Expand Down
2 changes: 1 addition & 1 deletion rust-libretro/src/core_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub(crate) struct CoreWrapper {
pub(crate) had_frame: bool,
pub(crate) last_width: u32,
pub(crate) last_height: u32,
pub(crate) last_pitch: u64,
pub(crate) last_pitch: usize,

pub(crate) supports_bitmasks: bool,

Expand Down
18 changes: 18 additions & 0 deletions rust-libretro/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1892,3 +1892,21 @@ pub unsafe fn get_throttle_state(callback: retro_environment_t) -> Option<retro_
// struct retro_throttle_state *
get_unchecked(callback, RETRO_ENVIRONMENT_GET_THROTTLE_STATE).map(|(v, _)| v)
}

/// Tells the core about the context the frontend is asking for savestate.
// See [`retro_savestate_context`]
#[proc::context(GenericContext)]
#[proc::unstable(feature = "env-commands")]
pub unsafe fn get_savestate_context(
callback: retro_environment_t,
) -> Option<retro_savestate_context> {
// int *

if let Some((value, _)) =
get::<retro_savestate_context_REPR_TYPE>(callback, RETRO_ENVIRONMENT_GET_SAVESTATE_CONTEXT)
{
return retro_savestate_context::try_from(value).ok();
}

None
}
31 changes: 14 additions & 17 deletions rust-libretro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ forward!(
#[doc = "See also [`rust_libretro_sys::retro_serialize_size`]."],
wrapper,
retro_serialize_size,
get_serialize_size -> size_t,
get_serialize_size -> usize,
GenericContext::new(&wrapper.environment_callback, Arc::clone(&wrapper.interfaces))
);
forward!(
Expand Down Expand Up @@ -507,7 +507,7 @@ pub unsafe extern "C" fn retro_run() {
///
/// This could also be used by a frontend to implement rewind.
#[no_mangle]
pub unsafe extern "C" fn retro_serialize(data: *mut std::os::raw::c_void, size: size_t) -> bool {
pub unsafe extern "C" fn retro_serialize(data: *mut std::os::raw::c_void, size: usize) -> bool {
#[cfg(feature = "log")]
log::trace!("retro_serialize(data = {data:#?}, size = {size})");

Expand All @@ -525,7 +525,7 @@ pub unsafe extern "C" fn retro_serialize(data: *mut std::os::raw::c_void, size:
);

// Convert the given buffer into a proper slice
let slice = std::slice::from_raw_parts_mut(data as *mut u8, size as usize);
let slice = std::slice::from_raw_parts_mut(data as *mut u8, size);

return wrapper.core.on_serialize(slice, &mut ctx);
}
Expand All @@ -538,10 +538,7 @@ pub unsafe extern "C" fn retro_serialize(data: *mut std::os::raw::c_void, size:
///
/// This could also be used by a frontend to implement rewind.
#[no_mangle]
pub unsafe extern "C" fn retro_unserialize(
data: *const std::os::raw::c_void,
size: size_t,
) -> bool {
pub unsafe extern "C" fn retro_unserialize(data: *const std::os::raw::c_void, size: usize) -> bool {
#[cfg(feature = "log")]
log::trace!("retro_unserialize(data = {data:#?}, size = {size})");

Expand All @@ -559,7 +556,7 @@ pub unsafe extern "C" fn retro_unserialize(
);

// Convert the given buffer into a proper slice
let slice = std::slice::from_raw_parts_mut(data as *mut u8, size as usize);
let slice = std::slice::from_raw_parts_mut(data as *mut u8, size);

return wrapper.core.on_unserialize(slice, &mut ctx);
}
Expand Down Expand Up @@ -658,7 +655,7 @@ pub unsafe extern "C" fn retro_load_game(game: *const retro_game_info) -> bool {
pub unsafe extern "C" fn retro_load_game_special(
game_type: std::os::raw::c_uint,
info: *const retro_game_info,
num_info: size_t,
num_info: usize,
) -> bool {
#[cfg(feature = "log")]
log::trace!(
Expand Down Expand Up @@ -736,7 +733,7 @@ pub unsafe extern "C" fn retro_get_memory_data(
///
/// `id` is one of the `RETRO_MEMORY_*` constants.
#[no_mangle]
pub unsafe extern "C" fn retro_get_memory_size(id: std::os::raw::c_uint) -> size_t {
pub unsafe extern "C" fn retro_get_memory_size(id: std::os::raw::c_uint) -> usize {
#[cfg(feature = "log")]
log::trace!("retro_get_memory_size(id = {id})");

Expand Down Expand Up @@ -936,7 +933,7 @@ pub unsafe extern "C" fn retro_set_initial_image_callback(
pub unsafe extern "C" fn retro_get_image_path_callback(
index: ::std::os::raw::c_uint,
path: *mut ::std::os::raw::c_char,
len: size_t,
len: usize,
) -> bool {
#[cfg(feature = "log")]
log::trace!("retro_get_image_path_callback(index = {index}, path = {path:#?}, len = {len})");
Expand All @@ -945,7 +942,7 @@ pub unsafe extern "C" fn retro_get_image_path_callback(
match wrapper.core.on_get_image_path(index) {
Some(image_path) => {
let image_path = image_path.as_bytes();
let buf = std::slice::from_raw_parts_mut(path as *mut u8, len as usize);
let buf = std::slice::from_raw_parts_mut(path as *mut u8, len);
let len = image_path.len().min(buf.len());

buf[..len].copy_from_slice(&image_path[..len]);
Expand All @@ -963,7 +960,7 @@ pub unsafe extern "C" fn retro_get_image_path_callback(
pub unsafe extern "C" fn retro_get_image_label_callback(
index: ::std::os::raw::c_uint,
label: *mut ::std::os::raw::c_char,
len: size_t,
len: usize,
) -> bool {
#[cfg(feature = "log")]
log::trace!("retro_get_image_label_callback(index = {index}, label = {label:#?}, len = {len})");
Expand All @@ -972,7 +969,7 @@ pub unsafe extern "C" fn retro_get_image_label_callback(
match wrapper.core.on_get_image_label(index) {
Some(image_label) => {
let image_label = image_label.as_bytes();
let buf = std::slice::from_raw_parts_mut(label as *mut u8, len as usize);
let buf = std::slice::from_raw_parts_mut(label as *mut u8, len);
let len = image_label.len().min(buf.len());

buf[..len].copy_from_slice(&image_label[..len]);
Expand Down Expand Up @@ -1050,9 +1047,9 @@ pub unsafe extern "C" fn retro_camera_frame_raw_framebuffer_callback(
buffer: *const u32,
width: ::std::os::raw::c_uint,
height: ::std::os::raw::c_uint,
pitch: size_t,
pitch: usize,
) {
let buffer_size = height as usize * pitch as usize;
let buffer_size = height as usize * pitch;
let buffer = std::slice::from_raw_parts(buffer, buffer_size);

#[cfg(feature = "log")]
Expand All @@ -1061,7 +1058,7 @@ pub unsafe extern "C" fn retro_camera_frame_raw_framebuffer_callback(
if let Some(wrapper) = RETRO_INSTANCE.as_mut() {
return wrapper
.core
.on_camera_raw_framebuffer(buffer, width, height, pitch as usize);
.on_camera_raw_framebuffer(buffer, width, height, pitch);
}

panic!("retro_camera_frame_raw_framebuffer_callback: Core has not been initialized yet!");
Expand Down

0 comments on commit 2cf0599

Please sign in to comment.