Table of Contents

Class GloamHost

Namespace
Gloam.Runtime
Assembly
Gloam.Runtime.dll

Optimized DryIoc container host for roguelike engines. Features performance optimizations for high-frequency object creation, memory management, and game loop scoping.

public class GloamHost : IGloamHost, IAsyncDisposable, IDisposable
Inheritance
GloamHost
Implements
Inherited Members

Constructors

GloamHost(GloamHostConfig)

Initializes a new instance of GloamHost with the specified configuration

public GloamHost(GloamHostConfig config)

Parameters

config GloamHostConfig

The host configuration

Exceptions

ArgumentNullException

Thrown when config is null

Properties

Container

Gets the dependency injection container

public IContainer Container { get; }

Property Value

IContainer

InputContextManager

public IInputContextManager InputContextManager { get; }

Property Value

IInputContextManager

LayerRenderingManager

/// Gets the layer rendering manager responsible for managing and rendering layers

public ILayerRenderingManager LayerRenderingManager { get; }

Property Value

ILayerRenderingManager

SceneManager

public ISceneManager SceneManager { get; }

Property Value

ISceneManager

State

Gets the current state of the host

public HostState State { get; }

Property Value

HostState

Methods

Dispose()

Disposes the host and releases all resources

public void Dispose()

DisposeAsync()

Asynchronously disposes the host and releases all resources

public ValueTask DisposeAsync()

Returns

ValueTask

A ValueTask representing the asynchronous dispose operation

GetLoopState()

Gets the current loop state information for debugging purposes

public (bool IsFirstFrame, TimeSpan TimeSinceStart, TimeSpan TimeSinceLastRender) GetLoopState()

Returns

(bool IsFirstFrame, TimeSpan TimeSinceStart, TimeSpan TimeSinceLastRender)

A tuple containing loop state information

InitializeAsync(CancellationToken)

Initializes the host asynchronously

public ValueTask InitializeAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Cancellation token

Returns

ValueTask

A ValueTask representing the initialization operation

LoadContentAsync(string, CancellationToken)

Loads content from the specified root directory

public ValueTask LoadContentAsync(string contentRoot, CancellationToken ct = default)

Parameters

contentRoot string

The root directory for content loading

ct CancellationToken

Cancellation token

Returns

ValueTask

A ValueTask representing the content loading operation

LoopAsync(GameLoopConfig, CancellationToken)

Executes a single game loop iteration. Can be called externally when LoopMode is External.

public Task LoopAsync(GameLoopConfig config, CancellationToken ct = default)

Parameters

config GameLoopConfig

Game loop configuration

ct CancellationToken

Cancellation token

Returns

Task

A Task representing the loop iteration

Exceptions

InvalidOperationException

Thrown when called in Internal mode or when host is not running

ResetLoopState()

Resets the internal loop state. Useful when switching between loop modes or restarting.

public void ResetLoopState()

RunAsync(GameLoopConfig, CancellationToken)

Runs the game loop with the specified configuration

public Task RunAsync(GameLoopConfig config, CancellationToken ct = default)

Parameters

config GameLoopConfig

Game loop configuration

ct CancellationToken

Cancellation token

Returns

Task

A Task representing the game loop execution

Exceptions

ArgumentNullException

Thrown when config is null

RunAsync(Func<bool>, TimeSpan, CancellationToken)

Legacy overload for backward compatibility. Runs the roguelike game loop

public Task RunAsync(Func<bool> keepRunning, TimeSpan fixedStep, CancellationToken ct)

Parameters

keepRunning Func<bool>

Function that returns true while the game should continue running

fixedStep TimeSpan

Ignored in roguelike mode (kept for compatibility)

ct CancellationToken

Cancellation token

Returns

Task

A Task representing the game loop execution

SetInputDevice(IInputDevice)

Sets the input device for the host to use for user input

public void SetInputDevice(IInputDevice inputDevice)

Parameters

inputDevice IInputDevice

The input device instance to use

SetRenderer(IRenderer)

Sets the renderer for the host to use for drawing operations

public void SetRenderer(IRenderer renderer)

Parameters

renderer IRenderer

The renderer instance to use

StartAsync(CancellationToken)

Starts the host and begins the game loop

public Task StartAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Cancellation token

Returns

Task

A Task representing the start operation

StopAsync(CancellationToken)

Stops the host and game loop gracefully

public Task StopAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Cancellation token

Returns

Task

A Task representing the stop operation