summaryrefslogtreecommitdiff
path: root/src/asset-manager.hpp
blob: 36516b56fd3e0c0facd4d20ca876a6ca87660ffa (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
#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 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{
	char key[16] = {'\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);
void AM_Release(AssetHandle assetHandle);
const Asset *AM_Get(AssetHandle assetHandle);
void AM_Teardown();
void AM_DebugPrint();

#endif /* PKE_ASSET_MANAGER_HPP */