From 68cc809555a4a7f72f38313db7c5bf2dabdffbba Mon Sep 17 00:00:00 2001 From: tobid7 Date: Mon, 9 Mar 2026 20:46:41 +0100 Subject: [PATCH] Fix Drawlist::Clear / Add HashID / FNV Type traits --- include/pd/core/core.hpp | 1 + include/pd/core/fnv.hpp | 17 +++++++++++++ include/pd/core/hashid.hpp | 50 +++++++++++++++++++++++++++++++++++++ include/pd/lithium/rect.hpp | 2 +- source/lithium/drawlist.cpp | 1 + 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 include/pd/core/hashid.hpp diff --git a/include/pd/core/core.hpp b/include/pd/core/core.hpp index f7be474..093e356 100755 --- a/include/pd/core/core.hpp +++ b/include/pd/core/core.hpp @@ -26,6 +26,7 @@ SOFTWARE. #include #include #include +#include #include #include #include diff --git a/include/pd/core/fnv.hpp b/include/pd/core/fnv.hpp index a3278ad..42c371a 100644 --- a/include/pd/core/fnv.hpp +++ b/include/pd/core/fnv.hpp @@ -50,4 +50,21 @@ constexpr u64 FNV1A64(std::string_view str) { } return ret; } + +namespace Detail { +template +struct FNV1A {}; + +template <> +struct FNV1A { + static constexpr u32 Hash(std::string_view str) { return FNV1A32(str); } + static constexpr u32 Hash(const std::string& str) { return FNV1A32(str); } +}; + +template <> +struct FNV1A { + static constexpr u64 Hash(std::string_view str) { return FNV1A64(str); } + static constexpr u64 Hash(const std::string& str) { return FNV1A64(str); } +}; +} // namespace Detail } // namespace PD \ No newline at end of file diff --git a/include/pd/core/hashid.hpp b/include/pd/core/hashid.hpp new file mode 100644 index 0000000..64241ec --- /dev/null +++ b/include/pd/core/hashid.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include +#include + +namespace PD { +template +class HashID { + public: + using __Type = T; + + constexpr HashID() {}; + constexpr HashID(T id) { pID = id; } + HashID(const std::string& name) { + pID = Detail::FNV1A::Hash(name); +#ifdef PD_HASHID_KEEP_STR + pName = name; +#endif + } + constexpr HashID(const char* name) { + pID = Detail::FNV1A::Hash(std::string_view(name)); +#ifdef PD_HASHID_KEEP_STR + pName = name; +#endif + } + ~HashID() {} + + constexpr T Get() { return pID; } + + std::string GetName() const { +#ifdef PD_HASHID_KEEP_STR + return pName; +#else + return std::format("hash({:#08x})", pID); +#endif + } + + operator T() const { return pID; } + // operator std::string() const { return GetName(); } + + private: + T pID; +#ifdef PD_HASHID_KEEP_STR + str pName; +#endif +}; + +using HashID32 = HashID; +using HashID64 = HashID; +} // namespace PD \ No newline at end of file diff --git a/include/pd/lithium/rect.hpp b/include/pd/lithium/rect.hpp index b4953a2..8897521 100755 --- a/include/pd/lithium/rect.hpp +++ b/include/pd/lithium/rect.hpp @@ -131,7 +131,7 @@ class Rect { return *this; } - bool operator==(Rect& r) { return Top == r.Top && Bot == r.Bot; } + bool operator==(const Rect& r) const { return Top == r.Top && Bot == r.Bot; } void SwapVec2XY() { Top.SwapXY(); diff --git a/source/lithium/drawlist.cpp b/source/lithium/drawlist.cpp index 201b666..bff1a9b 100644 --- a/source/lithium/drawlist.cpp +++ b/source/lithium/drawlist.cpp @@ -53,6 +53,7 @@ PD_API void DrawList::Clear() { while (!pClipRects.empty()) { pClipRects.pop(); } + DrawSolid(); } PD_API void DrawList::Merge(DrawList::Ref list) {