Skip to main content

Sdk

Trait Sdk 

Source
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§

Source

type Sample: Copy + PartialEq + Debug

A sound the SDK holds in memory (AudioSample).

Source

type SamplePlayer: Copy + Debug

A sample player (SamplePlayer).

Source

type FilePlayer: Copy + Debug

A file player (FilePlayer).

Required Methods§

Source

fn millis(&self) -> u32

getCurrentTimeMilliseconds: milliseconds from a fixed start, which stands still while the device sleeps and wraps at u32::MAX.

Source

fn clock_us() -> u64

The high-resolution timer in whole microseconds from its start (getElapsedTime), never going back; never reset by the backend.

Source

fn heap() -> Option<HeapCounts>

The debug build’s heap counter, read: None in a release build.

Source

fn buttons(&self) -> (u32, u32)

getButtonState: the bits held now, and those pressed since the last call.

Source

fn crank_change(&self) -> f32

getCrankChange: degrees turned since the last call, clockwise positive.

Source

fn crank_docked(&self) -> bool

isCrankDocked.

Source

fn add_menu_item(&self, title: &str, slot: u8) -> bool

addMenuItem: an item named title that gives slot back when chosen; false if the SDK refused it.

Source

fn set_refresh_rate(&self, fps: u16)

display->setRefreshRate.

Source

fn with_frame(&self, draw: impl FnOnce(&mut Frame))

Runs draw on the frame buffer (getFrame).

Source

fn mark_rows(&self, first: i32, last: i32)

markUpdatedRows: rows first to last of the frame buffer changed.

Source

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.

Source

fn log(&self, line: &str)

logToConsole: one line.

Source

fn is_file(&self, path: &str) -> bool

Whether path in the game’s data folder is a file.

Source

fn read_data(&self, path: &str) -> Result<Vec<u8>, String>

The whole of file path in the game’s data folder.

Source

fn read_bundled(&self, path: &str) -> Result<Vec<u8>, String>

The whole of file path in the game’s .pdx.

Source

fn write_data(&self, path: &str, bytes: &[u8]) -> Result<(), String>

Replaces file path in the game’s data folder with bytes, flushed.

Source

fn rename_data(&self, from: &str, to: &str) -> Result<(), String>

Moves file from to to in the game’s data folder.

Source

fn remove_data(&self, path: &str) -> Result<(), String>

Deletes file path in the game’s data folder.

Source

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.

Source

fn make_data_folder(&self, folder: &str) -> Result<(), String>

Makes folder in the game’s data folder; an error if it is there.

Source

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.

Source

fn sample_length(&self, sample: Self::Sample) -> f32

sample->getLength, in seconds.

Source

fn sample_player_new(&self) -> Option<Self::SamplePlayer>

sampleplayer->newPlayer.

Source

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).

Source

fn sample_player_set_volume(&self, player: Self::SamplePlayer, volume: f32)

sampleplayer->setVolume, the same on both sides.

Source

fn sample_player_stop(&self, player: Self::SamplePlayer)

sampleplayer->stop.

Source

fn sample_player_is_playing(&self, player: Self::SamplePlayer) -> bool

sampleplayer->isPlaying.

Source

fn sample_player_set_paused(&self, player: Self::SamplePlayer, paused: bool)

sampleplayer->setPaused.

Source

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.

Source

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).

Source

fn file_set_volume(&self, player: Self::FilePlayer, volume: f32)

fileplayer->setVolume, the same on both sides.

Source

fn file_set_rate(&self, player: Self::FilePlayer, rate: f32)

fileplayer->setRate.

Source

fn file_pause(&self, player: Self::FilePlayer)

fileplayer->pause.

Source

fn file_stop(&self, player: Self::FilePlayer)

fileplayer->stop.

Source

fn file_rewind(&self, player: Self::FilePlayer)

fileplayer->setOffset to the file’s start.

Source

fn file_is_playing(&self, player: Self::FilePlayer) -> bool

fileplayer->isPlaying.

Source

fn file_length(&self, player: Self::FilePlayer) -> f32

fileplayer->getLength, in seconds.

Source

fn file_close(&self, player: Self::FilePlayer)

Stops player and frees it: it isn’t used again.

Provided Methods§

Source

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.

Source

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.

Source

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.

Source

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".

Implementors§