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 registers the resulting renderables with the scene:
foreach (var component in entity.TemplateData!.Render)
{
var renderable = component switch
{
StaticMesh m => m.ToPresentation(engine),
LightSource l => l.ToPresentation(),
_ => null
};
if (renderable != null)
scene.Positionables.Add(renderable);
}
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 void Render(double elapsedTime)
{
_session!.Update(elapsedTime);
base.Render(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.
- GameBase
Base class for building a game using AlphaFramework. Handles basic engine and GUI setup.
- RenderComponentPresentation
Converts Render components into PositionableRenderables.
- TerrainExtensions
Contains extension methods for Terrain<TTemplate>.