Skip to main content

App

Struct App 

Source
pub struct App<G: GameData> { /* private fields */ }
Expand description

A game run one frame at a time by a backend’s loop.

Implementations§

Source§

impl<G: GameData> App<G>

Source

pub fn new(start: Start<G>) -> Self

A game that starts as start says: the card, then the load.

Source

pub fn running(game: Game<G>) -> Self

game, already loaded and running: for a test, which has no look to paint with (Show::Game’s look is None). What its context logged before is taken, at frame 0.

Source

pub fn set_system_hook(&mut self, hook: SystemHook<G>)

Gives the game hook for the system’s events, in place of any it had.

Source

pub fn frame( &mut self, platform: &mut impl Platform, now: Millis, ) -> FrameOutcome

Runs one frame at now on the backend’s clock: the system’s events, then the input, the game’s update and its fixed steps, the audio, and the frame to present. The time since the last frame is what the screens see and the steps are made of; the first frame, and the first after a load or a SystemEvent::Resume, count none.

Source

pub fn set_pacing(&mut self, pacing: Pacing)

Takes the backend’s report of how it paces the frames: the frame cap it applied, with the serial the cap came with on the last frame it was given (Frame::frame_cap_serial), and what it measured. A backend that paces calls this between frames, and the next frame that runs the game hands it over before the update (Game::set_pacing), so a request for a cap is confirmed. A later report before that frame replaces it.

Source

pub fn present_again(&mut self, platform: &mut impl Platform)

Presents the last frame again without running one: no input is read, nothing steps and no time passes for the game. For a backend whose display wants a picture on a frame the game isn’t due (the web under a frame cap, where the browser sets the rate and clears the picture each frame). Before anything is shown, shows nothing.

Source

pub fn frame_after( &mut self, platform: &mut impl Platform, seconds: f32, ) -> FrameOutcome

Runs one frame seconds after the last on a clock of the driver’s own, as frame does otherwise: for a driver whose frames a clock in whole milliseconds can’t give (the test Harness’s, exactly 1/60 s), or a backend whose system says how long the last frame took. A driver uses this or frame, never both. A recording stops here, since a record’s time is whole milliseconds, and says so (SessionRecord::truncated).

Source

pub fn record(&mut self) -> bool

Turns recording on (ADR-0072): false once a frame has run, since a record must start at the first frame to play back. While recording, a backend hands the game nothing around the Platform (game_mut), except through session_mut for what it puts into the Setup.

Source

pub fn session(&self) -> Option<&SessionRecord>

The record so far, if this run is recorded.

Source

pub fn session_mut(&mut self) -> Option<&mut SessionRecord>

The record so far, for what a backend puts into the game’s Setup and App can’t see (SessionRecord::voice_manifest).

Source

pub fn take_session(&mut self) -> Option<SessionRecord>

Ends the recording, handing back the record.

Source

pub fn take_session_save(&mut self) -> bool

Whether a debug tool asked in the last frames to save the session (Ctx::ask_session_save): true once for each ask. The backend writes session, which goes on recording.

Source

pub fn frame_hash(&self) -> Option<StateHash>

The last frame’s hash: of what happened in it, never its picture. None unless frames are hashed: while recording, or with hash_frames on.

Source

pub fn hash_frames(&mut self, on: bool)

Hashes each frame from now on (frame_hash), or stops: what a playback compares.

Source

pub fn game(&self) -> Option<&Game<G>>

The game, once it has loaded.

Source

pub fn game_mut(&mut self) -> Option<&mut Game<G>>

The game, once it has loaded, to change from outside a frame (a test, a platform’s own menu: Game::act).

Source

pub fn into_game(self) -> Option<Game<G>>

Ends the run, handing back the game if it loaded.

Source

pub fn crash_record(&self) -> Option<String>

The game’s record of its play (Start::crash_record), for a crash report: None while it loads, after a failed load, or if it has no record.

Source

pub fn is_loading(&self) -> bool

Whether the game hasn’t loaded yet.

Source

pub fn errors(&self) -> Option<&str>

Why the game couldn’t start, if its load failed.

Source

pub fn is_suspended(&self) -> bool

Whether the system has suspended the game.

Source

pub fn ticks(&self) -> u32

The fixed simulation steps the last frame handed the game (Game::set_ticks): 0 in a frame that didn’t run it (loading, suspended, quit).

Source

pub fn is_focused(&self) -> bool

Whether the game’s window has the player’s attention (until the system says otherwise, it has).

Source

pub fn is_paused(&self) -> bool

Whether the game is paused because its window has no focus and its GameSettings::BACKGROUND pauses it: it runs, hasn’t quit, and isn’t updated.

Source

pub fn has_quit(&self) -> bool

Whether the game has quit.

Source

pub fn frame_number(&self) -> u32

The frames run: 0 before the first, then one more for each frame or frame_after. The frame the log’s lines carry.

Source

pub fn set_log_filter(&mut self, filter: LogFilter)

Which lines the log keeps from now on: LogLevel::Info and more serious until set.

Source

pub fn log(&self) -> &LogRing

The log: the last LOG_LINES lines, oldest first, and how many were dropped.

Source

pub fn take_new_log(&mut self) -> Vec<LogLine>

The log’s lines since the last call, oldest first, for the backend’s sinks: each line is given once.

Source

pub fn perf(&self) -> &PerfRing

The last PERF_FRAMES frames’ records, oldest first, and how many were dropped (ADR-0046). A frame is measured in a build with debug tools, on a platform with a clock (Platform::clock), while the game’s Ctx::debug_tools is on; a loading, suspended, failed or quit frame makes no record.

Source

pub fn take_new_perf(&mut self) -> Vec<FrameRecord>

The records since the last call, oldest first, for the backend’s sinks: each record is given once.

Source

pub fn load_us(&self) -> Option<u32>

How long the game’s load took, in microseconds, if it was timed: in a build with debug tools, on a platform with a clock.

Source

pub fn heap_snapshot( &self, platform: &mut impl Platform, ) -> Option<HeapSnapshot>

What holds the heap now, by memory tag (ADR-0046 §6): platform’s snapshot (Platform::heap_snapshot) stamped with frame_number. Only while debug tools are on: in a build with them, and the running game’s Ctx::debug_tools on; None otherwise, or where the platform takes none.

Source

pub fn audio(&self) -> &[AudioRequest<G::Voice>]

The audio the screens asked for in the last frame, in order, as they asked (the device got it as SoundRequests).

Source

pub fn music(&self) -> &[MusicCommand]

The music commands of the last frame, in order.

Auto Trait Implementations§

§

impl<G> !RefUnwindSafe for App<G>

§

impl<G> !Send for App<G>

§

impl<G> !Sync for App<G>

§

impl<G> !UnwindSafe for App<G>

§

impl<G> Freeze for App<G>

§

impl<G> Unpin for App<G>
where <G as GameData>::Voice: Unpin,

§

impl<G> UnsafeUnpin for App<G>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.