Skip to main content

HeadlessPlatform

Struct HeadlessPlatform 

Source
pub struct HeadlessPlatform { /* private fields */ }
Expand description

A backend with no devices, for tests and tools.

Implementations§

Source§

impl HeadlessPlatform

Source

pub const DISPLAY: DisplayInfo

The display headless frames are said to be shown on, unless set.

Source

pub fn new() -> Self

A backend with an empty memory storage, no input waiting and no system keyboard.

Source

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.

Source

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.

Source

pub fn end_session(&mut self)

The session record has played: the music and the system keyboard are this backend’s own again.

Source

pub fn with_display(self, display: DisplayInfo) -> Self

The same backend on display.

Source

pub fn with_storage(self, storage: Box<dyn Storage>) -> Self

The same backend handing the game storage (a test’s earlier run).

Source

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.

Source

pub fn with_keyboard(self, keyboard: ScriptedKeyboard) -> Self

The same backend with a system keyboard of its own.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn has_memory(&self) -> bool

Whether it reads the heap: a fake, or a counter set.

Source

pub fn memory_calls(&self) -> u32

How many times App asked for the memory (Platform::memory).

Source

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.

Source

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.

Source

pub fn push_input(&mut self, events: &[RawInputEvent])

Queues events as the input of one poll, after those already queued.

Source

pub fn push_system(&mut self, event: SystemEvent)

Queues event for the next poll of the system’s events.

Source

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.

Source

pub fn changed_asks(&self) -> u32

How many times App asked what changed (Platform::changed_files).

Source

pub fn reload_errors(&self) -> &[String]

The hot reload errors the last frame presented asked to show (Frame::reload_errors).

Source

pub fn presented(&self) -> u32

How many frames were presented.

Source

pub fn last_frame(&self) -> Option<&Presented>

The last frame presented.

Source

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.

Source

pub fn speaker(&self) -> &Speaker

The sound device.

Source

pub fn speaker_mut(&mut self) -> &mut Speaker

The sound device, to set how the music loads.

Source

pub fn keyboard(&self) -> Option<&ScriptedKeyboard>

The system keyboard, if it has one.

Trait Implementations§

Source§

impl Debug for HeadlessPlatform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HeadlessPlatform

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Platform for HeadlessPlatform

Source§

fn display(&self) -> DisplayInfo

The display, as it is now (a window may be resized between frames).
Source§

fn present(&mut self, frame: &Frame<'_>)

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

Adds the keyboard and controller events since the last call to 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>)

Adds the system’s events since the last call to out, in order.
Source§

fn storage(&mut self) -> Box<dyn Storage>

Hands over the game’s storage: its saves, settings and key bindings, by key. 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

The sound device: it plays each frame’s sounds, music and voices and says what music is sounding.
Source§

fn text_input(&mut self) -> Option<&mut dyn TextInput>

The system’s own keyboard for text (a console’s, Steam’s on-screen one), if the device has one; None where the player types on keys, which come through poll_input.
Source§

fn facts(&self) -> PlatformFacts

Where the game runs (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 more
Source§

fn clock(&self) -> Option<PerfClock>

A clock in whole microseconds, to measure frames with in debug builds (ADR-0046): 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>

The memory tags of the backend’s heap counter, in debug builds (ADR-0046 §6): plain functions over its tags, so what the game allocates counts by the frame’s phase and the game’s spans. 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>

The device’s memory now, in debug builds (ADR-0046): the heap’s live bytes, their peak and the allocations since the last call. 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>

What holds the heap now, by memory tag, in debug builds (ADR-0046 §6): its live bytes and each tag’s counts, its 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>)

Adds the paths in the bundle of the files that changed since the last call to 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.

Auto Trait Implementations§

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.