Skip to content

KernelAPI reference

Class HeadlessPlatform

Namespace: MicroEngine.Core
Assembly: MicroEngine.dll
Guide: Testing your game

A windowless platform: no devices, and a renderer that counts calls (or, with Rasterize, also records them and draws them with the CPU reference rasterizer). Used by automated tests and CI to play whole games through scripts. Its surface has the canvas’s size; tests drive its events by hand (Resize, Focus, Suspend, Resume, RequestQuit), which the next event pump delivers in order. Its run preset (Preset) is deterministic time: a stated default of this testing composition that a run or a game overrides. Nothing the platform does depends on the time mode.

C#
public sealed class HeadlessPlatform : IPlatform, IPlatformHost, IDisposable, IScreenView, IViewCapture

Inheritance

object ← HeadlessPlatform

Implements

IPlatform, IPlatformHost, IDisposable, IScreenView, IViewCapture

Constructors

HeadlessPlatform(int, int)

Creates a headless platform whose renderer reports a width × height canvas.

C#
public HeadlessPlatform(int width = 320, int height = 180)

Parameters

width int

height int

Properties

Audio

The device the request supplied (Audio), otherwise SilentAudio.

C#
public IAudioDevice Audio { get; }

Property Value

IAudioDevice

CanBlock

True: tests and CI may block.

C#
public bool CanBlock { get; }

Property Value

bool

Clipboard

The clipboard (the IClipboard capability): tests put text on it or read what was copied.

C#
public MemoryClipboard Clipboard { get; }

Property Value

MemoryClipboard

Clock

A monotonic clock in seconds since the platform was created. The loop owns time: in deterministic time it never reads this clock to decide how many steps a frame runs.

C#
public IMonotonicClock Clock { get; }

Property Value

IMonotonicClock

CloseRequested

Set it to true to ask the game to quit at the next event pump, as if the window’s close button was pressed; the request is delivered once while it stays true. Setting it back to false allows a later request.

C#
public bool CloseRequested { get; set; }

Property Value

bool

Devices

The platform’s input backend (also its IInputBackend, IKeyLabels, IGamepadRumble and ITextInputControl capabilities): tests send device events with it, which the next frame routes like a real backend’s.

C#
public HeadlessInputBackend Devices { get; }

Property Value

HeadlessInputBackend

FullscreenToggles

How many times the game asked to switch between a window and full screen (there is no window to switch).

C#
public int FullscreenToggles { get; }

Property Value

int

Graphics

A HeadlessGraphicsDevice: textures have a size but no pixels, unless Rasterize is on.

C#
public IGraphicsDevice Graphics { get; }

Property Value

IGraphicsDevice

Input

Keys, read together with the request’s extra sources (ExtraInput) when there are any.

C#
public IInputSource Input { get; }

Property Value

IInputSource

Keys

The input tests set by hand (keys, gamepad, pointer), read every update as one polled device.

C#
public HeadlessInput Keys { get; }

Property Value

HeadlessInput

Letterbox

The colour around the world in a capture of a frame that drew a UI (CaptureScreen); there is no window to paint.

C#
public Color Letterbox { get; set; }

Property Value

Color

MainSurface

The surface, of the canvas’s size until Resize changes it; it has no native window.

C#
public ISurface MainSurface { get; }

Property Value

ISurface

PixelDensity

Pixels per logical unit of the surface (PixelDensity): 1 by default, as a headless run has no screen. Set it when creating the platform to stand for a high-density screen: with the presentation’s UiScale unset, the UI scale follows it.

C#
public float PixelDensity { get; init; }

Property Value

float

Exceptions

ArgumentOutOfRangeException

The value is not a positive finite number.

Presentation

How the canvas is placed in the surface for the UI view’s mapping (WorldFrame): the game’s presentation when the platform was made for its settings, else PixelArt.

C#
public Presentation Presentation { get; init; }

Property Value

Presentation

Preset

The run defaults this testing composition states (RunPreset, offered as a capability): Testing by default, so a game run on it through GameRunner, GameLoop, GameSession or InitializeForTest advances one fixed step per frame with no option. The run’s TimeMode and the game’s Configure win over it; Preset = new RunPreset() when creating the platform makes runs that choose nothing real-time. The platform behaves the same either way.

C#
public RunPreset Preset { get; init; }

Property Value

RunPreset

Profile

The headless platform as a catalog entry (–platform headless, –headless).

C#
public static PlatformProfile Profile { get; }

Property Value

