AssetManager
Base AssetManager providing UUID-based asset cache and retrieval. Subclassed by EditorAssetManager (scan/import) and RuntimeAssetManager (packed).
- Module
- AssetSystem
- Header
#include "AssetSystem/AssetManager.h"- Namespace
Mowo
Constructors
| Signature | Name | Description |
|---|---|---|
virtual ~AssetManager() | ~AssetManager |
Public functions
| Returns | Name | Description |
|---|---|---|
AssetManager& | Get | Singleton access |
AssetManager* | TryGet | out-of-line; reading s_instance |
void | SetInstance | from a consumer TU across the MowoEngine.Game.dll boundary as an inline triggers a dllimport mismatch on the static storage. |
bool | Initialize | Lifecycle |
void | Shutdown | |
void | Update | Called once per frame: runs the eviction tick. |
int | GetGpuUploadBudgetPerFrame | Max GPU uploads (CreateGPU calls) a subclass Update should drain per frame; <= 0 means unbounded. |
void | SetEvictionStrategy | |
EvictionStrategy | GetEvictionStrategy | |
void | SetMemoryBudget | The budget follows asset.MemoryBudgetMB whenever that cvar changes (0 = keep the current one); FQualityAutoTier::ResolveDeviceBudgets claims it from the device's VRAM. |
uint64_t | GetMemoryBudget | |
uint64_t | GetEstimatedUsage | |
void | RefreshMemoryEstimates | Re-reads every cached asset's estimate. |
void | TouchAsset | Bump the LRU stamp (GetAsset does this automatically). |
void | PinAsset | Pinned assets are never auto-evicted (UI atlases, always-resident). |
bool | UnloadAsset | Explicit unload: DestroyGPU + Unload + drop from the cache. |
void | UnloadAssetsInSet | Bulk variant for streaming sector unload. |
size_t | ReleaseUnreferencedSince | Closing a level or an asset editor freed nothing: everything it loaded stayed cached until usage crossed the whole budget (measured: three asset editors 3.06 -> 4.32 GB private, 4.17 GB after closing them). |
uint64_t | GetFrameCounter | Update() count, the clock lastAccessFrame and the sweeps above run on. |
Ref<Asset> | GetAsset | Get an asset by UUID. |
Ref<T> | GetAsset | Get a typed asset by UUID. |
Ref<T> | GetAssetByPath | Get a typed asset by source path. |
Ref<Asset> | RequestAssetAsync | The one load-by-path verb a caller below the editor/runtime split can use: hands back the asset only when it is fully resident, otherwise starts (or continues) loading it off the calling thread and returns null. |
void | ResolveMaterialTextures | Bind a material's texture slots from wherever the caller is — a mesh applying its authored slot materials does it on the main thread, inside the GPU drain. |
bool | IsImportInFlight | True while sourcePath is being imported in the background — queued, parsing, or uploading. |
void | ResolveHandle | Resolve an AssetHandle — fills in the Ref if the asset is loaded |
bool | IsAssetLoaded | |
bool | ReloadInPlace | Re-reads a resident asset in place from absolutePath: the object survives, so every Ref and handle in scenes and components keeps working and sees the new version. |
std::vector<Ref<Asset>> | GetResidentAssets | Every asset in the cache, copied out under its lock so the caller can touch them without holding it — an editor save that has to reach the live copy of what it just wrote walks this. |
AssetRegistry& | GetRegistry | Registry access |
const AssetRegistry& | GetRegistry | |
const GPUContext& | GetGPUContext | GPU Context |
Function details
~AssetManager
virtual ~AssetManager()Get
static AssetManager& Get()Singleton access
TryGet
static AssetManager* TryGet()out-of-line; reading s_instance
SetInstance
static void SetInstance(AssetManager* instance)from a consumer TU across the MowoEngine.Game.dll boundary as an inline triggers a dllimport mismatch on the static storage.
Initialize
virtual bool Initialize(const GPUContext& ctx)Lifecycle
Shutdown
virtual void Shutdown()Update
virtual void Update()Called once per frame: runs the eviction tick. Subclasses doing their own per-frame work (GPU uploads) must call the base.
GetGpuUploadBudgetPerFrame
static int GetGpuUploadBudgetPerFrame()Max GPU uploads (CreateGPU calls) a subclass Update should drain per frame; <= 0 means unbounded. Backed by the asset.UploadsPerFrame cvar so a burst of finished async imports is time-sliced instead of hitching the frame that receives them all.
SetEvictionStrategy
void SetEvictionStrategy(EvictionStrategy s)GetEvictionStrategy
EvictionStrategy GetEvictionStrategy() constSetMemoryBudget
void SetMemoryBudget(uint64_t bytes)The budget follows asset.MemoryBudgetMB whenever that cvar changes (0 = keep the current one); FQualityAutoTier::ResolveDeviceBudgets claims it from the device's VRAM. A direct SetMemoryBudget stands until the cvar next moves.
GetMemoryBudget
uint64_t GetMemoryBudget() constGetEstimatedUsage
uint64_t GetEstimatedUsage() constRefreshMemoryEstimates
void RefreshMemoryEstimates()Re-reads every cached asset's estimate. An entry's size was captured when it was cached — for a mesh, before its GPU buffers existed, so it counted 0 for the rest of its life. EvictionTick refreshes on its own every few frames; a caller that needs the number now asks here.
TouchAsset
void TouchAsset(UUID id)Bump the LRU stamp (GetAsset does this automatically).
PinAsset
void PinAsset(UUID id, bool pinned)Pinned assets are never auto-evicted (UI atlases, always-resident).
UnloadAsset
bool UnloadAsset(UUID id)Explicit unload: DestroyGPU + Unload + drop from the cache. Fails (false) when something besides the cache still holds a ref — yanking GPU resources from under a live user is a crash, not a cleanup.
UnloadAssetsInSet
void UnloadAssetsInSet(const std::vector<UUID>& ids)Bulk variant for streaming sector unload.
ReleaseUnreferencedSince
size_t ReleaseUnreferencedSince(uint64_t frame)Closing a level or an asset editor freed nothing: everything it loaded stayed cached until usage crossed the whole budget (measured: three asset editors 3.06 -> 4.32 GB private, 4.17 GB after closing them). The host calls this a few updates after a document closed: it unloads every unpinned asset nothing outside the cache holds and nobody touched since frame. Components keep raw pointers into assets, so the host touches whatever its still-open documents use first. Returns how many unloaded.
GetFrameCounter
uint64_t GetFrameCounter() constUpdate() count, the clock lastAccessFrame and the sweeps above run on.
GetAsset
Ref<Asset> GetAsset(UUID id) constGet an asset by UUID. Returns null if not loaded.
GetAsset
template<typename T> Ref<T> GetAsset(UUID id) constGet a typed asset by UUID.
GetAssetByPath
template<typename T> Ref<T> GetAssetByPath(const std::string& path)Get a typed asset by source path.
RequestAssetAsync
virtual Ref<Asset> RequestAssetAsync(const std::string& sourcePath)The one load-by-path verb a caller below the editor/runtime split can use: hands back the asset only when it is fully resident, otherwise starts (or continues) loading it off the calling thread and returns null. Poll it — the frame it returns non-null is the frame to use the asset. Repeat calls for one path coalesce into one load. The base only probes the cache, which is what a bare manager in a test wants.
ResolveMaterialTextures
virtual void ResolveMaterialTextures(const Ref<Asset>& material)Bind a material's texture slots from wherever the caller is — a mesh applying its authored slot materials does it on the main thread, inside the GPU drain. The base resolves them now, which is what a packaged game with cooked textures wants; the editor imports what is missing in the background and binds each slot as its texture lands, instead of decoding every slot of every material in the one frame a model finishes.
IsImportInFlight
virtual bool IsImportInFlight(const std::string& sourcePath) constTrue while sourcePath is being imported in the background — queued, parsing, or uploading. A big model takes seconds, and a tile that looks idle meanwhile reads as a broken asset. The base loads synchronously, so nothing is ever in flight there.
ResolveHandle
template<typename T> void ResolveHandle(AssetHandle<T>& handle)Resolve an AssetHandle — fills in the Ref if the asset is loaded
IsAssetLoaded
bool IsAssetLoaded(UUID id) constReloadInPlace
virtual bool ReloadInPlace(const std::string& sourcePath, const std::string& absolutePath)Re-reads a resident asset in place from absolutePath: the object survives, so every Ref and handle in scenes and components keeps working and sees the new version. sourcePath is the registry's path for it ("Content/..."). False when it is not resident here (nothing to reload) or the new version failed to load (the asset is then marked Invalid). The editor's override goes through its reimport, which also refreshes the registry's stamps.
GetResidentAssets
std::vector<Ref<Asset>> GetResidentAssets() constEvery asset in the cache, copied out under its lock so the caller can touch them without holding it — an editor save that has to reach the live copy of what it just wrote walks this.
GetRegistry
AssetRegistry& GetRegistry()Registry access
GetRegistry
const AssetRegistry& GetRegistry() constGetGPUContext
const GPUContext& GetGPUContext() constGPU Context