summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2023-12-28 12:00:47 -0500
committerJonathan Bradley <jcb@pikum.xyz>2023-12-28 12:00:47 -0500
commitcf0fac0eab12421f407d3acc1f1c84faead248bc (patch)
treec5b174085ebcd1bccaa29d20334e4123ade73f6b /src
parent41b5dafb1a3bf80db48abeb235ce00ec8e1c566f (diff)
add asset type for filtering
Diffstat (limited to 'src')
-rw-r--r--src/asset-manager.cpp9
-rw-r--r--src/asset-manager.hpp22
-rw-r--r--src/entities.cpp2
-rw-r--r--src/project.cpp15
4 files changed, 36 insertions, 12 deletions
diff --git a/src/asset-manager.cpp b/src/asset-manager.cpp
index b93a568..77aeffd 100644
--- a/src/asset-manager.cpp
+++ b/src/asset-manager.cpp
@@ -54,7 +54,7 @@ inline Asset *AM_Get_Inner(AssetKey key) {
return nullptr;
}
-AssetHandle AM_Register(AssetKey key, const void *data, int64_t size, std::size_t alignment) {
+AssetHandle AM_Register(AssetKey key, AssetType type, const void *data, int64_t size, std::size_t alignment) {
assert(data != nullptr && "Attempt to register invalid asset data");
assert(data != CAFE_BABE(void) && "Attempt to register invalid asset data");
assert(size != 0 && "Attempt to register asset data of size 0");
@@ -73,10 +73,11 @@ AssetHandle AM_Register(AssetKey key, const void *data, int64_t size, std::size_
asset.ptr = Pke_New(size, alignment);
memcpy(asset.ptr, data, size);
asset.state = PKE_ASSET_LOADING_STATE_LOADED;
+ asset.type = type;
return assetHandle;
}
-AssetHandle AM_Register(AssetKey key, const char *path) {
+AssetHandle AM_Register(AssetKey key, AssetType type, const char *path) {
Asset *searchedAsset = AM_Get_Inner(key);
if (searchedAsset != nullptr) {
return searchedAsset->handle;
@@ -93,6 +94,7 @@ AssetHandle AM_Register(AssetKey key, const char *path) {
strncpy(copiedPath, path, pathLen);
asset.basePath = copiedPath;
asset.state = PKE_ASSET_LOADING_STATE_LOADING;
+ asset.type = type;
std::packaged_task<void()> *task = Pke_New<std::packaged_task<void()>>();
new (task) std::packaged_task<void()>( [&asset] {
AM_Load_Task(asset);
@@ -102,7 +104,7 @@ AssetHandle AM_Register(AssetKey key, const char *path) {
return assetHandle;
}
-AssetHandle AM_Register(const char *path) {
+AssetHandle AM_Register(const char *path, AssetType type) {
NULL_CHAR_ARR(assetKey, AssetKeyLength);
int64_t pathLen = strlen(path);
int64_t pathOffset = (pathLen > AssetKeyLength ? pathLen - AssetKeyLength : 0);
@@ -124,6 +126,7 @@ AssetHandle AM_Register(const char *path) {
strncpy(copiedPath, path, pathLen);
asset.basePath = copiedPath;
asset.state = PKE_ASSET_LOADING_STATE_LOADING;
+ asset.type = type;
std::packaged_task<void()> *task = Pke_New<std::packaged_task<void()>>();
new (task) std::packaged_task<void()>( [&asset] {
AM_Load_Task(asset);
diff --git a/src/asset-manager.hpp b/src/asset-manager.hpp
index 71e95f5..fe0a688 100644
--- a/src/asset-manager.hpp
+++ b/src/asset-manager.hpp
@@ -12,16 +12,23 @@ struct AssetHandle : public PkeHandle { };
constexpr AssetHandle AssetHandle_MAX = AssetHandle{};
TypeSafeInt_Const_Expr(AssetLoadingState, uint8_t, 0xFF);
+TypeSafeInt_Const_Expr(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 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{
+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_ALL = AssetType {0xFF};
+
+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;
@@ -30,12 +37,13 @@ struct Asset{
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(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);
+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);
diff --git a/src/entities.cpp b/src/entities.cpp
index 8d4fdb7..9553a89 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -100,7 +100,7 @@ void EntityType_Load(EntityType &et) {
std::filesystem::path gltfPath{asset->basePath};
gltfPath.replace_filename(gltfData->buffers[0].uri);
- AssetHandle modelBinHandle = AM_Register(gltfPath.c_str());
+ AssetHandle modelBinHandle = AM_Register(gltfPath.c_str(), PKE_ASSET_TYPE_UNSET);
if (textureAssetHandle != AssetHandle_MAX) {
const Asset *textureAsset = AM_Get(textureAssetHandle);
diff --git a/src/project.cpp b/src/project.cpp
index 143f5ab..fdde6e0 100644
--- a/src/project.cpp
+++ b/src/project.cpp
@@ -40,6 +40,7 @@ const char* const PKE_PROJ_FILE_ENTITY_TYPE_PHYSICS_STARTING_COLLISION_MASK = "B
const char* const PKE_PROJ_FILE_ASSET_KEY = "Asset::Key: ";
const char* const PKE_PROJ_FILE_ASSET_BASE_PATH = "Asset::BasePath: ";
+const char* const PKE_PROJ_FILE_ASSET_TYPE = "Asset::Type: ";
/*
void Proj_SerializeProjectSettings(std::ofstream &stream) {
@@ -112,6 +113,9 @@ void Proj_SerializeAsset(std::ofstream &stream, const Asset &asset) {
if (asset.basePath != nullptr) {
stream << PKE_PROJ_FILE_ASSET_BASE_PATH << asset.basePath << std::endl;
}
+ if (asset.type != a.type) {
+ stream << PKE_PROJ_FILE_ASSET_TYPE << static_cast<AssetType_T>(asset.type) << std::endl;
+ }
}
/*
@@ -262,9 +266,10 @@ void Proj_ParseAssset(std::ifstream &stream) {
char basePath[256];
basePath[0] = '\0';
basePath[255] = '\0';
+ AssetType at{PKE_ASSET_TYPE_UNSET};
while (stream.getline(projReadLine, projReadLineLength)) {
if (strcmp(projReadLine, PKE_PROJ_FILE_OBJ_END) == 0) {
- AM_Register(keyStr, basePath);
+ AM_Register(keyStr, at, basePath);
return;
}
if (strstr(projReadLine, PKE_PROJ_FILE_ASSET_KEY) != nullptr) {
@@ -278,6 +283,14 @@ void Proj_ParseAssset(std::ifstream &stream) {
strncpy(basePath, projReadLine + prefixLen, strLen + 1);
continue;
}
+ if (strstr(projReadLine, PKE_PROJ_FILE_ASSET_TYPE) != nullptr) {
+ uint64_t prefixLen = strlen(PKE_PROJ_FILE_ASSET_TYPE);
+ AssetType_T val{};
+ STR2NUM_ERROR result = str2num(val, projReadLine + prefixLen);
+ at = AssetType{val};
+ assert(result == STR2NUM_ERROR::SUCCESS);
+ continue;
+ }
}
}