PlatformProfile

Rasterize

When true, textures keep their pixels and the renderer records each frame’s draws (Commands) and draws them on Frame with the CPU reference rasterizer, following the engine’s rendering rules; SaveScreenshot then writes that frame as a PNG (at scale 1). False by default: the renderer only counts. Set it when creating the platform.

C#
public bool Rasterize { get; init; }

Property Value

bool

Renderer

The renderer, typed so tests can read its counters.

C#
public HeadlessRenderer Renderer { get; }

Property Value

HeadlessRenderer

Screenshots

Paths of the screenshots requested, in order; a file is written only when Rasterize is on.

C#
public List<string> Screenshots { get; }

Property Value

List<string>

SilentAudio

The silent audio device, typed so tests can read Played.

C#
public SilentAudioDevice SilentAudio { get; }

Property Value

SilentAudioDevice

Suspended

Whether Suspend sent the platform to the background (until Resume).

C#
public bool Suspended { get; }

Property Value

bool

Touch

The same screen as TouchScreen.

C#
public ITouchScreen Touch { get; }

Property Value

ITouchScreen

TouchScreen

A touch screen tests can touch; by default 4× the canvas, not touch-first, no safe-area insets. Also the host’s ITouchScreen capability.

C#
public HeadlessTouchScreen TouchScreen { get; }

Property Value

HeadlessTouchScreen

UiRenderer

The UI view’s renderer of the current frame (IScreenView): the surface’s size in UI units (pixels divided by the UI scale, UiScaleFor of PixelDensity). It counts draw calls; with Rasterize on it also draws them, and a frame that drew a UI is captured with it composited over the world (IViewCapture), each UI unit repeated over the window pixels it covers.

C#
public HeadlessRenderer UiRenderer { get; }

Property Value

HeadlessRenderer

Methods

BeginFrame()

Starts a frame and returns the renderer that draws into the virtual canvas.

C#
public IRenderer BeginFrame()

Returns

IRenderer

Dispose()

Disposes the audio device the request supplied, if any; nothing else holds resources.

C#
public void Dispose()

EndFrame()

Finishes the frame and presents it.

C#
public void EndFrame()

Focus(bool)

Gives (true) or takes (false) the input focus; the next pump delivers it when the focus changes.

C#
public void Focus(bool focused)

Parameters

focused bool

For(GameSettings)

A headless platform with the virtual size of settings.

C#
public static HeadlessPlatform For(GameSettings settings)

Parameters

settings GameSettings

Returns

HeadlessPlatform

For(GameSettings, bool)

A headless platform with the virtual size of settings, rasterizing when rasterize is true (see Rasterize).

C#
public static HeadlessPlatform For(GameSettings settings, bool rasterize)

Parameters

settings GameSettings

rasterize bool

Returns

HeadlessPlatform

For(PlatformRequest)

A headless platform for request: the virtual size of its settings, the audio device it supplies (Audio) and its extra input sources read with Keys.

C#
public static HeadlessPlatform For(PlatformRequest request)

Parameters

request PlatformRequest

Returns

HeadlessPlatform

PumpEvents(IEngineEventSink)

Delivers the events the test hooks queued, in order; false while suspended.

C#
public bool PumpEvents(IEngineEventSink sink)

Parameters

sink IEngineEventSink

Returns

bool

RequestQuit()

Asks the game to quit, as a window’s close button does; the next pump delivers the request.

C#
public void RequestQuit()

Resize(int, int)

Changes the surface’s size; the next pump delivers the resize (once, when the size changed).

C#
public void Resize(int width, int height)

Parameters

width int

height int

Resume()

Brings the platform back; the next pump delivers Resumed after a Suspending.

C#
public void Resume()

SaveScreenshot(string)

Records path in Screenshots; with Rasterize on, also writes what the player would see there as an opaque PNG at scale 1 (CaptureScreen): the canvas, or, for a frame that drew a UI, the surface with the UI over the world.

C#
public void SaveScreenshot(string path)

Parameters

path string

Suspend()

Sends the platform to the background, as a phone does; the next pump delivers Suspending.

C#
public void Suspend()

ToggleFullscreen()

Counts the request in FullscreenToggles: there is no window to switch.

C#
public void ToggleFullscreen()

TryGetCapability<T>(out T?)

The optional feature of type T this host offers, if it offers one.

C#
public bool TryGetCapability<T>(out T? capability) where T : class

Parameters

capability T?

Returns

bool

Type Parameters

T