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>
impl<G: GameData> App<G>
Sourcepub fn running(game: Game<G>) -> Self
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.
Sourcepub fn set_system_hook(&mut self, hook: SystemHook<G>)
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.
Sourcepub fn frame(
&mut self,
platform: &mut impl Platform,
now: Millis,
) -> FrameOutcome
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.
Sourcepub fn set_pacing(&mut self, pacing: Pacing)
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.
Sourcepub fn present_again(&mut self, platform: &mut impl Platform)
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.
Sourcepub fn frame_after(
&mut self,
platform: &mut impl Platform,
seconds: f32,
) -> FrameOutcome
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).
Sourcepub fn record(&mut self) -> bool
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.
Sourcepub fn session(&self) -> Option<&SessionRecord>
pub fn session(&self) -> Option<&SessionRecord>
The record so far, if this run is recorded.
Sourcepub fn session_mut(&mut self) -> Option<&mut SessionRecord>
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).
Sourcepub fn take_session(&mut self) -> Option<SessionRecord>
pub fn take_session(&mut self) -> Option<SessionRecord>
Ends the recording, handing back the record.
Sourcepub fn take_session_save(&mut self) -> bool
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.
Sourcepub fn frame_hash(&self) -> Option<StateHash>
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.
Sourcepub fn hash_frames(&mut self, on: bool)
pub fn hash_frames(&mut self, on: bool)
Hashes each frame from now on (frame_hash), or
stops: what a playback compares.
Sourcepub fn game_mut(&mut self) -> Option<&mut Game<G>>
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).
Sourcepub fn crash_record(&self) -> Option<String>
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.
Sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
Whether the game hasn’t loaded yet.
Sourcepub fn is_suspended(&self) -> bool
pub fn is_suspended(&self) -> bool
Whether the system has suspended the game.
Sourcepub fn ticks(&self) -> u32
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).
Sourcepub fn is_focused(&self) -> bool
pub fn is_focused(&self) -> bool
Whether the game’s window has the player’s attention (until the system says otherwise, it has).
Sourcepub fn is_paused(&self) -> bool
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.
Sourcepub fn frame_number(&self) -> u32
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.
Sourcepub fn set_log_filter(&mut self, filter: LogFilter)
pub fn set_log_filter(&mut self, filter: LogFilter)
Which lines the log keeps from now on: LogLevel::Info and more
serious until set.
Sourcepub fn log(&self) -> &LogRing
pub fn log(&self) -> &LogRing
The log: the last LOG_LINES lines, oldest first, and how many
were dropped.
Sourcepub fn take_new_log(&mut self) -> Vec<LogLine>
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.
Sourcepub fn perf(&self) -> &PerfRing
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.
Sourcepub fn take_new_perf(&mut self) -> Vec<FrameRecord>
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.
Sourcepub fn load_us(&self) -> Option<u32>
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.
Sourcepub fn heap_snapshot(
&self,
platform: &mut impl Platform,
) -> Option<HeapSnapshot>
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.
Sourcepub fn audio(&self) -> &[AudioRequest<G::Voice>]
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).
Sourcepub fn music(&self) -> &[MusicCommand]
pub fn music(&self) -> &[MusicCommand]
The music commands of the last frame, in order.