KernelAPI reference
Class GameSession
Namespace: MicroEngine.Core
Assembly: MicroEngine.dll
Guide: Game lifecycle and time
Runs one game at a time for hosts that drive frames themselves and outlive a run, such as a browser page: each Start builds a fresh game and platform, Tick runs one frame, and the end of a run (quit, error, Stop) shuts the game down and releases the platform, so the host can show its own screen and start again without reloading.
public sealed class GameSessionInheritance
Remarks
A session made from a composition (#ctor, the browser host’s) decides every run with the launcher model all hosts share (GameHost): a run with a script is in deterministic time with seed 1 exactly as on desktop and phones, so its captures are reproducible.
Constructors
GameSession(Func<Game>, Func<Game, IPlatform>)
A session that builds each run’s game and platform with the two functions given.
public GameSession(Func<Game> createGame, Func<Game, IPlatform> createPlatform)Parameters
createPlatform Func<Game, IPlatform>
Exceptions
An argument is null.
GameSession(Func<LaunchRequest, GameHost>)
A session whose every run is composed by compose for that run’s launch (the game’s
Configure entry point with the host’s defaults), then decided by the shared launcher model.
public GameSession(Func<LaunchRequest, GameHost> compose)Parameters
compose Func<LaunchRequest, GameHost>
Exceptions
compose is null.
Properties
Frames
Frames rendered by the current or last run.
public long Frames { get; }Property Value
Game
The game of the current or last run.
public Game? Game { get; }Property Value
Game?
Host
The composition of the current or last run of a composed session; null otherwise.
public GameHost? Host { get; }Property Value
IsRunning
Whether a run is in progress.
public bool IsRunning { get; }Property Value
Platform
The platform of the current run; null between runs.
public IPlatform? Platform { get; }Property Value
Result
How the last run ended; null while a run is in progress or before the first one.
public RunResult? Result { get; }Property Value
Methods
Start(RunOptions?)
Builds and initializes a new game with options as they are (a session made from two functions).
False when that failed; the error is in Result.
public bool Start(RunOptions? options = null)Parameters
options RunOptions?
Returns
Exceptions
A run is in progress, or the session was made from a composition (use Start).
Start(LaunchRequest, Func<RunOptions, RunOptions>?)
Composes and starts a new run for request: its script, captures, seed and time mode follow the
launcher model (CreateRunOptions), its platform the composition’s catalog and request.
False when that failed; the error is in Result.
public bool Start(LaunchRequest request, Func<RunOptions, RunOptions>? change = null)Parameters
request LaunchRequest
The launch.
change Func<RunOptions, RunOptions>?
Changes the run’s options before the run starts (a phone host’s first-frame callback), or null.
Returns
Exceptions
The request’s script is invalid (nothing was started).
A run is in progress, or the session was made from two functions.
Stop()
Ends a running game (for example when the page is closing). Does nothing otherwise.
public void Stop()Tick()
Runs one frame. Returns false once the run has ended (see Result).
public bool Tick()