Table of Contents

Namespace AlphaFramework.Presentation

Provides a basis for building presenters that visualize AlphaFramework.World-based game worlds using OmegaEngine.Graphics.Renderables.

Note

NuGet package: AlphaFramework.Presentation

Presenter

The Presenter (see PresenterBase<TUniverse>) handles visual representation. It bridges the game world and the rendering engine:

  • Creates renderables - Converts entities to Renderables
  • Manages the scene - Adds/removes objects from the Scene
  • Handles view updates - Keeps visual representation synchronized with world state

Different presenter implementations can provide different visualization modes (e.g., in-game, editor, menu background) without changing the underlying world data.

public class Presenter : PresenterBase<Universe>
{
    public Presenter(Engine engine, Universe universe) : base(engine, universe)
    {
        View = new(Scene, new FreeFlyCamera());
    }

    public override void Initialize()
    {
        if (Initialized) return;

        // Add PositionableRenderables to Scene.Positionables

        base.Initialize();
    }
}

Template rendering

RenderComponentPresentation provides .ToPresentation() extension methods that convert AlphaFramework Render components into live OmegaEngine renderables:

Data component Presentation type
StaticMesh Model
AnimatedMesh AnimatedModel
TestSphere Model (procedural)
CpuParticleSystem CpuParticleSystem
LightSource PointLight

This is useful for applying AlphaFramework.World.Templates. A presenter typically iterates entity.TemplateData.Render, calls .ToPresentation(engine) on each component, and adds the resulting renderables to the entity's group in PivotedRenderables:

foreach (var component in entity.TemplateData!.Render)
{
    switch (component)
    {
        case StaticMesh m when m.ToPresentation(engine) is {} model:
            renderables.AddTo(model, entity, entity.Name);
            break;
        case LightSource l:
            var light = l.ToPresentation();
            light.AttachedTo = renderables.PivotFor(entity, entity.Name);
            scene.Lights.Add(light);
            break;
    }
}

A component's Shift becomes the renderable's local Position (or the light's Offset), so writing the entity's position and rotation to renderables.AnchorFor(entity) moves everything belonging to the entity at once. The group only gets a Pivot of its own once more than one thing shares that transform. See AlphaFramework for the full hierarchy contract.

GameBase

GameBase provides the application shell. It extends RenderHost with game-specific features:

  • Settings management - Loads and saves game configuration
  • GUI system - Integrates OmegaGUI for menus and HUD
  • Lifecycle management - Handles initialization, main loop, and cleanup

Your game class derives from GameBase and coordinates the other components:

public class MyGame(Settings settings)
    : GameBase(settings, "My game")
{
    private Session? _session;
    private Presenter? _presenter;

    protected override bool Initialize()
    {
        if (!base.Initialize()) return false;

        // Load universe
        var universe = Universe.Load("Level1.xml");

        // Create session
        _session = new Session(universe);

        // Create presenter
        _presenter = new(Engine, universe);
        _presenter.HookIn();

        return true;
    }

    protected override double UpdateGame(double elapsedTime)
        => _session!.Update(elapsedTime);
}

API

Namespaces

AlphaFramework.Presentation.Config

Configuration system for game and editor settings.

Classes

Arguments

Helpers for interpreting the command-line arguments for the current process.

CoordinatePresenter<TUniverse, TCoordinates>

Uses the Engine to present a CoordinateUniverse<TCoordinates> game world.

DialogOptions

Options for loading a dialog with LoadDialog(string, DialogOptions, object?).

GameBase

Base class for building a game using AlphaFramework. Handles basic engine and GUI setup.

PivotedRenderables

An ICollection<T> facade over the root renderables of a Scene that groups everything belonging to one owner under a shared transform.

PresenterBase<TUniverse>

Uses the Engine to present an IUniverse game world.

RenderComponentPresentation

Converts Render components into PositionableRenderables.

SoundComponentPresentation

Converts Sound components into Sound3Ds.

TerrainExtensions

Contains extension methods for Terrain<TTemplate>.

Interfaces

IPresenter<TUniverse>

Maintains a View to present an IUniverse game world.