summaryrefslogtreecommitdiff
path: root/src/asset-manager.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2024-11-14 14:46:23 -0500
committerJonathan Bradley <jcb@pikum.xyz>2024-11-14 14:46:23 -0500
commitb2548ba4ce295fcd94a50123fb543fac2ef2bc33 (patch)
tree444a32abb4a094c4fa2f7bc9a95aa86963ad4110 /src/asset-manager.cpp
parentb1d926361b9d613ad712ad161f9a8b7ccab4551d (diff)
add pk.h and major pkmem refactor
Completely replaces the memory module with pkmem pkmem is a newer implementation of the same bucket memory structure. Also includes replacing pkstr.h with pk.h's pkstr
Diffstat (limited to 'src/asset-manager.cpp')
-rw-r--r--src/asset-manager.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/asset-manager.cpp b/src/asset-manager.cpp
index 6ff4600..2784b1e 100644
--- a/src/asset-manager.cpp
+++ b/src/asset-manager.cpp
@@ -9,7 +9,7 @@
#include <fstream>
#include <future>
-const PkeHandleItemIndex_T maxAssetItemsPerBucket = 64;
+const pk_handle_item_index_T maxAssetItemsPerBucket = 64;
BucketContainer<Asset, AssetHandle> Asset_BucketContainer{};
@@ -38,7 +38,7 @@ void AM_Load_Task(Asset &asset) {
return;
}
asset.size = std::filesystem::file_size(asset.basePath);
- asset.ptr = Pke_New(asset.size, 64);
+ asset.ptr = pk_new_base(asset.size, 64);
file.seekg(0, std::ios::beg);
file.read(static_cast<char *>(asset.ptr), asset.size);
file.close();
@@ -77,7 +77,7 @@ AssetHandle AM_Register(AssetKey key, AssetType type, const void *data, int64_t
strncpy(asset.key, key, AssetKeyLength);
asset.basePath = nullptr;
asset.size = size;
- asset.ptr = Pke_New(size, alignment);
+ asset.ptr = pk_new_base(size, alignment);
memcpy(asset.ptr, data, size);
asset.state = PKE_ASSET_LOADING_STATE_LOADED;
asset.type = type;
@@ -95,13 +95,13 @@ AssetHandle AM_Register(AssetKey key, AssetType type, const char *path) {
asset.handle = assetHandle;
strncpy(asset.key, key, AssetKeyLength);
int64_t pathLen = strlen(path);
- auto *copiedPath = Pke_New<char>(pathLen + 1);
+ auto *copiedPath = pk_new<char>(pathLen + 1);
copiedPath[pathLen] = '\0';
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()>>();
+ std::packaged_task<void()> *task = pk_new<std::packaged_task<void()>>();
new (task) std::packaged_task<void()>( [&asset] {
AM_Load_Task(asset);
});
@@ -126,13 +126,13 @@ AssetHandle AM_Register(const char *path, AssetType type) {
new (&asset) Asset{};
asset.handle = assetHandle;
strncpy(asset.key, assetKey, AssetKeyLength);
- auto *copiedPath = Pke_New<char>(pathLen + 1);
+ auto *copiedPath = pk_new<char>(pathLen + 1);
copiedPath[pathLen] = '\0';
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()>>();
+ std::packaged_task<void()> *task = pk_new<std::packaged_task<void()>>();
new (task) std::packaged_task<void()>( [&asset] {
AM_Load_Task(asset);
});
@@ -149,7 +149,7 @@ void AM_Release(AssetHandle assetHandle) {
}
const Asset *AM_Get(AssetHandle assetHandle) {
- auto validationResult = ValidateHandle(assetHandle, Asset_BucketContainer.pkeHandle, maxAssetItemsPerBucket);
+ auto validationResult = pk_handle_validate(assetHandle, Asset_BucketContainer.pkeHandle, maxAssetItemsPerBucket);
assert(validationResult == 0);
auto &asset = Asset_BucketContainer.buckets[assetHandle.bucketIndex][assetHandle.itemIndex];
if (asset.state == PKE_ASSET_LOADING_STATE_LOADED) {
@@ -161,7 +161,7 @@ const Asset *AM_Get(AssetHandle assetHandle) {
return nullptr;
}
asset.state = PKE_ASSET_LOADING_STATE_LOADING;
- std::packaged_task<void()> *task = Pke_New<std::packaged_task<void()>>();
+ std::packaged_task<void()> *task = pk_new<std::packaged_task<void()>>();
new (task) std::packaged_task<void()>( [&asset] {
AM_Load_Task(asset);
});
@@ -174,7 +174,7 @@ const Asset *AM_Get(AssetHandle assetHandle) {
} else {
char buf[256];
buf[255] = '\0';
- snprintf(buf, 255, "[AM_Get] Attempting to retrieve asset: '%.16s' which had a state of '%hhu', but did not have a valid future and thus cannot wait for completion", asset.key, asset.state);
+ snprintf(buf, 255, "[AM_Get] Attempting to retrieve asset: '%.16s' which had a state of '%hhu', but did not have a valid future and thus cannot wait for completion", asset.key, static_cast<AssetLoadingState_T>(asset.state));
throw buf;
}
}
@@ -226,7 +226,7 @@ void AM_DebugPrint() {
printf("\tptr %p\n", asset.ptr);
printf("\tfuture: %i\n", asset.future.valid());
printf("\treferenceCount: %i\n", asset.referenceCount);
- printf("\tAssetLoadingState: %hhu\n", asset.state);
+ printf("\tAssetLoadingState: %hhu\n", static_cast<AssetLoadingState_T>(asset.state));
}
}
}
@@ -238,7 +238,7 @@ void AM_GC() {
if (asset.referenceCount > 0)
continue;
if (asset.ptr != nullptr && asset.ptr != CAFE_BABE(void)) {
- Pke_Delete(asset.ptr, asset.size);
+ pk_delete_base(asset.ptr, asset.size);
}
asset.size = 0;
asset.ptr = CAFE_BABE(void);