summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-03-18 15:35:34 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-03-18 15:35:34 -0400
commit95ee6f829b9ba379e883f4295d96dad5a0c738dd (patch)
treefed2767a8d28828ac13112e6ee96645c579d6281 /src
parentc922bdda1691a2195f691dec72880a6a7e617d6b (diff)
pke: refactor PkeArray, typdef count + store bkt
Diffstat (limited to 'src')
-rw-r--r--src/array.hpp14
-rw-r--r--src/level.cpp2
2 files changed, 10 insertions, 6 deletions
diff --git a/src/array.hpp b/src/array.hpp
index c8a9cb6..883d512 100644
--- a/src/array.hpp
+++ b/src/array.hpp
@@ -7,15 +7,19 @@
#include <cstring>
#include <type_traits>
+typedef uint32_t PkeArray_Count_T;
+
struct PkeArray_Base {
- uint32_t next = 0;
- uint32_t reserved = 0;
+ PkeArray_Count_T next = 0;
+ PkeArray_Count_T reserved = 0;
+ struct pk_membucket *bkt;
};
template<typename D>
struct PkeArray : PkeArray_Base {
using PkeArray_Base::next;
using PkeArray_Base::reserved;
+ using PkeArray_Base::bkt;
D *data = nullptr;
};
@@ -32,7 +36,7 @@ inline void PkeArray_SoftReset(PkeArray_Base *arrIn) {
}
template<typename D>
-inline void PkeArray_Add(PkeArray_Base *arrIn, const D &val, struct pk_membucket *bkt = nullptr) {
+inline void PkeArray_Add(PkeArray_Base *arrIn, const D &val) {
auto *arr = static_cast<PkeArray<D> *>(arrIn);
if (arr->reserved == arr->next) {
long originalCount = arr->reserved;
@@ -44,7 +48,7 @@ inline void PkeArray_Add(PkeArray_Base *arrIn, const D &val, struct pk_membucket
arr->reserved *= 2.5;
diff = arr->reserved - originalCount;
}
- auto *newData = pk_new<D>(arr->reserved, bkt);
+ auto *newData = pk_new<D>(arr->reserved, arr->bkt);
if constexpr (std::is_trivial<D>::value) {
memset(newData + (sizeof(D) * originalCount), 0x00, sizeof(D) * diff);
} else {
@@ -60,7 +64,7 @@ inline void PkeArray_Add(PkeArray_Base *arrIn, const D &val, struct pk_membucket
newData[i] = arr->data[i];
}
}
- pk_delete<D>(arr->data, originalCount, bkt);
+ pk_delete<D>(arr->data, originalCount, arr->bkt);
}
arr->data = newData;
}
diff --git a/src/level.cpp b/src/level.cpp
index 794626d..b7d42ec 100644
--- a/src/level.cpp
+++ b/src/level.cpp
@@ -69,7 +69,7 @@ void PkeLevel_RegisterCamera(LevelHandle levelHandle, CameraHandle cameraHandle)
assert(cameraHandle != CameraHandle_MAX);
PkeLevel *lvl = PkeLevel_Get_Inner(levelHandle);
assert(lvl != nullptr && "Failed to find level by requested LevelHandle");
- PkeArray_Add(&lvl->cameras, cameraHandle, lvl->bkt);
+ PkeArray_Add(&lvl->cameras, cameraHandle);
}
void PkeLevel_Remove(LevelHandle handle) {