mirror of
https://github.com/godotengine/godot-cpp.git
synced 2025-12-31 01:48:45 +03:00
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include <godot_cpp/core/math.hpp>
|
#include <godot_cpp/core/math.hpp>
|
||||||
#include <godot_cpp/core/object.hpp>
|
#include <godot_cpp/core/object.hpp>
|
||||||
|
#include <godot_cpp/templates/pair.hpp>
|
||||||
#include <godot_cpp/variant/aabb.hpp>
|
#include <godot_cpp/variant/aabb.hpp>
|
||||||
#include <godot_cpp/variant/node_path.hpp>
|
#include <godot_cpp/variant/node_path.hpp>
|
||||||
#include <godot_cpp/variant/rect2.hpp>
|
#include <godot_cpp/variant/rect2.hpp>
|
||||||
@@ -319,6 +320,13 @@ struct HashMapHasherDefault {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
static _FORCE_INLINE_ uint32_t hash(const Ref<T> &p_ref) { return hash_one_uint64((uint64_t)p_ref.operator->()); }
|
static _FORCE_INLINE_ uint32_t hash(const Ref<T> &p_ref) { return hash_one_uint64((uint64_t)p_ref.operator->()); }
|
||||||
|
|
||||||
|
template <typename F, typename S>
|
||||||
|
static _FORCE_INLINE_ uint32_t hash(const Pair<F, S> &p_pair) {
|
||||||
|
uint64_t h1 = hash(p_pair.first);
|
||||||
|
uint64_t h2 = hash(p_pair.second);
|
||||||
|
return hash_one_uint64((h1 << 32) | h2);
|
||||||
|
}
|
||||||
|
|
||||||
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
|
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
|
||||||
static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
|
static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
|
||||||
static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar) { return hash_fmix32(uint32_t(p_wchar)); }
|
static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar) { return hash_fmix32(uint32_t(p_wchar)); }
|
||||||
@@ -329,6 +337,7 @@ struct HashMapHasherDefault {
|
|||||||
static _FORCE_INLINE_ uint32_t hash(const StringName &p_string_name) { return p_string_name.hash(); }
|
static _FORCE_INLINE_ uint32_t hash(const StringName &p_string_name) { return p_string_name.hash(); }
|
||||||
static _FORCE_INLINE_ uint32_t hash(const NodePath &p_path) { return p_path.hash(); }
|
static _FORCE_INLINE_ uint32_t hash(const NodePath &p_path) { return p_path.hash(); }
|
||||||
static _FORCE_INLINE_ uint32_t hash(const ObjectID &p_id) { return hash_one_uint64(p_id); }
|
static _FORCE_INLINE_ uint32_t hash(const ObjectID &p_id) { return hash_one_uint64(p_id); }
|
||||||
|
static _FORCE_INLINE_ uint32_t hash(const Callable &p_callable) { return p_callable.hash(); }
|
||||||
|
|
||||||
static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }
|
static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }
|
||||||
static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash_one_uint64(uint64_t(p_int)); }
|
static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash_one_uint64(uint64_t(p_int)); }
|
||||||
@@ -376,6 +385,13 @@ struct HashMapHasherDefault {
|
|||||||
h = hash_murmur3_one_real(p_vec.w, h);
|
h = hash_murmur3_one_real(p_vec.w, h);
|
||||||
return hash_fmix32(h);
|
return hash_fmix32(h);
|
||||||
}
|
}
|
||||||
|
static _FORCE_INLINE_ uint32_t hash(const Color &p_vec) {
|
||||||
|
uint32_t h = hash_murmur3_one_float(p_vec.r);
|
||||||
|
h = hash_murmur3_one_float(p_vec.g, h);
|
||||||
|
h = hash_murmur3_one_float(p_vec.b, h);
|
||||||
|
h = hash_murmur3_one_float(p_vec.a, h);
|
||||||
|
return hash_fmix32(h);
|
||||||
|
}
|
||||||
static _FORCE_INLINE_ uint32_t hash(const Rect2i &p_rect) {
|
static _FORCE_INLINE_ uint32_t hash(const Rect2i &p_rect) {
|
||||||
uint32_t h = hash_murmur3_one_32(uint32_t(p_rect.position.x));
|
uint32_t h = hash_murmur3_one_32(uint32_t(p_rect.position.x));
|
||||||
h = hash_murmur3_one_32(uint32_t(p_rect.position.y), h);
|
h = hash_murmur3_one_32(uint32_t(p_rect.position.y), h);
|
||||||
|
|||||||
@@ -30,86 +30,70 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <godot_cpp/templates/hashfuncs.hpp>
|
#include <godot_cpp/core/defs.hpp>
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
template <typename F, typename S>
|
template <typename F, typename S>
|
||||||
struct Pair {
|
struct Pair {
|
||||||
F first;
|
F first{};
|
||||||
S second;
|
S second{};
|
||||||
|
|
||||||
Pair() :
|
constexpr Pair() = default;
|
||||||
first(),
|
constexpr Pair(const F &p_first, const S &p_second) :
|
||||||
second() {
|
first(p_first), second(p_second) {}
|
||||||
}
|
|
||||||
|
|
||||||
Pair(F p_first, const S &p_second) :
|
constexpr bool operator==(const Pair &p_other) const { return first == p_other.first && second == p_other.second; }
|
||||||
first(p_first),
|
constexpr bool operator!=(const Pair &p_other) const { return first != p_other.first || second != p_other.second; }
|
||||||
second(p_second) {
|
constexpr bool operator<(const Pair &p_other) const { return first == p_other.first ? (second < p_other.second) : (first < p_other.first); }
|
||||||
}
|
constexpr bool operator<=(const Pair &p_other) const { return first == p_other.first ? (second <= p_other.second) : (first < p_other.first); }
|
||||||
|
constexpr bool operator>(const Pair &p_other) const { return first == p_other.first ? (second > p_other.second) : (first > p_other.first); }
|
||||||
|
constexpr bool operator>=(const Pair &p_other) const { return first == p_other.first ? (second >= p_other.second) : (first > p_other.first); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename F, typename S>
|
|
||||||
bool operator==(const Pair<F, S> &pair, const Pair<F, S> &other) {
|
|
||||||
return (pair.first == other.first) && (pair.second == other.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename F, typename S>
|
|
||||||
bool operator!=(const Pair<F, S> &pair, const Pair<F, S> &other) {
|
|
||||||
return (pair.first != other.first) || (pair.second != other.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename F, typename S>
|
template <typename F, typename S>
|
||||||
struct PairSort {
|
struct PairSort {
|
||||||
bool operator()(const Pair<F, S> &A, const Pair<F, S> &B) const {
|
constexpr bool operator()(const Pair<F, S> &p_lhs, const Pair<F, S> &p_rhs) const {
|
||||||
if (A.first != B.first) {
|
return p_lhs < p_rhs;
|
||||||
return A.first < B.first;
|
|
||||||
}
|
|
||||||
return A.second < B.second;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Pair is zero-constructible if and only if both constrained types are zero-constructible.
|
||||||
template <typename F, typename S>
|
template <typename F, typename S>
|
||||||
struct PairHash {
|
struct is_zero_constructible<Pair<F, S>> : std::conjunction<is_zero_constructible<F>, is_zero_constructible<S>> {};
|
||||||
static uint32_t hash(const Pair<F, S> &P) {
|
|
||||||
uint64_t h1 = HashMapHasherDefault::hash(P.first);
|
|
||||||
uint64_t h2 = HashMapHasherDefault::hash(P.second);
|
|
||||||
return hash_one_uint64((h1 << 32) | h2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V>
|
||||||
struct KeyValue {
|
struct KeyValue {
|
||||||
const K key;
|
const K key{};
|
||||||
V value;
|
V value{};
|
||||||
|
|
||||||
void operator=(const KeyValue &p_kv) = delete;
|
KeyValue &operator=(const KeyValue &p_kv) = delete;
|
||||||
_FORCE_INLINE_ KeyValue(const KeyValue &p_kv) :
|
KeyValue &operator=(KeyValue &&p_kv) = delete;
|
||||||
key(p_kv.key),
|
|
||||||
value(p_kv.value) {
|
constexpr KeyValue(const KeyValue &p_kv) = default;
|
||||||
}
|
constexpr KeyValue(KeyValue &&p_kv) = default;
|
||||||
_FORCE_INLINE_ KeyValue(const K &p_key, const V &p_value) :
|
constexpr KeyValue(const K &p_key, const V &p_value) :
|
||||||
key(p_key),
|
key(p_key), value(p_value) {}
|
||||||
value(p_value) {
|
constexpr KeyValue(const Pair<K, V> &p_pair) :
|
||||||
}
|
key(p_pair.first), value(p_pair.second) {}
|
||||||
|
|
||||||
|
constexpr bool operator==(const KeyValue &p_other) const { return key == p_other.key && value == p_other.value; }
|
||||||
|
constexpr bool operator!=(const KeyValue &p_other) const { return key != p_other.key || value != p_other.value; }
|
||||||
|
constexpr bool operator<(const KeyValue &p_other) const { return key == p_other.key ? (value < p_other.value) : (key < p_other.key); }
|
||||||
|
constexpr bool operator<=(const KeyValue &p_other) const { return key == p_other.key ? (value <= p_other.value) : (key < p_other.key); }
|
||||||
|
constexpr bool operator>(const KeyValue &p_other) const { return key == p_other.key ? (value > p_other.value) : (key > p_other.key); }
|
||||||
|
constexpr bool operator>=(const KeyValue &p_other) const { return key == p_other.key ? (value >= p_other.value) : (key > p_other.key); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
|
||||||
bool operator==(const KeyValue<K, V> &pair, const KeyValue<K, V> &other) {
|
|
||||||
return (pair.key == other.key) && (pair.value == other.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename K, typename V>
|
|
||||||
bool operator!=(const KeyValue<K, V> &pair, const KeyValue<K, V> &other) {
|
|
||||||
return (pair.key != other.key) || (pair.value != other.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V>
|
||||||
struct KeyValueSort {
|
struct KeyValueSort {
|
||||||
bool operator()(const KeyValue<K, V> &A, const KeyValue<K, V> &B) const {
|
constexpr bool operator()(const KeyValue<K, V> &p_lhs, const KeyValue<K, V> &p_rhs) const {
|
||||||
return A.key < B.key;
|
return p_lhs.key < p_rhs.key;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// KeyValue is zero-constructible if and only if both constrained types are zero-constructible.
|
||||||
|
template <typename K, typename V>
|
||||||
|
struct is_zero_constructible<KeyValue<K, V>> : std::conjunction<is_zero_constructible<K>, is_zero_constructible<V>> {};
|
||||||
|
|
||||||
} // namespace godot
|
} // namespace godot
|
||||||
|
|||||||
Reference in New Issue
Block a user