From b2548ba4ce295fcd94a50123fb543fac2ef2bc33 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Thu, 14 Nov 2024 14:46:23 -0500 Subject: 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 --- src/asset-manager.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/asset-manager.cpp') 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 #include -const PkeHandleItemIndex_T maxAssetItemsPerBucket = 64; +const pk_handle_item_index_T maxAssetItemsPerBucket = 64; BucketContainer 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(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(pathLen + 1); + auto *copiedPath = pk_new(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 *task = Pke_New>(); + std::packaged_task *task = pk_new>(); new (task) std::packaged_task( [&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(pathLen + 1); + auto *copiedPath = pk_new(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 *task = Pke_New>(); + std::packaged_task *task = pk_new>(); new (task) std::packaged_task( [&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 *task = Pke_New>(); + std::packaged_task *task = pk_new>(); new (task) std::packaged_task( [&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(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(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); -- cgit v1.2.3