Add Drawlist

- Add Pool iterator support
- Add Pool Expandability
- Add Pool::Push
- Add Lithium Maths API
- Remove InitPools
- update spirv-helper
This commit is contained in:
2026-03-19 22:06:58 +01:00
parent e6cd8b7d24
commit afe30a5dbd
13 changed files with 541 additions and 42 deletions

View File

@@ -8,7 +8,7 @@ class Pool {
public:
using value_type = T;
using iterator = T*;
using const_iterator = const iterator*;
using const_iterator = const T*;
Pool() = default;
~Pool() {
@@ -36,21 +36,34 @@ class Pool {
Pool& operator=(Pool&&) = delete;
T* Allocate(size_t num = 1) {
if (CheckLimits(num)) return nullptr;
ExpandIf(num);
T* ret = &pData[pPos];
pPos += num;
return ret;
}
bool CheckLimits(size_t num) {
if ((pPos + num) >= pCap) {
throw std::runtime_error(
std::format("[PD::Pool]: Trying to allocate {} elements but this is "
"going out of range ({}/{})",
num, pPos + num, pCap));
return true;
void Push(const T& elem) {
T* e = Allocate(1);
*e = elem;
}
void ExpandIf(size_t req) {
if ((pPos + req) <= pCap) return;
size_t ncap = std::max(pCap * 2, pPos + req);
T* nu = pAlloc.allocate(ncap);
if (pData) {
for (size_t i = 0; i < pPos; i++) {
std::allocator_traits<Alloc>::construct(
pAlloc, &nu[i], std::move_if_noexcept(pData[i]));
}
pAlloc.deallocate(pData, pCap);
}
return false;
for (size_t i = pPos; i < ncap; i++) {
std::allocator_traits<Alloc>::construct(pAlloc, &nu[i]);
}
PDLOG("Pool::ExpandIf({}): {} -> {}", req, pCap, ncap);
pData = nu;
pCap = ncap;
}
void Reset() {
@@ -67,6 +80,10 @@ class Pool {
size_t capacity() const { return pCap; }
T& at(size_t idx) { return pData[idx]; }
const T& at(size_t idx) const { return pData[idx]; }
iterator begin() { return pData; }
iterator end() { return pData + pPos; }
const_iterator begin() const { return pData; }
const_iterator end() const { return pData + pPos; }
T& operator[](size_t idx) { return at(idx); }
const T& operator[](size_t idx) const { return at(idx); }