Fix Drawlist::Clear / Add HashID / FNV Type traits
This commit is contained in:
@@ -26,6 +26,7 @@ SOFTWARE.
|
|||||||
#include <pd/core/bit_util.hpp>
|
#include <pd/core/bit_util.hpp>
|
||||||
#include <pd/core/color.hpp>
|
#include <pd/core/color.hpp>
|
||||||
#include <pd/core/fnv.hpp>
|
#include <pd/core/fnv.hpp>
|
||||||
|
#include <pd/core/hashid.hpp>
|
||||||
#include <pd/core/io.hpp>
|
#include <pd/core/io.hpp>
|
||||||
#include <pd/core/mat.hpp>
|
#include <pd/core/mat.hpp>
|
||||||
#include <pd/core/strings.hpp>
|
#include <pd/core/strings.hpp>
|
||||||
|
|||||||
@@ -50,4 +50,21 @@ constexpr u64 FNV1A64(std::string_view str) {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Detail {
|
||||||
|
template <typename T>
|
||||||
|
struct FNV1A {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct FNV1A<u32> {
|
||||||
|
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<u64> {
|
||||||
|
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
|
} // namespace PD
|
||||||
50
include/pd/core/hashid.hpp
Normal file
50
include/pd/core/hashid.hpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/core/fnv.hpp>
|
||||||
|
#include <pd/core/strings.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
template <typename T>
|
||||||
|
class HashID {
|
||||||
|
public:
|
||||||
|
using __Type = T;
|
||||||
|
|
||||||
|
constexpr HashID() {};
|
||||||
|
constexpr HashID(T id) { pID = id; }
|
||||||
|
HashID(const std::string& name) {
|
||||||
|
pID = Detail::FNV1A<T>::Hash(name);
|
||||||
|
#ifdef PD_HASHID_KEEP_STR
|
||||||
|
pName = name;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
constexpr HashID(const char* name) {
|
||||||
|
pID = Detail::FNV1A<T>::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<u32>;
|
||||||
|
using HashID64 = HashID<u64>;
|
||||||
|
} // namespace PD
|
||||||
@@ -131,7 +131,7 @@ class Rect {
|
|||||||
return *this;
|
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() {
|
void SwapVec2XY() {
|
||||||
Top.SwapXY();
|
Top.SwapXY();
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ PD_API void DrawList::Clear() {
|
|||||||
while (!pClipRects.empty()) {
|
while (!pClipRects.empty()) {
|
||||||
pClipRects.pop();
|
pClipRects.pop();
|
||||||
}
|
}
|
||||||
|
DrawSolid();
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_API void DrawList::Merge(DrawList::Ref list) {
|
PD_API void DrawList::Merge(DrawList::Ref list) {
|
||||||
|
|||||||
Reference in New Issue
Block a user