Skip to content

KernelAPI reference

Class EngineBuilder

Namespace: MicroEngine.Kernel
Assembly: MicroEngine.Kernel.dll
Guide: Modules and the frame schedule

Composes an Engine: modules are added in order, each registering services, frame systems and capabilities; settings records are edited; Build then fixes the schedule and the time policy. Nothing is discovered by reflection.

C#
public sealed class EngineBuilder

Inheritance

object ← EngineBuilder

Examples

C#
var builder = new EngineBuilder()
.Configure<TimeSettings>(time => time with { FixedRate = 120 })
.Add(new PhysicsModule());
builder.Schedule.Add(FramePhase.Update, "mygame.camera", frame => camera.Follow(frame.Blend));
Engine engine = builder.Build();

Constructors

EngineBuilder()

C#
public EngineBuilder()

Properties

Capabilities

The optional features declared so far (CapabilityRegistry).

C#
public CapabilityRegistry Capabilities { get; }

Property Value

CapabilityRegistry

Lifecycle

The engine’s events; modules may subscribe while they are configured.

C#
public EngineLifecycle Lifecycle { get; }

Property Value

EngineLifecycle

Schedule

The frame systems, by phase (FrameSchedule).

C#
public FrameSchedule Schedule { get; }

Property Value

FrameSchedule

Services

The services modules register and read (ServiceRegistry).

C#
public ServiceRegistry Services { get; }

Property Value

ServiceRegistry

Methods

Add<TModule>(TModule)

Adds module and runs its Configure now.

C#
public EngineBuilder Add<TModule>(TModule module) where TModule : IEngineModule

Parameters

module TModule

Returns

EngineBuilder

This builder, to chain calls.

Type Parameters

TModule

Exceptions

ArgumentNullException

module is null.

InvalidOperationException

A module of the same type was already added, or the engine was built.

Build()

Builds the engine, once. Registers the defaults of what nobody registered (TimeSettings, a ConsoleLog as ILog, the lifecycle as IEngineLifecycle), resolves and fixes the frame schedule and creates the loop’s FrameClock.

C#
public Engine Build()

Returns

Engine

Exceptions

InvalidOperationException

The engine was already built, or the schedule’s order cannot be resolved (a cycle, or a constraint naming a missing system or one in another phase).

ArgumentOutOfRangeException

A TimeSettings value is out of range.

Configure<TSettings>(Func<TSettings, TSettings>)

Edits the settings record TSettings: edit receives the current value (Settings``1) and returns the new one, which becomes the registered service. Settings are values: the engine reads them once, when it is built.

C#
public EngineBuilder Configure<TSettings>(Func<TSettings, TSettings> edit) where TSettings : class, new()

Parameters

edit Func<TSettings, TSettings>

Returns

EngineBuilder

This builder, to chain calls.

Type Parameters

TSettings

Exceptions

ArgumentNullException

edit is null.

InvalidOperationException

edit returned null, or the engine was built.

HasModule<TModule>()

Whether a module of type TModule was added.

C#
public bool HasModule<TModule>() where TModule : IEngineModule

Returns

bool

Type Parameters

TModule

Settings<TSettings>()

The settings record TSettings as configured so far: the registered service, or a new instance with its defaults when none was registered.

C#
public TSettings Settings<TSettings>() where TSettings : class, new()

Returns

TSettings

Type Parameters

TSettings