Skip to content

PlatformAPI reference

Namespace MicroEngine.Platform

The platform contracts: the host (clock, event pump, main surface, capabilities, whether it may block), the surface, display pacing and precise waits, storage for saves and content sources.

Guide: The platform host

Classes

BrowserStorage

Save slots in the page’s localStorage under “microengine/<game>/<slot>”: the default save medium in browsers. The browser’s file system is in memory and vanishes on reload; localStorage writes are synchronous and survive it. The page registers the “microengine” JavaScript module (its storage.get, storage.set and storage.remove functions) before the game starts; the browser host’s page does.

FolderContentSource

Content files in a folder on disk. Names must match the files’ letter case exactly on every system: “Hero.png” for “hero.png” works on Windows and macOS but not on Linux, Android or in browsers, so it fails everywhere, naming the real spelling. Paths that leave the folder (.., another drive) are refused.

HostSurface

An ISurface for hosts: it reads its size, density and state from the host’s window when asked, and Pump reports a size change the way the platform contract requires (Resized and the sink’s Resized, once per change).

Structs

AudioFormat

The PCM format a sink plays: interleaved 32-bit float samples, Channels per frame, at SampleRate frames per second.

Interfaces

IAudioSink

A PCM audio output, version 1 of the contract: the engine’s one mixer renders, the sink plays. The sink chooses the thread that renders (Schedule).

IContentSource

Where a game’s content files come from: a folder next to the executable, a phone’s unpacked package, later an archive or a browser’s fetch. Paths are relative to the source with ‘/’ separators and match the stored name’s letter case exactly on every system.

IDisplayPacing

The refresh rate a host’s frames are paced to, when a display paces them (VSync). A capability (TryGetCapability``1): a host without it never paces frames to a display.

IEngineEventSink

Where a host delivers what happens to the game from outside its simulation (PumpEvents). The engine’s loop implements it and raises the matching IEngineLifecycle events.

IMonotonicClock

A monotonic clock in seconds: it never goes back and does not depend on frames, steps or rates.

IPlatformHost

The platform a game runs on, as the loop sees it: a monotonic clock, the events of the window and the system, the main surface, optional features found by type and whether the host may block its thread.

IPreciseDelay

A precise way to wait, used by the loop to hold a frame back until the frame limit allows it. A capability (TryGetCapability``1) of hosts that can block (CanBlock); without it the loop sleeps and then spins for the last milliseconds.

IStorage

Where a game keeps what it saves: named slots of text that are written whole (files on desktops and phones, the page’s localStorage in browsers, a cloud service). Failures surface as IOException or UnauthorizedAccessException.

ISurface

A surface a host produces and a graphics device presents to: a window, a browser canvas, a phone’s screen. This is the graphics contract’s surface (version 1); only backends read NativeWindow.

Enums

AudioSinkSchedule

Who calls a sink’s AudioRender.

Delegates

AudioRender

Fills all of buffer (buffer.Length / Channels frames of the sink’s AudioFormat). Called by one thread at a time; which thread depends on Schedule. It never blocks, allocates, takes a lock the main thread holds, or throws.