summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2022-06-18 16:20:55 +0200
committerreduz <reduzio@gmail.com>2022-06-20 12:54:19 +0200
commit141c3755814cea60888c7ee548c7ce709550b784 (patch)
treecc5045d98995b754097d1dde100f0138033fc735 /scene/resources
parent8e3d9a23aa0a724d3dd25fcf0e8085b5a438c233 (diff)
Clean up Hash Functions
Clean up and do fixes to hash functions and newly introduced murmur3 hashes in #61934 * Clean up usage of murmur3 * Fixed usages of binary murmur3 on floats (this is invalid) * Changed DJB2 to use xor (which seems to be better)
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/canvas_item_material.h2
-rw-r--r--scene/resources/concave_polygon_shape_3d.h4
-rw-r--r--scene/resources/font.cpp8
-rw-r--r--scene/resources/material.cpp2
-rw-r--r--scene/resources/particles_material.h2
-rw-r--r--scene/resources/primitive_meshes.cpp4
-rw-r--r--scene/resources/surface_tool.cpp3
7 files changed, 13 insertions, 12 deletions
diff --git a/scene/resources/canvas_item_material.h b/scene/resources/canvas_item_material.h
index 7c44c125a8..160c67d6b1 100644
--- a/scene/resources/canvas_item_material.h
+++ b/scene/resources/canvas_item_material.h
@@ -64,7 +64,7 @@ private:
uint32_t key = 0;
static uint32_t hash(const MaterialKey &p_key) {
- return hash_djb2_one_32(p_key.key);
+ return hash_murmur3_one_32(p_key.key);
}
bool operator==(const MaterialKey &p_key) const {
return key == p_key.key;
diff --git a/scene/resources/concave_polygon_shape_3d.h b/scene/resources/concave_polygon_shape_3d.h
index 4711e38468..a265590edd 100644
--- a/scene/resources/concave_polygon_shape_3d.h
+++ b/scene/resources/concave_polygon_shape_3d.h
@@ -43,8 +43,8 @@ class ConcavePolygonShape3D : public Shape3D {
Vector3 a;
Vector3 b;
static uint32_t hash(const DrawEdge &p_edge) {
- uint32_t h = hash_djb2_one_32(HashMapHasherDefault::hash(p_edge.a));
- return hash_djb2_one_32(HashMapHasherDefault::hash(p_edge.b), h);
+ uint32_t h = hash_murmur3_one_32(HashMapHasherDefault::hash(p_edge.a));
+ return hash_murmur3_one_32(HashMapHasherDefault::hash(p_edge.b), h);
}
bool operator==(const DrawEdge &p_edge) const {
return (a == p_edge.a && b == p_edge.b);
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index 8a353f4b49..46f23424dd 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -2273,7 +2273,7 @@ Size2 Font::get_string_size(const String &p_text, int p_size, HorizontalAlignmen
uint64_t hash = p_text.hash64();
if (p_alignment == HORIZONTAL_ALIGNMENT_FILL) {
- hash = hash_djb2_one_64(hash_djb2_one_float(p_width), hash);
+ hash = hash_djb2_one_64(hash_murmur3_one_float(p_width), hash);
hash = hash_djb2_one_64(p_flags, hash);
}
hash = hash_djb2_one_64(p_size, hash);
@@ -2297,7 +2297,7 @@ Size2 Font::get_multiline_string_size(const String &p_text, float p_width, int p
}
uint64_t hash = p_text.hash64();
- uint64_t wrp_hash = hash_djb2_one_64(hash_djb2_one_float(p_width), hash);
+ uint64_t wrp_hash = hash_djb2_one_64(hash_murmur3_one_float(p_width), hash);
wrp_hash = hash_djb2_one_64(p_flags, wrp_hash);
wrp_hash = hash_djb2_one_64(p_size, wrp_hash);
@@ -2335,7 +2335,7 @@ void Font::draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_t
uint64_t hash = p_text.hash64();
if (p_alignment == HORIZONTAL_ALIGNMENT_FILL) {
- hash = hash_djb2_one_64(hash_djb2_one_float(p_width), hash);
+ hash = hash_djb2_one_64(hash_murmur3_one_float(p_width), hash);
hash = hash_djb2_one_64(p_flags, hash);
}
hash = hash_djb2_one_64(p_size, hash);
@@ -2374,7 +2374,7 @@ void Font::draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const S
}
uint64_t hash = p_text.hash64();
- uint64_t wrp_hash = hash_djb2_one_64(hash_djb2_one_float(p_width), hash);
+ uint64_t wrp_hash = hash_djb2_one_64(hash_murmur3_one_float(p_width), hash);
wrp_hash = hash_djb2_one_64(p_flags, wrp_hash);
wrp_hash = hash_djb2_one_64(p_size, wrp_hash);
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index fc207d358e..b7a3b677f5 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -2209,7 +2209,7 @@ Ref<Material> BaseMaterial3D::get_material_for_2d(bool p_shaded, bool p_transpar
if (p_fixed_size) {
hash |= 1 << 9;
}
- hash = hash_djb2_one_64(p_filter, hash);
+ hash = hash_murmur3_one_64(p_filter, hash);
if (materials_for_2d.has(hash)) {
if (r_shader_rid) {
diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h
index 24341d964d..af45593f38 100644
--- a/scene/resources/particles_material.h
+++ b/scene/resources/particles_material.h
@@ -110,7 +110,7 @@ private:
uint32_t key = 0;
static uint32_t hash(const MaterialKey &p_key) {
- return hash_djb2_one_32(p_key.key);
+ return hash_murmur3_one_32(p_key.key);
}
bool operator==(const MaterialKey &p_key) const {
diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp
index f8fb51ae42..b2fd8eb895 100644
--- a/scene/resources/primitive_meshes.cpp
+++ b/scene/resources/primitive_meshes.cpp
@@ -2435,7 +2435,7 @@ void TextMesh::_create_mesh_array(Array &p_arr) const {
}
if (glyphs[i].font_rid != RID()) {
uint32_t hash = hash_one_uint64(glyphs[i].font_rid.get_id());
- hash = hash_djb2_one_32(glyphs[i].index, hash);
+ hash = hash_murmur3_one_32(glyphs[i].index, hash);
_generate_glyph_mesh_data(hash, glyphs[i]);
GlyphMeshData &gl_data = cache[hash];
@@ -2494,7 +2494,7 @@ void TextMesh::_create_mesh_array(Array &p_arr) const {
}
if (glyphs[i].font_rid != RID()) {
uint32_t hash = hash_one_uint64(glyphs[i].font_rid.get_id());
- hash = hash_djb2_one_32(glyphs[i].index, hash);
+ hash = hash_murmur3_one_32(glyphs[i].index, hash);
const GlyphMeshData &gl_data = cache[hash];
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index 77d6e3c6f9..9829c7e86b 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -141,7 +141,8 @@ uint32_t SurfaceTool::VertexHasher::hash(const Vertex &p_vtx) {
h = hash_djb2_buffer((const uint8_t *)p_vtx.bones.ptr(), p_vtx.bones.size() * sizeof(int), h);
h = hash_djb2_buffer((const uint8_t *)p_vtx.weights.ptr(), p_vtx.weights.size() * sizeof(float), h);
h = hash_djb2_buffer((const uint8_t *)&p_vtx.custom[0], sizeof(Color) * RS::ARRAY_CUSTOM_COUNT, h);
- h = hash_djb2_one_32(p_vtx.smooth_group, h);
+ h = hash_murmur3_one_32(p_vtx.smooth_group, h);
+ h = hash_fmix32(h);
return h;
}