PlatformAPI reference
Interface IPlatformHost
Namespace: MicroEngine.Platform
Assembly: MicroEngine.Platform.dll
Guide: The platform host
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.
public interface IPlatformHost : IDisposableImplements
Remarks
The platform contract, which every host follows:
- One thread. The loop calls every member on the game's thread. A host that learns of an event on another thread (a phone's lifecycle callbacks) holds it until the next [PumpEvents](/docs/api/microengine.platform.iplatformhost/#MicroEngine_Platform_IPlatformHost_PumpEvents_MicroEngine_Platform_IEngineEventSink_).
- Events are delivered only by [PumpEvents](/docs/api/microengine.platform.iplatformhost/#MicroEngine_Platform_IPlatformHost_PumpEvents_MicroEngine_Platform_IEngineEventSink_), which the loop calls once at the start of every frame, in the order they happened. Nothing is delivered between pumps.
- Lifecycle order. [Suspending](/docs/api/microengine.platform.iengineeventsink/#MicroEngine_Platform_IEngineEventSink_Suspending) and [Resumed](/docs/api/microengine.platform.iengineeventsink/#MicroEngine_Platform_IEngineEventSink_Resumed)
alternate, starting with
Suspending: a host never sends two in a row, and neverResumedwithout aSuspendingbefore it. A trip to the background and back that happened between two pumps is delivered as both, in that order, in one pump. [FocusChanged](/docs/api/microengine.platform.iengineeventsink/#MicroEngine_Platform_IEngineEventSink_FocusChanged_System_Boolean_) is sent only when the focus changes. [QuitRequested](/docs/api/microengine.platform.iengineeventsink/#MicroEngine_Platform_IEngineEventSink_QuitRequested) is sent once per request; the loop decides (handlers may veto it), and a later request is sent again. - Resizes. When the main surface's pixel size changes, the same pump raises [Resized](/docs/api/microengine.platform.isurface/#MicroEngine_Platform_ISurface_Resized) and delivers [Resized](/docs/api/microengine.platform.iengineeventsink/#MicroEngine_Platform_IEngineEventSink_Resized_MicroEngine_Kernel_SurfaceResized_) with the new [PixelSize](/docs/api/microengine.platform.isurface/#MicroEngine_Platform_ISurface_PixelSize); a size that did not change is not delivered.
- Clock. [Clock](/docs/api/microengine.platform.iplatformhost/#MicroEngine_Platform_IPlatformHost_Clock) is monotonic and nothing else: it is never derived from frames, steps or the update rate. The loop owns time.
- Capabilities. Optional features (changing the display mode, diagnostics, a touch screen, display pacing, a precise timer) are found with [TryGetCapability``1](/docs/api/microengine.platform.iplatformhost/#MicroEngine_Platform_IPlatformHost_TryGetCapability__1___0__), never by casting the host. A host's capabilities do not change while it runs (a capability's values may). A host that wraps another forwards the query.
- Page-driven hosts. A host whose frames are driven by a page (a browser's animation frames) reports [CanBlock](/docs/api/microengine.platform.iplatformhost/#MicroEngine_Platform_IPlatformHost_CanBlock) false and then never blocks: no waits, sleeps or precise delays in any member; the page paces the frames. It reads the surface size from the canvas after start, never from the size requested at creation. It opens the audio output inside the user gesture that starts the game.
- No time coupling. Nothing a host does depends on how the loop advances time: display pacing, device start-up and audio output are explicit options of the host's creation.
Properties
CanBlock
Whether the host may block its thread to pace frames (a desktop window, a phone, headless runs). False for page-driven hosts (a browser), which must never block: the loop then skips a frame that comes early instead of waiting for it.
bool CanBlock { get; }Property Value
Clock
The host’s monotonic clock.
IMonotonicClock Clock { get; }Property Value
MainSurface
The surface the game presents to (its window or canvas), or null when the host has none.
ISurface? MainSurface { get; }Property Value
Methods
PumpEvents(IEngineEventSink)
Processes the system’s pending events (window, keyboard, gamepad, touch) and delivers those the engine handles
to sink, in the order they happened. Called by the loop once at the start of every frame.
bool PumpEvents(IEngineEventSink sink)Parameters
sink IEngineEventSink
Returns
True when the game can run a frame now; false while it is suspended (between Suspending and Resumed).
TryGetCapability<T>(out T?)
The optional feature of type T this host offers, if it offers one.
bool TryGetCapability<T>(out T? capability) where T : classParameters
capability T?
Returns
Type Parameters
T