1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// This file is part of the 64k demo project.
// Core asset management interface for basic asset retrieval.
// For typed helpers (TextureAsset, MeshAsset), include asset_manager_utils.h
#pragma once
#include "asset_manager_dcl.h"
enum class AssetType : uint8_t {
WGSL,
SPEC,
TEXTURE,
MESH,
BINARY,
MP3,
PROC,
PROC_GPU,
};
// Compression scheme applied to the packed bytes (only relevant for static
// embedded assets; disk-load and procedural assets are always NONE).
enum class AssetCompression : uint8_t {
NONE = 0,
// Order-0 rANS, model seeded from a corpus-wide histogram embedded in the
// generated assets blob (see GetAnsAsciiHistogram). Used for WGSL.
ANS_ASCII = 1,
};
struct AssetRecord {
const uint8_t* data; // Pointer to asset data (static or dynamic)
size_t size; // Size of 'data' in bytes (compressed size if any)
AssetType type;
AssetCompression compression; // How 'data' is encoded; NONE = raw bytes
size_t uncompressed_size; // Size after decompression (== size if NONE)
const char* proc_func_name_str; // Name of procedural generation function
// (string literal)
const float* proc_params; // Parameters for procedural generation (static,
// from assets.txt)
int num_proc_params; // Number of procedural parameters
};
// Initial-state histogram (256 entries) used to seed ANS_ASCII compression.
// Defined in the generated assets blob; computed at pack time over the WGSL
// corpus.
const uint32_t* GetAnsAsciiHistogram();
// Generic interface
// Retrieves a pointer to the asset data.
// - Static assets are guaranteed to be 16-byte aligned.
// - Static assets are guaranteed to be null-terminated (safe as C-strings).
// - 'out_size' returns the original asset size (excluding the null terminator).
const uint8_t* GetAsset(AssetId asset_id, size_t* out_size = nullptr);
void DropAsset(AssetId asset_id, const uint8_t* asset);
// Returns the AssetId for a given asset name, or AssetId::ASSET_LAST_ID if not
// found.
AssetId GetAssetIdByName(const char* name);
// Returns the AssetType for a given asset id.
AssetType GetAssetType(AssetId asset_id);
#if !defined(STRIP_ALL)
// Hot-reload: Parse and reload assets from config file (debug only)
bool ReloadAssetsFromFile(const char* config_path);
#endif
|