Skip to content

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.

C#
public sealed class GameSession

Inheritance

object ← GameSession

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.

C#
public GameSession(Func<Game> createGame, Func<Game, IPlatform> createPlatform)

Parameters

createGame Func<Game>

createPlatform Func<Game, IPlatform>

Exceptions

ArgumentNullException

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.

C#
public GameSession(Func<LaunchRequest, GameHost> compose)

Parameters

compose Func<LaunchRequest, GameHost>

Exceptions

ArgumentNullException

compose is null.

Properties

Frames

Frames rendered by the current or last run.

C#
public long Frames { get; }

Property Value

long

Game

The game of the current or last run.

C#
public Game? Game { get; }

Property Value

Game?

Host

The composition of the current or last run of a composed session; null otherwise.

C#
public GameHost? Host { get; }

Property Value

GameHost?

IsRunning

Whether a run is in progress.

C#
public bool IsRunning { get; }

Property Value

bool

Platform

The platform of the current run; null between runs.

C#
public IPlatform? Platform { get; }

Property Value

IPlatform?

Result

How the last run ended; null while a run is in progress or before the first one.

C#
public RunResult? Result { get; }

Property Value

RunResult?

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.

C#
public bool Start(RunOptions? options = null)

Parameters

options RunOptions?

Returns

bool

Exceptions

InvalidOperationException

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.

C#
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

bool

Exceptions

FormatException

The request’s script is invalid (nothing was started).

InvalidOperationException

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.

C#
public void Stop()

Tick()

Runs one frame. Returns false once the run has ended (see Result).

C#
public bool Tick()

Returns

bool