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.
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.
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().
#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;
}();
};
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.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 name | Category | Manager used | Value type |
|---|---|---|---|
| Images | Asset | TextureManager | sf::Texture |
| Fonts | Asset | FontManager | sf::Font |
| Sounds | Asset | SoundManager | sf::SoundBuffer |
| Text | Config | ConfigManager | std::string |
| Ints | Config | ConfigManager | int |
| Floats | Config | ConfigManager | float |
| Booleans | Config | ConfigManager | bool |
| Flag | Component | FlagManager | Boolean on/off |
| State | Component | StateManager | Exclusive active mode |
| Event | Component | Event system | Custom event identifiers |
Images and Fonts is perfectly valid.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.
#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;
};
&Resources::get(Images::X) gives you const sf::Texture* directly — exactly what setTexture() expects. No intermediate variable needed.Accessing Resources Outside a Component
You can access manifest resources from any translation unit via the individual managers or through AssetsManager.
#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);
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.
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 need | Use |
|---|---|
| One asset type only | TextureManager / FontManager / SoundManager |
| Multiple asset types | AssetsManager<M> |
| Assets + config | Context<M> |
| Inside a Component | Resources::get() — injected automatically |