pub struct HeadlessPlatform { /* private fields */ }Expand description
A backend with no devices, for tests and tools.
Implementations§
Source§impl HeadlessPlatform
impl HeadlessPlatform
Sourcepub const DISPLAY: DisplayInfo
pub const DISPLAY: DisplayInfo
The display headless frames are said to be shown on, unless set.
Sourcepub fn new() -> Self
pub fn new() -> Self
A backend with an empty memory storage, no input waiting and no system keyboard.
Sourcepub fn from_session(record: &SessionRecord) -> Self
pub fn from_session(record: &SessionRecord) -> Self
A backend ready to play record (Playback):
the display and the facts it recorded, and a memory storage holding
its store (writes stay in memory). Its music and its system keyboard
are the record’s from the first push_frame.
Sourcepub fn push_frame(&mut self, frame: &FrameRecord)
pub fn push_frame(&mut self, frame: &FrameRecord)
Queues one frame of a session record: its system events, its input, and what the sound device and the system keyboard answer in it.
Sourcepub fn end_session(&mut self)
pub fn end_session(&mut self)
The session record has played: the music and the system keyboard are this backend’s own again.
Sourcepub fn with_display(self, display: DisplayInfo) -> Self
pub fn with_display(self, display: DisplayInfo) -> Self
The same backend on display.
Sourcepub fn with_storage(self, storage: Box<dyn Storage>) -> Self
pub fn with_storage(self, storage: Box<dyn Storage>) -> Self
The same backend handing the game storage (a test’s earlier run).
Sourcepub fn with_facts(self, facts: PlatformFacts) -> Self
pub fn with_facts(self, facts: PlatformFacts) -> Self
The same backend saying the game runs where facts say (the
desktop target’s until called): a target’s, read from its
profile with PlatformFacts::from_profile.
Sourcepub fn with_keyboard(self, keyboard: ScriptedKeyboard) -> Self
pub fn with_keyboard(self, keyboard: ScriptedKeyboard) -> Self
The same backend with a system keyboard of its own.
Sourcepub fn with_clock(self, clock: PerfClock) -> Self
pub fn with_clock(self, clock: PerfClock) -> Self
The same backend giving clock to measure frames with
(Platform::clock): a fake one (PerfClock::fake) makes a
test’s records the same on every run.
Sourcepub fn set_clock(&mut self, clock: Option<PerfClock>)
pub fn set_clock(&mut self, clock: Option<PerfClock>)
Gives clock to measure frames with from now on, or none. App
asks for it on its first frame only.
Sourcepub fn with_fake_memory(self) -> Self
pub fn with_fake_memory(self) -> Self
The same backend reading a fake heap (Platform::memory) that
moves by fixed amounts, so a test’s records are the same on every
run: with n the frames it has presented, live bytes 1,048,576 +
16,384 × (n mod 30), the peak the most of those so far, and n
mod 7 allocations.
It takes fake heap snapshots too (Platform::heap_snapshot),
whose rows add up to those live bytes: Asset/image 49,152 bytes
in 3 blocks; Phase/load 524,288 in 40; Phase/update 16,384 ×
(n mod 30) in n mod 30, left out before the first frame; and
Other/other 475,136 in 12. Each row’s peak is the most of its
live bytes so far, and its bytes ever allocated equal its peak.
Sourcepub fn set_memory(&mut self, memory: Option<fn() -> HeapCounts>)
pub fn set_memory(&mut self, memory: Option<fn() -> HeapCounts>)
Reads the heap with memory from now on (a real counter’s
reading), or reads none; the fake memory is dropped either way.
Sourcepub fn set_heap_snapshots(&mut self, snapshot: Option<fn() -> HeapSnapshot>)
pub fn set_heap_snapshots(&mut self, snapshot: Option<fn() -> HeapSnapshot>)
Takes heap snapshots with snapshot from now on (a real counter’s),
or takes none; the fake memory’s snapshots come first.
Sourcepub fn set_present_hook(&mut self, hook: Option<PresentHook>)
pub fn set_present_hook(&mut self, hook: Option<PresentHook>)
Runs hook on each frame presented from now on, after the backend
keeps it, or runs none (None).
Sourcepub fn has_memory(&self) -> bool
pub fn has_memory(&self) -> bool
Whether it reads the heap: a fake, or a counter set.
Sourcepub fn memory_calls(&self) -> u32
pub fn memory_calls(&self) -> u32
How many times App asked for the memory (Platform::memory).
Sourcepub fn with_scopes(self, scopes: MemoryScopes) -> Self
pub fn with_scopes(self, scopes: MemoryScopes) -> Self
The same backend giving scopes as its memory tags
(Platform::memory_scopes): a test’s fake ones, which note what
is entered.
Sourcepub fn set_scopes(&mut self, scopes: Option<MemoryScopes>)
pub fn set_scopes(&mut self, scopes: Option<MemoryScopes>)
Gives scopes as its memory tags from now on, or none. App asks
for them on its first frame only.
Sourcepub fn push_input(&mut self, events: &[RawInputEvent])
pub fn push_input(&mut self, events: &[RawInputEvent])
Queues events as the input of one poll, after those already
queued.
Sourcepub fn push_system(&mut self, event: SystemEvent)
pub fn push_system(&mut self, event: SystemEvent)
Queues event for the next poll of the system’s events.
Sourcepub fn change_file(&mut self, layer: Layer, path: &str, bytes: Vec<u8>)
pub fn change_file(&mut self, layer: Layer, path: &str, bytes: Vec<u8>)
Queues a change of the file at path in layer (one handed in at
run time) for the next time App asks what changed
(Platform::changed_files), as a file changing on disk does: then
it has bytes, and its path is told.
Sourcepub fn changed_asks(&self) -> u32
pub fn changed_asks(&self) -> u32
How many times App asked what changed
(Platform::changed_files).
Sourcepub fn reload_errors(&self) -> &[String]
pub fn reload_errors(&self) -> &[String]
The hot reload errors the last frame presented asked to show
(Frame::reload_errors).
Sourcepub fn last_frame(&self) -> Option<&Presented>
pub fn last_frame(&self) -> Option<&Presented>
The last frame presented.
Sourcepub fn frame_cap(&self) -> Option<(FrameCap, u32)>
pub fn frame_cap(&self) -> Option<(FrameCap, u32)>
The frame cap the last frame presented asked for, and its serial: the headless backend doesn’t pace, and reports nothing.
Sourcepub fn speaker_mut(&mut self) -> &mut Speaker
pub fn speaker_mut(&mut self) -> &mut Speaker
The sound device, to set how the music loads.
Sourcepub fn keyboard(&self) -> Option<&ScriptedKeyboard>
pub fn keyboard(&self) -> Option<&ScriptedKeyboard>
The system keyboard, if it has one.
Trait Implementations§
Source§impl Debug for HeadlessPlatform
impl Debug for HeadlessPlatform
Source§impl Default for HeadlessPlatform
impl Default for HeadlessPlatform
Source§impl Platform for HeadlessPlatform
impl Platform for HeadlessPlatform
Source§fn display(&self) -> DisplayInfo
fn display(&self) -> DisplayInfo
Source§fn present(&mut self, frame: &Frame<'_>)
fn present(&mut self, frame: &Frame<'_>)
frame. Called once per frame the game isn’t suspended,
after its input, audio and update; the backend shows it as soon
as it can and keeps it on the screen until the next.Source§fn poll_input(&mut self, out: &mut Vec<RawInputEvent>)
fn poll_input(&mut self, out: &mut Vec<RawInputEvent>)
out, in the order they happened: releases before presses within
one poll of a device, as RawInputEvent::from_pads gives them.Source§fn system_events(&mut self, out: &mut Vec<SystemEvent>)
fn system_events(&mut self, out: &mut Vec<SystemEvent>)
out, in order.Source§fn storage(&mut self) -> Box<dyn Storage>
fn storage(&mut self) -> Box<dyn Storage>
App calls it once, as the game loads, and the game’s
context keeps it (screens save through it).Source§fn audio(&mut self) -> &mut dyn Audio
fn audio(&mut self) -> &mut dyn Audio
Source§fn text_input(&mut self) -> Option<&mut dyn TextInput>
fn text_input(&mut self) -> Option<&mut dyn TextInput>
None where the player types on keys,
which come through poll_input.Source§fn facts(&self) -> PlatformFacts
fn facts(&self) -> PlatformFacts
PlatformFacts): the target’s id, whether
the game may quit, whether its window goes full screen and back,
and the keyboard, pointer and touch screen the device has. Read
from the target’s profile, or from what the backend reads of the
system; constant for a run. App asks once, as the game loads, and
the game’s context keeps them (Ctx::platform). Read moreSource§fn clock(&self) -> Option<PerfClock>
fn clock(&self) -> Option<PerfClock>
App takes it once, on its first frame, and only
with DEBUG_TOOLS on. None (the
default) for a backend without one: nothing is measured.Source§fn memory_scopes(&self) -> Option<MemoryScopes>
fn memory_scopes(&self) -> Option<MemoryScopes>
App
takes them with the clock (clock), once, with
DEBUG_TOOLS on, and moves them into the
game’s context when it runs. None (the default) for a backend
whose counter has no tags. A backend with them also tags each
asset decode when it starts, before the game’s load
(shuyi_assets::format::watch_decodes).Source§fn memory(&mut self) -> Option<MemoryReading>
fn memory(&mut self) -> Option<MemoryReading>
App asks once a frame, at the end of a frame it keeps a record of
(debug tools on, with a clock), and puts the heap’s counts in the
record. None (the default) for a backend that doesn’t count:
records have no heap counts.Source§fn heap_snapshot(&mut self) -> Option<HeapSnapshot>
fn heap_snapshot(&mut self) -> Option<HeapSnapshot>
frame left 0 for
App::heap_snapshot to stamp. Taking
one allocates the rows, so it is asked for now and then (a tool, a
trace every 600 frames), never every frame. None (the default)
for a backend whose counter has no tags.Source§fn changed_files(&mut self, out: &mut Vec<String>)
fn changed_files(&mut self, out: &mut Vec<String>)
out, in a build with debug tools (ADR-0071): the
backend has already put their new bytes in their layers
(Layer::replace). App asks
once a frame while the game runs, only with
Ctx::debug_tools on. By default it
adds nothing: a device with no files to watch.