Merge branch 'stable' of https://github.com/tobid7/palladium into stable

This commit is contained in:
2026-03-09 20:47:53 +01:00
13 changed files with 233 additions and 15 deletions

View File

@@ -29,6 +29,7 @@ SOFTWARE.
#include <pd/core/hashid.hpp>
#include <pd/core/io.hpp>
#include <pd/core/mat.hpp>
#include <pd/core/pool.hpp>
#include <pd/core/strings.hpp>
#include <pd/core/timer.hpp>
#include <pd/core/timetrace.hpp>

51
include/pd/core/pool.hpp Normal file
View File

@@ -0,0 +1,51 @@
#pragma once
#include <pd/core/common.hpp>
namespace PD {
template <typename T, typename Alloc = std::allocator<T>>
class Pool {
public:
Pool() = default;
~Pool() = default;
static Pool* Create(size_t size) { return new Pool(size); }
void Init(size_t size) {
pPos = 0;
pCap = size;
pPool.resize(size);
}
Pool(const Pool&) = delete;
Pool(Pool&&) = delete;
Pool& operator=(const Pool&) = delete;
Pool& operator=(Pool&&) = delete;
T* Allocate(size_t num = 1) {
if (CheckLimits(num)) return nullptr;
T* ret = &pPool[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;
}
return false;
}
void Reset() { pPos = 0; }
private:
Pool(size_t size) : pCap(size), pPos(0) { pPool.resize(size); }
size_t pCap = 0;
size_t pPos = 0;
std::vector<T, Alloc> pPool;
};
} // namespace PD

View File

@@ -127,4 +127,48 @@ inline const std::string GetCompilerVersion() {
return res.str();
}
} // namespace Strings
class U8Iterator {
public:
explicit U8Iterator(const char* s) : ptr(reinterpret_cast<const u8*>(s)) {}
~U8Iterator() = default;
bool Decode32(u32& ret) {
if (ptr == nullptr || *ptr == 0) return false;
u8 c = *ptr;
if (c < 0x80) {
ret = c;
ptr += 1;
} else if ((c >> 5) == 0x6) {
ret = ((c & 0x1F) << 6) | (ptr[1] & 0x3F);
ptr += 2;
} else if ((c >> 4) == 0xE) {
ret = ((c & 0x0F) << 12) | ((ptr[1] & 0x3F) << 6) | (ptr[2] & 0x3F);
ptr += 3;
} else {
ret = ((c & 0x07) << 18) | ((ptr[1] & 0x3F) << 12) |
((ptr[2] & 0x3F) << 6) | (ptr[3] & 0x3F);
ptr += 4;
}
return true;
}
bool PeekNext32(u32& ret) {
if (ptr + 1 == nullptr || *ptr + 1 == 0) return false;
u8 c = *ptr;
if (c < 0x80) {
ret = c;
} else if ((c >> 5) == 0x6) {
ret = ((c & 0x1F) << 6) | (ptr[1] & 0x3F);
} else if ((c >> 4) == 0xE) {
ret = ((c & 0x0F) << 12) | ((ptr[1] & 0x3F) << 6) | (ptr[2] & 0x3F);
} else {
ret = ((c & 0x07) << 18) | ((ptr[1] & 0x3F) << 12) |
((ptr[2] & 0x3F) << 6) | (ptr[3] & 0x3F);
}
return true;
}
private:
const u8* ptr = nullptr;
};
} // namespace PD

View File

@@ -34,7 +34,7 @@ SOFTWARE.
namespace PD {
namespace UI7 {
class Context;
class Context;
class PD_API Layout {
public:
Layout(const ID& id, IO::Ref io) : ID(id) {