diff --git a/Cargo.lock b/Cargo.lock index 1078913c..d223913b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,15 +112,6 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" -[[package]] -name = "atomic-polyfill" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ff7eb3f316534d83a8a2c3d1674ace8a5a71198eba31e2e2b597833f699b28" -dependencies = [ - "critical-section", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -622,12 +613,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "critical-section" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" - [[package]] name = "crossbeam-channel" version = "0.5.8" @@ -793,9 +778,9 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "elliptic-curve" -version = "0.13.5" +version = "0.13.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "968405c8fdc9b3bf4df0a6638858cc0b52462836ab6b1c87377785dd09cf1c0b" +checksum = "d97ca172ae9dc9f9b779a6e3a65d308f2af74e5b8c921299075bdb4a0370e914" dependencies = [ "base16ct", "crypto-bigint", @@ -839,9 +824,9 @@ checksum = "76a5aa24577083f8190ad401e376b55887c7cd9083ae95d83ceec5d28ea78125" [[package]] name = "errno" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +checksum = "add4f07d43996f76ef320709726a556a9d4f965d9410d8d0271132d2f8293480" dependencies = [ "errno-dragonfly", "libc", @@ -1684,15 +1669,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "hash32" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" -dependencies = [ - "byteorder", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -1705,19 +1681,6 @@ version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" -[[package]] -name = "heapless" -version = "0.7.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db04bc24a18b9ea980628ecf00e6c0264f3c1426dac36c00cb49b6fbad8b0743" -dependencies = [ - "atomic-polyfill", - "hash32", - "rustc_version", - "spin", - "stable_deref_trait", -] - [[package]] name = "heck" version = "0.4.1" @@ -2147,9 +2110,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.3" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memmap2" @@ -2513,7 +2476,7 @@ checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "playdate" -version = "0.1.12" +version = "0.1.13" dependencies = [ "playdate-controls", "playdate-display", @@ -2589,7 +2552,7 @@ dependencies = [ [[package]] name = "playdate-display" -version = "0.3.3" +version = "0.3.4" dependencies = [ "playdate-sys", ] @@ -2604,7 +2567,7 @@ dependencies = [ [[package]] name = "playdate-graphics" -version = "0.3.8" +version = "0.3.9" dependencies = [ "playdate-color", "playdate-display", @@ -2643,7 +2606,7 @@ dependencies = [ [[package]] name = "playdate-sprite" -version = "0.2.4" +version = "0.2.5" dependencies = [ "playdate-display", "playdate-graphics", @@ -2653,16 +2616,16 @@ dependencies = [ [[package]] name = "playdate-sys" -version = "0.2.4" +version = "0.2.5" dependencies = [ - "heapless", + "arrayvec 0.7.4", "playdate-bindgen", "semver", ] [[package]] name = "playdate-system" -version = "0.3.5" +version = "0.3.6" dependencies = [ "playdate-sys", ] @@ -2914,15 +2877,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - [[package]] name = "rustfix" version = "0.6.1" @@ -3167,15 +3121,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "spki" version = "0.7.2" @@ -3186,12 +3131,6 @@ dependencies = [ "der", ] -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - [[package]] name = "static_assertions" version = "1.1.0" diff --git a/api/display/Cargo.toml b/api/display/Cargo.toml index 45040151..6b8856bb 100644 --- a/api/display/Cargo.toml +++ b/api/display/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-display" -version = "0.3.3" +version = "0.3.4" readme = "README.md" description = "High-level Display API built on-top of Playdate API" keywords = ["playdate", "sdk", "api", "gamedev"] diff --git a/api/display/src/lib.rs b/api/display/src/lib.rs index 25ac2a61..5c7c5406 100644 --- a/api/display/src/lib.rs +++ b/api/display/src/lib.rs @@ -172,6 +172,17 @@ impl Into for DisplayScale { fn into(self) -> c_uint { (self as u8).into() } } +impl core::fmt::Display for DisplayScale { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", *self as u8) } +} + +impl DisplayScale { + #[inline(always)] + pub const fn as_u8(self) -> u8 { self as u8 } + #[inline(always)] + pub const fn as_int(self) -> c_int { self as u8 as _ } +} + pub mod api { use core::ffi::c_float; diff --git a/api/gfx/Cargo.toml b/api/gfx/Cargo.toml index 4e7e345f..f5a9829a 100644 --- a/api/gfx/Cargo.toml +++ b/api/gfx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-graphics" -version = "0.3.8" +version = "0.3.9" readme = "README.md" description = "High-level graphics API built on-top of Playdate API" keywords = ["playdate", "sdk", "api", "gamedev"] diff --git a/api/gfx/examples/font.rs b/api/gfx/examples/font.rs index 5b04918b..f2650d9a 100644 --- a/api/gfx/examples/font.rs +++ b/api/gfx/examples/font.rs @@ -61,7 +61,7 @@ impl State { .unwrap_or_default(); let char = bitmap_ref.into_bitmap(); - let w = char.size().map(|(w, _h)| w).unwrap(); + let w = char.size().0; let x = OFFSET + i as i32 * w; let y = OFFSET + kern; diff --git a/api/gfx/src/bitmap/api.rs b/api/gfx/src/bitmap/api.rs index 9449d342..bf48cc11 100644 --- a/api/gfx/src/bitmap/api.rs +++ b/api/gfx/src/bitmap/api.rs @@ -8,9 +8,17 @@ use sys::ffi::LCDBitmapFlip; use sys::ffi::LCDRect; -#[derive(Debug, Clone, Copy, core::default::Default)] -pub struct Default; -impl Api for Default {} +/// Default graphics bitmap api end-point, ZST. +/// +/// All calls approximately costs ~3 derefs. +pub type Default = crate::api::Default; + +/// Cached graphics bitmap api end-point. +/// +/// Stores one reference, so size on stack is eq `usize`. +/// +/// All calls approximately costs ~1 deref. +pub type Cache = crate::api::Cache; /// End-point with methods about ops over bitmap. diff --git a/api/gfx/src/bitmap/bitmap.rs b/api/gfx/src/bitmap/bitmap.rs index cd084f44..f25ff987 100644 --- a/api/gfx/src/bitmap/bitmap.rs +++ b/api/gfx/src/bitmap/bitmap.rs @@ -252,7 +252,7 @@ impl Bitmap { /// /// Calls [`sys::ffi::playdate_graphics::getBitmapData`]. #[doc(alias = "sys::ffi::playdate_graphics::getBitmapData")] - pub fn size(&self) -> Result<(c_int, c_int), Error> { + pub fn size(&self) -> (c_int, c_int) { let mut width: c_int = 0; let mut height: c_int = 0; let mut row_bytes: c_int = 0; @@ -269,14 +269,14 @@ impl Bitmap { ) }; - Ok((width, height)) + (width, height) } /// Returns mutable borrow of bitmap-data by this bitmap. /// /// Calls [`sys::ffi::playdate_graphics::getBitmapData`]. #[doc(alias = "sys::ffi::playdate_graphics::getBitmapData")] - pub fn bitmap_data<'bitmap>(&'bitmap mut self) -> Result, Error> { + pub fn bitmap_data<'bitmap>(&'bitmap mut self) -> BitmapData<'bitmap> { let mut width: c_int = 0; let mut height: c_int = 0; let mut row_bytes: c_int = 0; @@ -313,12 +313,11 @@ impl Bitmap { }; let data = unsafe { core::slice::from_raw_parts_mut::(*boxed_data, len as usize) }; - - Ok(BitmapData { width, - height, - row_bytes, - mask, - data }) + BitmapData { width, + height, + row_bytes, + mask, + data } } @@ -772,3 +771,80 @@ impl Graphics { unsafe { f() }; } } + + +impl Graphics { + /// Draws `self` with its upper-left corner at location `x`, `y`, + /// using the given `flip` orientation. + /// + /// Equivalent to [`sys::ffi::playdate_graphics::drawBitmap`]. + #[doc(alias = "sys::ffi::playdate_graphics::drawBitmap")] + #[inline(always)] + pub fn draw(&self, bitmap: &impl AnyBitmap, x: c_int, y: c_int, flip: BitmapFlip) { + let f = self.0.draw_bitmap(); + unsafe { f(bitmap.as_raw(), x, y, flip) } + } + + /// Draws `self` with its upper-left corner at location `x`, `y` + /// __tiled inside a `width` by `height` rectangle__. + /// + /// Equivalent to [`sys::ffi::playdate_graphics::tileBitmap`]. + #[doc(alias = "sys::ffi::playdate_graphics::tileBitmap")] + #[inline(always)] + pub fn draw_tiled(&self, + bitmap: &impl AnyBitmap, + x: c_int, + y: c_int, + width: c_int, + height: c_int, + flip: BitmapFlip) { + let f = self.0.tile_bitmap(); + unsafe { f(bitmap.as_raw(), x, y, width, height, flip) } + } + + /// Draws the *bitmap* scaled to `x_scale` and `y_scale` + /// then rotated by `degrees` with its center as given by proportions `center_x` and `center_y` at `x`, `y`; + /// + /// that is: + /// * if `center_x` and `center_y` are both 0.5 the center of the image is at (`x`,`y`), + /// * if `center_x` and `center_y` are both 0 the top left corner of the image (before rotation) is at (`x`,`y`), etc. + /// + /// Equivalent to [`sys::ffi::playdate_graphics::drawRotatedBitmap`]. + #[doc(alias = "sys::ffi::playdate_graphics::drawRotatedBitmap")] + #[inline(always)] + pub fn draw_rotated(&self, + bitmap: &impl AnyBitmap, + x: c_int, + y: c_int, + degrees: c_float, + center_x: c_float, + center_y: c_float, + x_scale: c_float, + y_scale: c_float) { + let f = self.0.draw_rotated_bitmap(); + unsafe { + f( + bitmap.as_raw(), + x, + y, + degrees, + center_x, + center_y, + x_scale, + y_scale, + ) + } + } + + /// Draws this bitmap scaled to `x_scale` and `y_scale` with its upper-left corner at location `x`, `y`. + /// + /// Note that flip is not available when drawing scaled bitmaps but negative scale values will achieve the same effect. + /// + /// Equivalent to [`sys::ffi::playdate_graphics::drawScaledBitmap`]. + #[doc(alias = "sys::ffi::playdate_graphics::drawScaledBitmap")] + #[inline(always)] + pub fn draw_scaled(&self, bitmap: &impl AnyBitmap, x: c_int, y: c_int, x_scale: c_float, y_scale: c_float) { + let f = self.0.draw_scaled_bitmap(); + unsafe { f(bitmap.as_raw(), x, y, x_scale, y_scale) } + } +} diff --git a/api/gfx/src/bitmap/table.rs b/api/gfx/src/bitmap/table.rs index cd9aed46..77f6c091 100644 --- a/api/gfx/src/bitmap/table.rs +++ b/api/gfx/src/bitmap/table.rs @@ -160,9 +160,17 @@ pub mod api { use sys::ffi::LCDBitmapTable; - #[derive(Debug, Clone, Copy, core::default::Default)] - pub struct Default; - impl Api for Default {} + /// Default graphics bitmap table api end-point, ZST. + /// + /// All calls approximately costs ~3 derefs. + pub type Default = crate::api::Default; + + /// Cached graphics bitmap table api end-point. + /// + /// Stores one reference, so size on stack is eq `usize`. + /// + /// All calls approximately costs ~1 deref. + pub type Cache = crate::api::Cache; /// End-point with methods about ops over bitmap-table. diff --git a/api/gfx/src/text.rs b/api/gfx/src/text.rs index d03871be..48027744 100644 --- a/api/gfx/src/text.rs +++ b/api/gfx/src/text.rs @@ -536,6 +536,19 @@ pub mod api { use sys::ffi::PDStringEncoding; + /// Default graphics text api end-point, ZST. + /// + /// All calls approximately costs ~3 derefs. + pub type Default = crate::api::Default; + + /// Cached graphics text api end-point. + /// + /// Stores one reference, so size on stack is eq `usize`. + /// + /// All calls approximately costs ~1 deref. + pub type Cache = crate::api::Cache; + + /// End-point with methods about ops with text. pub trait Api { /// Equivalent to [`sys::ffi::playdate_graphics::drawText`] diff --git a/api/playdate/Cargo.toml b/api/playdate/Cargo.toml index 320237da..69524b6b 100644 --- a/api/playdate/Cargo.toml +++ b/api/playdate/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate" -version = "0.1.12" +version = "0.1.13" readme = "README.md" description = "High-level Playdate API" keywords = ["playdate", "sdk", "api", "gamedev"] diff --git a/api/playdate/examples/hello-world.rs b/api/playdate/examples/hello-world.rs index 4efa1e67..08bf4eff 100644 --- a/api/playdate/examples/hello-world.rs +++ b/api/playdate/examples/hello-world.rs @@ -72,7 +72,7 @@ impl State { // Load ferris the crab and draw let ferris = Bitmap::::load(IMG_PATH).expect("missed bitmap"); gfx::set_draw_mode(BitmapDrawMode::Inverted); - let (ferris_width, ferris_height) = ferris.size().expect("impossible"); + let (ferris_width, ferris_height) = ferris.size(); ferris.draw(BOX_WIDTH / 2 - ferris_width / 2, 0, BitmapFlip::Unflipped); // Load system font diff --git a/api/sprite/Cargo.toml b/api/sprite/Cargo.toml index 51cd8b5f..78f4fbe3 100644 --- a/api/sprite/Cargo.toml +++ b/api/sprite/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-sprite" -version = "0.2.4" +version = "0.2.5" readme = "README.md" description = "High-level sprite API built on-top of Playdate API" keywords = ["playdate", "sdk", "api", "gamedev"] diff --git a/api/sprite/src/callback/collision.rs b/api/sprite/src/callback/collision.rs index 36a88d01..8134b189 100644 --- a/api/sprite/src/callback/collision.rs +++ b/api/sprite/src/callback/collision.rs @@ -130,7 +130,7 @@ impl Handle } -pub(crate) mod l2 { +pub mod l2 { use core::ops::Deref; use core::marker::PhantomData; diff --git a/api/sprite/src/callback/draw.rs b/api/sprite/src/callback/draw.rs index 4d5e77f8..4bfd7169 100644 --- a/api/sprite/src/callback/draw.rs +++ b/api/sprite/src/callback/draw.rs @@ -12,9 +12,9 @@ use crate::api::{self, Api}; impl Sprite { /// Sets the draw function for the this sprite. /// - /// ⚠️ Caution: Using with [`Sprite::set_image`], - /// do not forget to set image __before__ setting draw function, - /// but not __after__. + /// ⚠️ Caution: + /// Do not forget to set [`bounds`](Sprite::set_bounds) __before__ setting draw function, + /// default zero bounds causes UB in the system. pub fn into_draw_handler>(self) -> Handle where T::Api: Default { Handle::new(self) @@ -130,7 +130,7 @@ impl Handle } -pub(crate) mod l2 { +pub mod l2 { use core::ops::Deref; use core::marker::PhantomData; @@ -153,9 +153,9 @@ pub(crate) mod l2 { { /// Sets the draw function for the this sprite. /// - /// ⚠️ Caution: Using with [`Sprite::set_image`], - /// Do not forget to set image __before__ setting draw function, - /// but not __after__. + /// ⚠️ Caution: + /// Do not forget to set [`bounds`](Sprite::set_bounds) __before__ setting draw function, + /// default zero bounds causes UB in the system. pub fn into_draw_handler>(self) -> Handle, Self, T> where T::Api: Default { Handle::new(self) @@ -168,9 +168,9 @@ pub(crate) mod l2 { { /// Sets the draw function for the this sprite. /// - /// ⚠️ Caution: Using with [`Sprite::set_image`], - /// Do not forget to set image __before__ setting draw function, - /// but not __after__. + /// ⚠️ Caution: + /// Do not forget to set [`bounds`](Sprite::set_bounds) __before__ setting draw function, + /// default zero bounds causes UB in the system. pub fn into_draw_handler>(self) -> Handle, Self, T> where T::Api: Default { Handle::new(self) @@ -185,9 +185,9 @@ pub(crate) mod l2 { { /// Sets the draw function for the this sprite. /// - /// ⚠️ Caution: Using with [`Sprite::set_image`], - /// Do not forget to set image __before__ setting draw function, - /// but not __after__. + /// ⚠️ Caution: + /// Do not forget to set [`bounds`](Sprite::set_bounds) __before__ setting draw function, + /// default zero bounds causes UB in the system. pub fn into_draw_handler>(self) -> Handle, Self, T> where T::Api: Default { Handle::new(self) @@ -202,9 +202,9 @@ pub(crate) mod l2 { { /// Sets the draw function for the this sprite. /// - /// ⚠️ Caution: Using with [`Sprite::set_image`], - /// Do not forget to set image __before__ setting draw function, - /// but not __after__. + /// ⚠️ Caution: + /// Do not forget to set [`bounds`](Sprite::set_bounds) __before__ setting draw function, + /// default zero bounds causes UB in the system. pub fn into_draw_handler>(self) -> Handle, Self, T> where T::Api: Default { Handle::new(self) diff --git a/api/sprite/src/callback/update.rs b/api/sprite/src/callback/update.rs index e2a6fb2d..6892b936 100644 --- a/api/sprite/src/callback/update.rs +++ b/api/sprite/src/callback/update.rs @@ -120,7 +120,7 @@ impl Handle } -pub(crate) mod l2 { +pub mod l2 { use core::ops::Deref; use core::marker::PhantomData; diff --git a/api/sprite/src/sprite.rs b/api/sprite/src/sprite.rs index 7d291711..a3870985 100644 --- a/api/sprite/src/sprite.rs +++ b/api/sprite/src/sprite.rs @@ -632,7 +632,7 @@ impl Sprite { #[doc(alias = "sys::ffi::playdate_sprite::setCenter")] #[inline(always)] #[cfg(feature = "sdk_2_1")] - fn set_center(&self, x: c_float, y: c_float) { + pub fn set_center(&self, x: c_float, y: c_float) { let f = self.1.set_center(); unsafe { f(self.0, x, y) } } @@ -643,7 +643,7 @@ impl Sprite { #[doc(alias = "sys::ffi::playdate_sprite::getCenter")] #[inline(always)] #[cfg(feature = "sdk_2_1")] - fn center(&self) -> (c_float, c_float) { + pub fn center(&self) -> (c_float, c_float) { let (mut x, mut y) = (0.0, 0.0); let f = self.1.get_center(); unsafe { f(self.0, &mut x, &mut y) }; diff --git a/api/sys/Cargo.toml b/api/sys/Cargo.toml index 4c6374c8..322b8679 100644 --- a/api/sys/Cargo.toml +++ b/api/sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-sys" -version = "0.2.4" +version = "0.2.5" build = "src/build.rs" readme = "README.md" description = "Low-level Playdate API bindings" @@ -23,7 +23,7 @@ default = ["bindgen-runtime", "bindings-derive-debug"] lang-items = ["allocator", "panic-handler", "eh-personality"] # lang-items allocator = [] # global allocator -panic-handler = [] # global panic handler +panic-handler = ["arrayvec"] # global panic handler eh-personality = [] # eh_personality for sim-targets, dummy empty no-op entry-point = [] # simple minimal proxy entry point @@ -53,7 +53,7 @@ bindings-derive-constparamty = [] # derive `ConstParamTy` [dependencies] -heapless = "0.7" +arrayvec = { version = "0.7.4", default-features = false, optional = true } [build-dependencies] @@ -98,12 +98,13 @@ cargo-args = [ name = "hello-world" crate-type = ["dylib", "staticlib"] path = "examples/hello-world.rs" +required-features = ["lang-items"] [[example]] name = "handler" crate-type = ["dylib", "staticlib"] path = "examples/handler.rs" -required-features = ["entry-point"] +required-features = ["lang-items", "entry-point"] [package.metadata.playdate] bundle-id = "rs.playdate.sys" diff --git a/api/sys/src/sys/panic.rs b/api/sys/src/sys/panic.rs index 687d0152..98f458dd 100644 --- a/api/sys/src/sys/panic.rs +++ b/api/sys/src/sys/panic.rs @@ -3,13 +3,13 @@ use core::panic::PanicInfo; use core::fmt::Write; -use heapless::String; +use arrayvec::ArrayString; use super::proc::error; #[panic_handler] fn panic(#[allow(unused)] panic_info: &PanicInfo) -> ! { - let mut output = String::<1024>::new(); + let mut output = ArrayString::<1024>::new(); let payload = if let Some(payload) = panic_info.payload().downcast_ref::<&str>() { payload } else { diff --git a/api/system/Cargo.toml b/api/system/Cargo.toml index 6a7f4400..28e29235 100644 --- a/api/system/Cargo.toml +++ b/api/system/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-system" -version = "0.3.5" +version = "0.3.6" readme = "README.md" description = "High-level System API built on-top of Playdate API" keywords = ["playdate", "sdk", "api", "gamedev"] diff --git a/api/system/src/lib.rs b/api/system/src/lib.rs index 57bacaa7..75975266 100644 --- a/api/system/src/lib.rs +++ b/api/system/src/lib.rs @@ -77,9 +77,14 @@ impl System { #[doc(alias = "sys::ffi::playdate_sys::getCurrentTimeMilliseconds")] #[inline(always)] pub fn current_time_milliseconds(&self) -> Duration { + Duration::from_millis(self.current_time_milliseconds_raw().into()) + } + + /// Equivalent to [`sys::ffi::playdate_sys::getCurrentTimeMilliseconds`] + #[doc(alias = "sys::ffi::playdate_sys::getCurrentTimeMilliseconds")] + pub fn current_time_milliseconds_raw(&self) -> c_uint { let f = self.0.get_current_time_milliseconds(); - let t = unsafe { f() }; - Duration::from_millis(t.into()) + unsafe { f() } } /// Equivalent to [`sys::ffi::playdate_sys::getSecondsSinceEpoch`]