|
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
|
File: deki-engine/include/deki/assets/AssetRef.h
Every component that references an asset uses AssetRef<T>. It has four fields:
| Field | Type | Purpose |
|---|---|---|
| guid | std::string | The GUID used to load the asset from disk. Always points to an actual file. |
| source | std::string | Context-dependent metadata. See "Dual-Field Pattern" below. |
| ptr | void* | Cached pointer to the loaded asset. Set on first Get(). |
| loadAttempted | bool | Prevents retry spam. Set to true after first load attempt. |
Get() triggers a one-time load:
To force a reload after changing guid, you must clear both ptr and loadAttempted:
The guid and source fields have different meanings depending on the asset type. This is intentional and reflects a real architectural difference.
| Asset type | guid | source | Why |
|---|---|---|---|
| Sprite (plain) | Sprite GUID | (empty) | Single file, no indirection |
| Sprite (frame) | Parent sprite GUID | Frame GUID | The parent .tex file contains all frames. guid loads the file, source identifies the frame region. |
| Font | Variant GUID (baked) | TTF source GUID | Each font size is a separate file. guid loads the baked variant directly. |
| Animation | Animation GUID | (empty) | Single file |
The code generator produces ResolveObjectRefs with:
This ensures OnAssetRefResolved receives the meaningful identifier (frame GUID for sprites, TTF source for fonts) regardless of which field it's stored in.
Virtual/derived assets use deterministic GUIDs generated from a seed string via GenerateDeterministicGuid() (dual 64-bit FNV-1a hash, formatted as UUID).
| Virtual Asset | Seed Format | Example |
|---|---|---|
| Font variant | sourceGuid + ":" + fontSize | "abc-123:16" |
| Font atlas | sourceGuid + ":" + fontSize + ":atlas" | "abc-123:16:atlas" |
| Sprite frame | parentGuid + ":" + frameIndex | "abc-123:0" |
| Preview font | "preview:" + sourceGuid + ":" + fontSize | "preview:abc-123:16" |
The "preview:" prefix prevents collision with real font variant GUIDs.
Binary format for O(log n) runtime lookup:
NEVER change these constants. They must match between:
| Key format | Maps to | Used by |
|---|---|---|
| "path:type" (e.g., "textures/player:Sprite") | Asset GUID | AssetManager::Load<T>("path") |
| GUID string (e.g., "abc-123-...") | Same GUID | Direct GUID lookup for baked fonts |
| File | Scope | Written by |
|---|---|---|
| cache/asset_table.bin | All project assets | AssetPipeline::UpdateAssetTable() |
| <build's assets>/asset_table.bin | Only used assets | AssetExporter::ExportAssetLookupTable() |
A build's assets are exported next to its boot payload (assets/, read as F:/assets/) when the target keeps them in internal storage, or to <project>/storage/ for an SD card (S:/). AssetManager::LoadAssetRoot loads the table, the pack index and every asset from there; see platforms.md.
| File | Purpose |
|---|---|
| deki-engine/include/deki/assets/AssetRef.h | AssetRef template |
| deki-engine/src/assets/AssetManager.cpp | GUID lookup, asset loading |
| deki-engine/include/deki/assets/AssetLookupTable.h | Binary table format + FNV-1a |
| deki-engine/src/Guid.h / .cpp | Deterministic GUID generation |
| deki-editor/src/AssetPipeline.cpp | GUID assignment, cache management |
| src/services/AssetExporter.cpp | Export pipeline |