blob: 0c2cc63b6b813b849271467e64af32503238f439 (
plain)
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
|
// This file is part of the 64k demo project.
// It defines the core structures and interface for asset management.
// Used for efficient retrieval of embedded binary resources.
#pragma once
#include <cstddef>
#include <cstdint>
enum class AssetId : uint16_t; // Forward declaration
// Type for procedural generation functions: (buffer, width, height, params,
// num_params)
// Returns true on success, false on failure.
typedef bool (*ProcGenFunc)(uint8_t*, int, int, const float*, int);
struct AssetRecord {
const uint8_t* data; // Pointer to asset data (static or dynamic)
size_t size; // Size of the asset data
bool is_procedural; // True if data was dynamically allocated by a procedural
// generator
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
};
// 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);
struct TextureAsset {
int width;
int height;
const uint8_t* pixels;
};
struct MeshVertex {
float p[3];
float n[3];
float u[2];
};
struct MeshAsset {
uint32_t num_vertices;
const MeshVertex* vertices;
uint32_t num_indices;
const uint32_t* indices;
};
// Helper to retrieve and parse a simple texture asset (from packer's
// [w][h][pixels] format)
TextureAsset GetTextureAsset(AssetId asset_id);
// Helper to retrieve and parse a mesh asset (from packer's binary format)
MeshAsset GetMeshAsset(AssetId asset_id);
|