Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/math/aabb.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/math/plane.h"
#include "core/math/vector3.h"
#include "core/templates/hashfuncs.h"

/**
* AABB (Axis Aligned Bounding Box)
Expand Down Expand Up @@ -131,6 +132,16 @@ struct [[nodiscard]] AABB {
return position + (size * 0.5f);
}

uint32_t hash() const {
uint32_t h = hash_murmur3_one_real(position.x);
h = hash_murmur3_one_real(position.y, h);
h = hash_murmur3_one_real(position.z, h);
h = hash_murmur3_one_real(size.x, h);
h = hash_murmur3_one_real(size.y, h);
h = hash_murmur3_one_real(size.z, h);
return hash_fmix32(h);
}

explicit operator String() const;

AABB() = default;
Expand Down
9 changes: 9 additions & 0 deletions core/math/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#pragma once

#include "core/math/math_funcs.h"
#include "core/templates/hashfuncs.h"

class String;

Expand Down Expand Up @@ -239,6 +240,14 @@ struct [[nodiscard]] Color {
_FORCE_INLINE_ void set_ok_hsl_s(float p_s) { set_ok_hsl(get_ok_hsl_h(), p_s, get_ok_hsl_l(), a); }
_FORCE_INLINE_ void set_ok_hsl_l(float p_l) { set_ok_hsl(get_ok_hsl_h(), get_ok_hsl_s(), p_l, a); }

uint32_t hash() const {
uint32_t h = hash_murmur3_one_float(r);
h = hash_murmur3_one_float(r, h);
h = hash_murmur3_one_float(b, h);
h = hash_murmur3_one_float(a, h);
return hash_fmix32(h);
}

constexpr Color() :
r(0), g(0), b(0), a(1) {}

Expand Down
1 change: 1 addition & 0 deletions core/math/delaunay_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "core/math/aabb.h"
#include "core/math/projection.h"
#include "core/math/vector3.h"
#include "core/math/vector3i.h"
#include "core/templates/a_hash_map.h"
#include "core/templates/list.h"
#include "core/templates/local_vector.h"
Expand Down
2 changes: 2 additions & 0 deletions core/math/geometry_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@

#pragma once

#include "core/math/color.h"
#include "core/math/delaunay_3d.h"
#include "core/math/face3.h"
#include "core/math/vector2.h"
#include "core/templates/local_vector.h"
#include "core/templates/vector.h"

Expand Down
9 changes: 9 additions & 0 deletions core/math/rect2.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/error/error_macros.h"
#include "core/math/vector2.h"
#include "core/templates/hashfuncs.h"

class String;
struct Rect2i;
Expand Down Expand Up @@ -361,6 +362,14 @@ struct [[nodiscard]] Rect2 {
explicit operator String() const;
operator Rect2i() const;

uint32_t hash() const {
uint32_t h = hash_murmur3_one_real(position.x);
h = hash_murmur3_one_real(position.y, h);
h = hash_murmur3_one_real(size.x, h);
h = hash_murmur3_one_real(size.y, h);
return hash_fmix32(h);
}

Rect2() = default;
constexpr Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) :
position(Point2(p_x, p_y)),
Expand Down
9 changes: 9 additions & 0 deletions core/math/rect2i.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/error/error_macros.h"
#include "core/math/vector2i.h"
#include "core/templates/hashfuncs.h"

class String;
struct Rect2;
Expand Down Expand Up @@ -226,6 +227,14 @@ struct [[nodiscard]] Rect2i {
explicit operator String() const;
operator Rect2() const;

uint32_t hash() const {
uint32_t h = hash_murmur3_one_32(uint32_t(position.x));
h = hash_murmur3_one_32(uint32_t(position.y), h);
h = hash_murmur3_one_32(uint32_t(size.x), h);
h = hash_murmur3_one_32(uint32_t(size.y), h);
return hash_fmix32(h);
}

Rect2i() = default;
constexpr Rect2i(int p_x, int p_y, int p_width, int p_height) :
position(Point2i(p_x, p_y)),
Expand Down
7 changes: 7 additions & 0 deletions core/math/vector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/error/error_macros.h"
#include "core/math/math_funcs.h"
#include "core/templates/hashfuncs.h"

class String;
struct Vector2i;
Expand Down Expand Up @@ -190,6 +191,12 @@ struct [[nodiscard]] Vector2 {
explicit operator String() const;
operator Vector2i() const;

uint32_t hash() const {
uint32_t h = hash_murmur3_one_real(x);
h = hash_murmur3_one_real(y, h);
return hash_fmix32(h);
}

// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init)
constexpr Vector2() :
x(0), y(0) {}
Expand Down
7 changes: 7 additions & 0 deletions core/math/vector2i.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/error/error_macros.h"
#include "core/math/math_funcs.h"
#include "core/templates/hashfuncs.h"

class String;
struct Vector2;
Expand Down Expand Up @@ -147,6 +148,12 @@ struct [[nodiscard]] Vector2i {
explicit operator String() const;
operator Vector2() const;

uint32_t hash() const {
uint32_t h = hash_murmur3_one_32(uint32_t(x));
h = hash_murmur3_one_32(uint32_t(y), h);
return hash_fmix32(h);
}

// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init)
constexpr Vector2i() :
x(0), y(0) {}
Expand Down
7 changes: 7 additions & 0 deletions core/math/vector3.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ struct [[nodiscard]] Vector3 {
explicit operator String() const;
operator Vector3i() const;

uint32_t hash() const {
uint32_t h = hash_murmur3_one_real(x);
h = hash_murmur3_one_real(y, h);
h = hash_murmur3_one_real(z, h);
return hash_fmix32(h);
}

constexpr Vector3() :
x(0), y(0), z(0) {}
constexpr Vector3(real_t p_x, real_t p_y, real_t p_z) :
Expand Down
8 changes: 8 additions & 0 deletions core/math/vector3i.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/error/error_macros.h"
#include "core/math/math_funcs.h"
#include "core/templates/hashfuncs.h"

class String;
struct Vector3;
Expand Down Expand Up @@ -140,6 +141,13 @@ struct [[nodiscard]] Vector3i {
explicit operator String() const;
operator Vector3() const;

uint32_t hash() const {
uint32_t h = hash_murmur3_one_32(uint32_t(x));
h = hash_murmur3_one_32(uint32_t(y), h);
h = hash_murmur3_one_32(uint32_t(z), h);
return hash_fmix32(h);
}

constexpr Vector3i() :
x(0), y(0), z(0) {}
constexpr Vector3i(int32_t p_x, int32_t p_y, int32_t p_z) :
Expand Down
9 changes: 9 additions & 0 deletions core/math/vector4.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/error/error_macros.h"
#include "core/math/math_defs.h"
#include "core/templates/hashfuncs.h"
#include "core/typedefs.h"

class String;
Expand Down Expand Up @@ -146,6 +147,14 @@ struct [[nodiscard]] Vector4 {
explicit operator String() const;
operator Vector4i() const;

uint32_t hash() const {
uint32_t h = hash_murmur3_one_real(x);
h = hash_murmur3_one_real(y, h);
h = hash_murmur3_one_real(z, h);
h = hash_murmur3_one_real(w, h);
return hash_fmix32(h);
}

constexpr Vector4() :
x(0), y(0), z(0), w(0) {}
constexpr Vector4(real_t p_x, real_t p_y, real_t p_z, real_t p_w) :
Expand Down
9 changes: 9 additions & 0 deletions core/math/vector4i.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/error/error_macros.h"
#include "core/math/math_funcs.h"
#include "core/templates/hashfuncs.h"

class String;
struct Vector4;
Expand Down Expand Up @@ -135,6 +136,14 @@ struct [[nodiscard]] Vector4i {
explicit operator String() const;
operator Vector4() const;

uint32_t hash() const {
uint32_t h = hash_murmur3_one_32(uint32_t(x));
h = hash_murmur3_one_32(uint32_t(y), h);
h = hash_murmur3_one_32(uint32_t(z), h);
h = hash_murmur3_one_32(uint32_t(w), h);
return hash_fmix32(h);
}

constexpr Vector4i() :
x(0), y(0), z(0), w(0) {}
Vector4i(const Vector4 &p_vec4);
Expand Down
2 changes: 1 addition & 1 deletion core/object/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ class Object {
};

MethodInfo user;
HashMap<Callable, Slot, HashableHasher<Callable>> slot_map;
HashMap<Callable, Slot> slot_map;
bool removable = false;
};
friend struct _ObjectSignalLock;
Expand Down
3 changes: 3 additions & 0 deletions core/object/object_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#pragma once

#include "core/templates/hashfuncs.h"
#include "core/typedefs.h"

// Class to store an object ID (int64)
Expand All @@ -54,6 +55,8 @@ class ObjectID {
_ALWAYS_INLINE_ void operator=(int64_t p_int64) { id = p_int64; }
_ALWAYS_INLINE_ void operator=(uint64_t p_uint64) { id = p_uint64; }

uint32_t hash() const { return HashMapHasherDefault::hash(id); }

_ALWAYS_INLINE_ ObjectID() {}
_ALWAYS_INLINE_ explicit ObjectID(const uint64_t p_id) { id = p_id; }
_ALWAYS_INLINE_ explicit ObjectID(const int64_t p_id) { id = p_id; }
Expand Down
2 changes: 2 additions & 0 deletions core/object/ref_counted.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ class Ref {
ref(memnew(T(p_params...)));
}

uint32_t hash() const { return HashMapHasherDefault::hash(reference); }

Ref() = default;

~Ref() {
Expand Down
3 changes: 3 additions & 0 deletions core/string/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "core/string/char_utils.h" // IWYU pragma: export
#include "core/templates/cowdata.h"
#include "core/templates/hashfuncs.h"
#include "core/templates/vector.h"
#include "core/typedefs.h"
#include "core/variant/array.h"
Expand Down Expand Up @@ -232,6 +233,8 @@ class [[nodiscard]] CharStringT {
return *this;
}

uint32_t hash() const { return hash_djb2(get_data()); }

protected:
void copy_from(const T *p_cstr) {
if (!p_cstr) {
Expand Down
4 changes: 4 additions & 0 deletions core/templates/a_hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@

#pragma once

#include "core/string/ustring.h"
#include "core/templates/hash_map.h"

class StringName;
class Variant;

/**
* An array-based implementation of a hash map. It is very efficient in terms of performance and
* memory usage. Works like a dynamic array, adding elements to the end of the array, and
Expand Down
Loading