gamercade_rs/api/
data.rs

1use super::{f32_to_option, i32_u32_to_option};
2use crate::raw;
3
4/// Returns the height of the screen, in pixels.
5pub fn height() -> usize {
6    unsafe { raw::height() as usize }
7}
8
9/// Returns the width of the screen, in pixels.
10pub fn width() -> usize {
11    unsafe { raw::width() as usize }
12}
13
14/// Returns the target frame rate, in frames per second.
15pub fn fps() -> usize {
16    unsafe { raw::fps() as usize }
17}
18
19/// Returns the time per frame. This is equal to 1.0 / fps.
20/// Also known as tick time or delta time.
21pub fn frame_time() -> f32 {
22    unsafe { raw::frame_time() }
23}
24
25/// Returns the total number of sprite sheets present in the ROM.
26pub fn sprite_sheet_count() -> u8 {
27    unsafe { raw::sprite_sheet_count() as u8 }
28}
29
30/// Returns the number of palettes sheets present in the ROM.
31pub fn palette_count() -> u8 {
32    unsafe { raw::palette_count() as u8 }
33}
34
35/// Returns the height of each image for the requested sprite sheet.
36/// If the index is invalid, will return None.
37pub fn sprite_height(sprite_sheet: usize) -> Option<u32> {
38    let val = unsafe { raw::sprite_height(sprite_sheet as i32) };
39    i32_u32_to_option(val)
40}
41
42/// Returns the width of each image for the requested sprite sheet.
43/// If the index is invalid, will return None.
44pub fn sprite_width(sprite_sheet: usize) -> Option<u32> {
45    let val = unsafe { raw::sprite_width(sprite_sheet as i32) };
46    i32_u32_to_option(val)
47}
48
49/// Returns the number of sprites for the requsted sprite sheet.
50/// If the index is invalid, will return None.
51pub fn sprite_count(sprite_sheet: usize) -> Option<u32> {
52    let val = unsafe { raw::sprite_count(sprite_sheet as i32) };
53    i32_u32_to_option(val)
54}
55
56/// Returns the length of the requested song in seconds.
57/// If the requested song is invalid, will return None.
58pub fn bgm_length_secs(bgm_index: usize) -> Option<f32> {
59    let val = unsafe { raw::bgm_length_secs(bgm_index as i32) };
60    f32_to_option(val)
61}
62
63/// Returns the length of the requested song in frames.
64/// Any fractional component will be rounded up.
65/// If the requested song is invalid, will return None.
66pub fn bgm_length_frames(bgm_index: usize) -> Option<u32> {
67    let val = unsafe { raw::bgm_length_frames(bgm_index as i32) };
68    i32_u32_to_option(val)
69}
70
71/// Returns the length of the requested sfx in seconds.
72/// If the requested sfx is invalid, will return None.
73pub fn sfx_length_secs(sfx_index: usize) -> Option<f32> {
74    let val = unsafe { raw::sfx_length_secs(sfx_index as i32) };
75    f32_to_option(val)
76}
77
78/// Returns the length of the requested sfx in frames.
79/// Any fractional component will be rounded up.
80/// If the requested sfx is invalid, will return None.
81pub fn sfx_length_frames(sfx_index: usize) -> Option<u32> {
82    let val = unsafe { raw::sfx_length_frames(sfx_index as i32) };
83    i32_u32_to_option(val)
84}