pub trait Sdk:
Clone
+ Debug
+ 'static {
type Sample: Copy + PartialEq + Debug;
type SamplePlayer: Copy + Debug;
type FilePlayer: Copy + Debug;
Show 42 methods
// Required methods
fn millis(&self) -> u32;
fn clock_us() -> u64;
fn heap() -> Option<HeapCounts>;
fn buttons(&self) -> (u32, u32);
fn crank_change(&self) -> f32;
fn crank_docked(&self) -> bool;
fn add_menu_item(&self, title: &str, slot: u8) -> bool;
fn set_refresh_rate(&self, fps: u16);
fn with_frame(&self, draw: impl FnOnce(&mut Frame));
fn mark_rows(&self, first: i32, last: i32);
fn draw_text(&self, text: &str, white: bool);
fn log(&self, line: &str);
fn is_file(&self, path: &str) -> bool;
fn read_data(&self, path: &str) -> Result<Vec<u8>, String>;
fn read_bundled(&self, path: &str) -> Result<Vec<u8>, String>;
fn write_data(&self, path: &str, bytes: &[u8]) -> Result<(), String>;
fn rename_data(&self, from: &str, to: &str) -> Result<(), String>;
fn remove_data(&self, path: &str) -> Result<(), String>;
fn data_names(&self, folder: &str) -> Result<Vec<String>, String>;
fn make_data_folder(&self, folder: &str) -> Result<(), String>;
fn sample_load(&self, path: &str) -> Option<Self::Sample>;
fn sample_length(&self, sample: Self::Sample) -> f32;
fn sample_player_new(&self) -> Option<Self::SamplePlayer>;
fn sample_player_play(
&self,
player: Self::SamplePlayer,
sample: Self::Sample,
volume: f32,
looped: bool,
rate: f32,
);
fn sample_player_set_volume(&self, player: Self::SamplePlayer, volume: f32);
fn sample_player_stop(&self, player: Self::SamplePlayer);
fn sample_player_is_playing(&self, player: Self::SamplePlayer) -> bool;
fn sample_player_set_paused(&self, player: Self::SamplePlayer, paused: bool);
fn file_open(&self, path: &str) -> Option<Self::FilePlayer>;
fn file_play(&self, player: Self::FilePlayer, looped: bool) -> bool;
fn file_set_volume(&self, player: Self::FilePlayer, volume: f32);
fn file_set_rate(&self, player: Self::FilePlayer, rate: f32);
fn file_pause(&self, player: Self::FilePlayer);
fn file_stop(&self, player: Self::FilePlayer);
fn file_rewind(&self, player: Self::FilePlayer);
fn file_is_playing(&self, player: Self::FilePlayer) -> bool;
fn file_length(&self, player: Self::FilePlayer) -> f32;
fn file_close(&self, player: Self::FilePlayer);
// Provided methods
fn sample_from_data(
&self,
samples: &[i16],
rate: u32,
stereo: bool,
) -> Option<Self::Sample> { ... }
fn sample_free(&self, sample: Self::Sample) { ... }
fn file_did_underrun(&self) -> bool { ... }
fn stack_used(&self) -> Option<usize> { ... }
}Expand description
The SDK’s calls. A clone is the same SDK: the storage keeps its own, as a game’s context outlives nothing the backend holds.
Required Associated Types§
Sourcetype SamplePlayer: Copy + Debug
type SamplePlayer: Copy + Debug
A sample player (SamplePlayer).
Sourcetype FilePlayer: Copy + Debug
type FilePlayer: Copy + Debug
A file player (FilePlayer).
Required Methods§
Sourcefn millis(&self) -> u32
fn millis(&self) -> u32
getCurrentTimeMilliseconds: milliseconds from a fixed start, which
stands still while the device sleeps and wraps at u32::MAX.
Sourcefn clock_us() -> u64
fn clock_us() -> u64
The high-resolution timer in whole microseconds from its start
(getElapsedTime), never going back; never reset by the backend.
Sourcefn heap() -> Option<HeapCounts>
fn heap() -> Option<HeapCounts>
The debug build’s heap counter, read: None in a release build.
getButtonState: the bits held now, and those pressed since the
last call.
Sourcefn crank_change(&self) -> f32
fn crank_change(&self) -> f32
getCrankChange: degrees turned since the last call, clockwise
positive.
Sourcefn crank_docked(&self) -> bool
fn crank_docked(&self) -> bool
isCrankDocked.
addMenuItem: an item named title that gives slot back when
chosen; false if the SDK refused it.
Sourcefn set_refresh_rate(&self, fps: u16)
fn set_refresh_rate(&self, fps: u16)
display->setRefreshRate.
Sourcefn with_frame(&self, draw: impl FnOnce(&mut Frame))
fn with_frame(&self, draw: impl FnOnce(&mut Frame))
Runs draw on the frame buffer (getFrame).
Sourcefn mark_rows(&self, first: i32, last: i32)
fn mark_rows(&self, first: i32, last: i32)
markUpdatedRows: rows first to last of the frame buffer changed.
Sourcefn draw_text(&self, text: &str, white: bool)
fn draw_text(&self, text: &str, white: bool)
Clears the screen and draws text, centred and wrapped, in the
system’s font: black on white if white, else white on black.
Sourcefn read_data(&self, path: &str) -> Result<Vec<u8>, String>
fn read_data(&self, path: &str) -> Result<Vec<u8>, String>
The whole of file path in the game’s data folder.
Sourcefn read_bundled(&self, path: &str) -> Result<Vec<u8>, String>
fn read_bundled(&self, path: &str) -> Result<Vec<u8>, String>
The whole of file path in the game’s .pdx.
Sourcefn write_data(&self, path: &str, bytes: &[u8]) -> Result<(), String>
fn write_data(&self, path: &str, bytes: &[u8]) -> Result<(), String>
Replaces file path in the game’s data folder with bytes, flushed.
Sourcefn rename_data(&self, from: &str, to: &str) -> Result<(), String>
fn rename_data(&self, from: &str, to: &str) -> Result<(), String>
Moves file from to to in the game’s data folder.
Sourcefn remove_data(&self, path: &str) -> Result<(), String>
fn remove_data(&self, path: &str) -> Result<(), String>
Deletes file path in the game’s data folder.
Sourcefn data_names(&self, folder: &str) -> Result<Vec<String>, String>
fn data_names(&self, folder: &str) -> Result<Vec<String>, String>
The names in folder of the game’s data folder ("": the data
folder itself); a folder’s has a / after it.
Sourcefn make_data_folder(&self, folder: &str) -> Result<(), String>
fn make_data_folder(&self, folder: &str) -> Result<(), String>
Makes folder in the game’s data folder; an error if it is there.
Sourcefn sample_load(&self, path: &str) -> Option<Self::Sample>
fn sample_load(&self, path: &str) -> Option<Self::Sample>
sample->load: the sound at path in the .pdx, without its
extension; None if there is none.
Sourcefn sample_length(&self, sample: Self::Sample) -> f32
fn sample_length(&self, sample: Self::Sample) -> f32
sample->getLength, in seconds.
Sourcefn sample_player_new(&self) -> Option<Self::SamplePlayer>
fn sample_player_new(&self) -> Option<Self::SamplePlayer>
sampleplayer->newPlayer.
Sourcefn sample_player_play(
&self,
player: Self::SamplePlayer,
sample: Self::Sample,
volume: f32,
looped: bool,
rate: f32,
)
fn sample_player_play( &self, player: Self::SamplePlayer, sample: Self::Sample, volume: f32, looped: bool, rate: f32, )
Plays sample from its start on player, stopping what it played, at
volume, once or looped, at rate (1 as recorded).
Sourcefn sample_player_set_volume(&self, player: Self::SamplePlayer, volume: f32)
fn sample_player_set_volume(&self, player: Self::SamplePlayer, volume: f32)
sampleplayer->setVolume, the same on both sides.
Sourcefn sample_player_stop(&self, player: Self::SamplePlayer)
fn sample_player_stop(&self, player: Self::SamplePlayer)
sampleplayer->stop.
Sourcefn sample_player_is_playing(&self, player: Self::SamplePlayer) -> bool
fn sample_player_is_playing(&self, player: Self::SamplePlayer) -> bool
sampleplayer->isPlaying.
Sourcefn sample_player_set_paused(&self, player: Self::SamplePlayer, paused: bool)
fn sample_player_set_paused(&self, player: Self::SamplePlayer, paused: bool)
sampleplayer->setPaused.
Sourcefn file_open(&self, path: &str) -> Option<Self::FilePlayer>
fn file_open(&self, path: &str) -> Option<Self::FilePlayer>
A new file player on the file at path in the .pdx, without its
extension; None if there is no such file.
Sourcefn file_play(&self, player: Self::FilePlayer, looped: bool) -> bool
fn file_play(&self, player: Self::FilePlayer, looped: bool) -> bool
Starts player, or goes on from where its pause left it, once or
looped: false if it could not (fileplayer->play).
Sourcefn file_set_volume(&self, player: Self::FilePlayer, volume: f32)
fn file_set_volume(&self, player: Self::FilePlayer, volume: f32)
fileplayer->setVolume, the same on both sides.
Sourcefn file_set_rate(&self, player: Self::FilePlayer, rate: f32)
fn file_set_rate(&self, player: Self::FilePlayer, rate: f32)
fileplayer->setRate.
Sourcefn file_pause(&self, player: Self::FilePlayer)
fn file_pause(&self, player: Self::FilePlayer)
fileplayer->pause.
Sourcefn file_stop(&self, player: Self::FilePlayer)
fn file_stop(&self, player: Self::FilePlayer)
fileplayer->stop.
Sourcefn file_rewind(&self, player: Self::FilePlayer)
fn file_rewind(&self, player: Self::FilePlayer)
fileplayer->setOffset to the file’s start.
Sourcefn file_is_playing(&self, player: Self::FilePlayer) -> bool
fn file_is_playing(&self, player: Self::FilePlayer) -> bool
fileplayer->isPlaying.
Sourcefn file_length(&self, player: Self::FilePlayer) -> f32
fn file_length(&self, player: Self::FilePlayer) -> f32
fileplayer->getLength, in seconds.
Sourcefn file_close(&self, player: Self::FilePlayer)
fn file_close(&self, player: Self::FilePlayer)
Stops player and frees it: it isn’t used again.
Provided Methods§
Sourcefn sample_from_data(
&self,
samples: &[i16],
rate: u32,
stereo: bool,
) -> Option<Self::Sample>
fn sample_from_data( &self, samples: &[i16], rate: u32, stereo: bool, ) -> Option<Self::Sample>
sample->newSampleFromData: a sound of samples, 16 bits each,
interleaved, at rate a second, mono or stereo. The SDK keeps a copy
of its own. None if it made none (no memory, or no samples). Without
it, none.
Sourcefn sample_free(&self, sample: Self::Sample)
fn sample_free(&self, sample: Self::Sample)
sample->freeSample, with its copy of the samples: a sample
sample_from_data made, which no sample
player plays any more. Without it, nothing.
Sourcefn file_did_underrun(&self) -> bool
fn file_did_underrun(&self) -> bool
Whether a file player open now ran out of data to play
(fileplayer->didUnderrun): the music stuttered. Without it, never.
Sourcefn stack_used(&self) -> Option<usize>
fn stack_used(&self) -> Option<usize>
The bytes of the game’s own stack it has ever used
(stack_high_water): None where they
aren’t measured, as on the Simulator.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".