Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
Flint::AssetManager Class Reference

Central resource cache and hot-reload coordinator. More...

#include <flint/resource/assets-manager.h>

+ Collaboration diagram for Flint::AssetManager:

Classes

class  WatchHandle
 RAII handle returned by watch(). More...
 

Public Types

using ReloadCallback = std::function<void(const std::string &)>
 Callback type invoked when a watched asset is reloaded.
 

Public Member Functions

 AssetManager (IAssetLoader &loader, SDL_GPUDevice *gpuDevice, bool hotReloadEnable)
 Construct an AssetManager.
 
 ~AssetManager ()
 Destroy the AssetManager.
 
GPUTexture & getTexture (const std::string &path)
 Return a GPU texture for path, uploading it on first access.
 
WatchHandle watch (const std::string &path, ReloadCallback callback)
 Register a callback to be invoked whenever path is reloaded.
 
void update ()
 Poll for hot-reload changes and fire pending callbacks.
 
IAssetLoader & getLoader ()
 Return a reference to the underlying asset loader.
 
void setHotReloadEnabled (bool enabled)
 Enable or disable hot-reload polling.
 
bool isHotReloadEnabled () const
 Return whether hot-reload polling is currently active.
 

Detailed Description

Central resource cache and hot-reload coordinator.

AssetManager sits between game code and the raw byte-loading layer (IAssetLoader). It caches GPU textures so repeated calls to getTexture() never re-upload the same asset, and—when hot-reload is enabled—polls the loader for revision bumps every HOT_RELOAD_INTERVAL milliseconds, invoking registered callbacks so the game can react without restarting.

Ownership and lifetime

AssetManager is non-copyable. Callbacks registered via watch() are automatically cancelled when their WatchHandle is destroyed, which prevents use-after-free if a system outlives the manager.

Note
SDL_GPUDevice must outlive this object; the manager does not take ownership of the device pointer.

Definition at line 37 of file assets-manager.h.


The documentation for this class was generated from the following file: