summaryrefslogtreecommitdiff
path: root/src/asset-manager.hpp
blob: ec98d08f8ea9d1f50575bd182d75ecce3b1ca345 (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
#ifndef PKE_ASSET_MANAGER_HPP
#define PKE_ASSET_MANAGER_HPP

#include "pk.h"

#include <cstdint>
#include <future>

struct AssetHandle : public pk_handle { };

constexpr AssetHandle AssetHandle_MAX = AssetHandle{ pk_handle_MAX_constexpr };

TypeSafeInt_constexpr(AssetLoadingState, uint8_t, 0xFF);
TypeSafeInt_constexpr(AssetType, uint8_t, 0xFF);

const int64_t AssetKeyLength = 16;
using AssetKey = char[AssetKeyLength];

const AssetLoadingState PKE_ASSET_LOADING_STATE_UNLOADED = AssetLoadingState {0};
const AssetLoadingState PKE_ASSET_LOADING_STATE_LOADING  = AssetLoadingState {1};
const AssetLoadingState PKE_ASSET_LOADING_STATE_LOADED   = AssetLoadingState {2};
const AssetLoadingState PKE_ASSET_LOADING_STATE_FAILED   = AssetLoadingState {3};

const AssetType PKE_ASSET_TYPE_UNSET   = AssetType {0x00};
const AssetType PKE_ASSET_TYPE_SHADER  = AssetType {0x01};
const AssetType PKE_ASSET_TYPE_MODEL   = AssetType {0x02};
const AssetType PKE_ASSET_TYPE_TEXTURE = AssetType {0x04};
const AssetType PKE_ASSET_TYPE_AUDIO   = AssetType {0x08};
const AssetType PKE_ASSET_TYPE_FONT    = AssetType {0x10};
const AssetType PKE_ASSET_TYPE_ALL     = AssetType {0xFF};

constexpr int64_t EngineDefinedAssetCount = 8;
extern AssetKey EngineDefinedAssets[EngineDefinedAssetCount];

struct Asset {
	AssetHandle handle{};
	AssetKey key = {'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
	const char *basePath = nullptr;
	int64_t size = 0;
	void *ptr = nullptr;
	std::future<void> future;
	int8_t referenceCount = 0;
	AssetLoadingState state = PKE_ASSET_LOADING_STATE_UNLOADED;
	AssetType type = PKE_ASSET_TYPE_UNSET;
};

void AM_Init();
AssetHandle AM_Register(AssetKey key, AssetType type, const void *data, int64_t size, std::size_t alignment);
AssetHandle AM_Register(const char *path, AssetType type);
AssetHandle AM_Register(AssetKey key, AssetType type, const char *path);
void AM_Release(AssetHandle assetHandle);
const Asset *AM_Get(AssetHandle assetHandle);
const AssetHandle AM_GetHandle(AssetKey key);
pk_handle_bucket_index_T AM_GetBucketCount();
Asset *AM_GetAssets(pk_handle_bucket_index_T bucketIndex, pk_handle_item_index_T &itemCount);
void AM_Teardown();
void AM_DebugPrint();

#endif /* PKE_ASSET_MANAGER_HPP */