--- tags: - engine - assets --- # Assets ## Handles, not shared pointers - Every asset is referenced by a typed `Handle` (index plus generation), **not** `Ref` / `shared_ptr`. - Ownership stays with the `AssetManager`, so it's always clear when an asset is freed. - **Hot reload** swaps the resource behind a handle, and every holder sees the new version automatically. ## Asset types | Type | Source | Loader | |---|---|---| | `Texture` | PNG, JPG | SDL_image → GPU upload | | `Model` | glTF 2.0 (`.glb`/`.gltf`) | cgltf or fastgltf (TBD) | | `AnimationClip` | glTF node animations | same as Model | | `Material` | parameters + textures | glTF material or script data | | `Shader` / `Pipeline` | SPIR-V built from `Assets/Shaders` | see [[Rendering#Shaders]] | | `Font` | TTF | SDL_ttf | | `Sound`, `Music` | WAV, OGG | SDL_mixer | | Script modules | see [[Scripting]] | script backend | ## Paths - Assets resolve relative to `SDL_GetBasePath()/Assets`, which matches the existing post-build copy step. - Saves and settings go to `SDL_GetPrefPath()`. ## Hot reload (debug builds only) - Poll file modification times about twice a second; reload textures, models, shaders, sounds and scripts. - Failed reloads keep the previous version and report the error in the debug UI. ## Definition databases - `DefinitionDB` maps a `StringId` to a definition (`CardDef`, `TowerDef`, `EnemyDef`, …). - Definitions are filled by the script loader (see [[Scripting]]). - Instances store only the ID, so reloaded definitions take effect immediately. > [!question] Open > glTF loader choice: cgltf (a single C header, simple) or fastgltf (C++20, faster, needs simdjson). Check nixpkgs availability under the same-version rule. See [[Open Questions]].