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

#include "macros.hpp"
#include "memory.hpp"

#include <cstdint>
#include <future>

struct AssetHandle : public PkeHandle { };

constexpr AssetHandle AssetHandle_MAX = AssetHandle{};

TypeSafeInt_Const_Expr(AssetLoadingState, 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};

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;
};

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

#endif /* PKE_ASSET_MANAGER_HPP */