ml::docs | Your First App Manifests Events Plugins Scenes Graphics Resources
← All Tutorials
Beginner 6 sections ~20 min C++17/20

Manifests

Declare every asset, config value, flag, and state your component needs in one place. The framework loads and caches them automatically.

Before you start

You'll need Malena and SFML set up. Check the quick start guide if you haven't already.

Introduction

What is a Manifest?

A Manifest is a static registry class that binds enum keys to file paths and configuration values. Instead of scattering loadFromFile() calls across your codebase, you declare everything your component needs in one place, and the framework resolves and caches every asset for you.

Think of it as a header file for your data. Just as a .h file declares what a module exposes, a Manifest declares what resources a component depends on — and the framework handles loading, caching, and lifetime automatically.

The core contract: Declare it once, use it everywhere. The framework handles loading, caching, and lifetime management automatically. Wrong key type = compile error, not runtime crash.

1Core Concepts

Creating a Manifest

A manifest publicly inherits ml::Manifest. Declare inner enum class types for each category of resource you need, then register all file paths and config values in a single inline static initializer that runs at program startup — before main().

MyManifest.h cpp
#pragma once
#include 

class HUDManifest : public ml::Manifest
{
public:
    // ── Plugin identity (required for plugins) ──────────────────────
    static constexpr const char* name    = "HUD";
    static constexpr const char* version = "1.0.0";

    // ── Asset enums ─────────────────────────────────────────────────
    enum class Images  { Background, HealthBar };
    enum class Fonts   { Main, Mono };
    enum class Sounds  { Alert, Pickup };

    // ── Config enums ─────────────────────────────────────────────────
    enum class Text     { WindowTitle, ScoreLabel };
    enum class Ints     { MaxHealth, MaxAmmo };
    enum class Floats   { Opacity };
    enum class Booleans { ShowMinimap };

    // ── Component flags & states ─────────────────────────────────────
    enum class Flag  { Selected, Highlighted };
    enum class State { Idle, Active, Paused };

private:
    // Inline static initializer — runs once before main()
    inline static const auto _ = [](){
        set(Images::Background, "assets/hud/bg.png");
        set(Images::HealthBar,  "assets/hud/healthbar.png");
        set(Fonts::Main,        "assets/fonts/main.ttf");
        set(Fonts::Mono,        "assets/fonts/mono.ttf");
        set(Sounds::Alert,      "assets/sfx/alert.wav");
        set(Sounds::Pickup,     "assets/sfx/pickup.wav");

        set(Text::WindowTitle,  std::string("My Game"));
        set(Ints::MaxHealth,    100);
        set(Floats::Opacity,    0.85f);
        set(Booleans::ShowMinimap, true);
        return 0;
    }();
};
The inline static const auto _ = [](){{...}}(); pattern must be in the private: section. It's an implementation detail that registers entries into the framework's internal maps.

2Core Concepts

Enum Types at a Glance

Every enum name has a reserved meaning in the framework. The template machinery detects their presence at compile time and enables the appropriate manager overloads automatically.

Enum nameCategoryManager usedValue type
ImagesAssetTextureManagersf::Texture
FontsAssetFontManagersf::Font
SoundsAssetSoundManagersf::SoundBuffer
TextConfigConfigManagerstd::string
IntsConfigConfigManagerint
FloatsConfigConfigManagerfloat
BooleansConfigConfigManagerbool
FlagComponentFlagManagerBoolean on/off
StateComponentStateManagerExclusive active mode
EventComponentEvent systemCustom event identifiers
Only declare the enums you actually use. Missing enums compile cleanly as empty base classes — a manifest with only Images and Fonts is perfectly valid.

3Core Concepts

Using a Manifest with a Component

Pass your manifest as the first template argument to ml::ComponentWith<M>. This injects three things into your component automatically: all inner enum types as unqualified aliases, a Resources alias, and the full flag/state management systems.

HUDComponent.h cpp
#pragma once
#include 
#include "HUDManifest.h"

class HUDComponent : public ml::ComponentWith
{
public:
    void initialization() override
    {
        // Enum aliases are in scope — no HUDManifest:: prefix needed
        auto& tex   = Resources::get(Images::Background);
        auto& font  = Resources::get(Fonts::Main);
        auto& title = Resources::get(Text::WindowTitle);
        int   hp    = Resources::get(Ints::MaxHealth);

        // Pass texture pointer directly — &const_ref = const*
        _bg.setTexture(&Resources::get(Images::Background));

        // Flags and states from the manifest
        setState(State::Idle);
        enableFlag(Flag::Selected);
    }

    void draw(sf::RenderTarget& target, sf::RenderStates states) const override
    {
        target.draw(_bg, states);
    }

private:
    ml::Rectangle _bg;
};
Malena tip: &Resources::get(Images::X) gives you const sf::Texture* directly — exactly what setTexture() expects. No intermediate variable needed.

4Core Concepts

Accessing Resources Outside a Component

You can access manifest resources from any translation unit via the individual managers or through AssetsManager.

Any translation unit cpp
#include 

// Via AssetsManager (multiple asset types)
const sf::Texture& bg  = ml::AssetsManager::get(HUDManifest::Images::Background);
const sf::Font&    fnt = ml::AssetsManager::get(HUDManifest::Fonts::Main);

// Via individual managers
const sf::Font& mono = ml::FontManager::get(HUDManifest::Fonts::Mono);

// Built-in Arial — no manifest needed
const sf::Font& arial = ml::FontManager<>::getDefault();

// Config values
const std::string& title = ml::ConfigManager::get(HUDManifest::Text::WindowTitle);
int maxHp               = ml::ConfigManager::get(HUDManifest::Ints::MaxHealth);

5Core Concepts

Using Context for Assets + Config

Use ml::Context<Manifest> when you need assets AND config outside a component — in a plugin, utility class, or any code that doesn't inherit ComponentWith.

Using Context cpp
struct HUDContext : public ml::Context
{
    void setup()
    {
        // ManifestAliases bring enum types into scope
        auto& tex   = AssetMgr::get(Images::Background);
        auto& font  = AssetMgr::get(Fonts::Main);
        auto& title = ConfigMgr::get(HUDManifest::Text::WindowTitle);
        int   fps   = ConfigMgr::get(HUDManifest::Ints::MaxHealth);
    }
};
You needUse
One asset type onlyTextureManager / FontManager / SoundManager
Multiple asset typesAssetsManager<M>
Assets + configContext<M>
Inside a ComponentResources::get() — injected automatically