From 45af29da8095af16729955117a165d23e77cd740 Mon Sep 17 00:00:00 2001 From: reduz Date: Thu, 19 May 2022 17:00:06 +0200 Subject: Add a new HashSet template * Intended to replace RBSet in most cases. * Optimized for iteration speed --- modules/raycast/lightmap_raycaster.cpp | 2 +- modules/raycast/lightmap_raycaster.h | 4 ++-- modules/raycast/raycast_occlusion_cull.h | 16 +++++++++------- modules/raycast/static_raycaster.cpp | 2 +- modules/raycast/static_raycaster.h | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) (limited to 'modules/raycast') diff --git a/modules/raycast/lightmap_raycaster.cpp b/modules/raycast/lightmap_raycaster.cpp index fc9ac416b7..9b35b5616e 100644 --- a/modules/raycast/lightmap_raycaster.cpp +++ b/modules/raycast/lightmap_raycaster.cpp @@ -152,7 +152,7 @@ void LightmapRaycasterEmbree::commit() { rtcCommitScene(embree_scene); } -void LightmapRaycasterEmbree::set_mesh_filter(const RBSet &p_mesh_ids) { +void LightmapRaycasterEmbree::set_mesh_filter(const HashSet &p_mesh_ids) { for (const int &E : p_mesh_ids) { rtcDisableGeometry(rtcGetGeometry(embree_scene, E)); } diff --git a/modules/raycast/lightmap_raycaster.h b/modules/raycast/lightmap_raycaster.h index 4c52758fd8..4266b46ea8 100644 --- a/modules/raycast/lightmap_raycaster.h +++ b/modules/raycast/lightmap_raycaster.h @@ -53,7 +53,7 @@ private: static void filter_function(const struct RTCFilterFunctionNArguments *p_args); HashMap alpha_textures; - RBSet filter_meshes; + HashSet filter_meshes; public: virtual bool intersect(Ray &p_ray) override; @@ -64,7 +64,7 @@ public: virtual void set_mesh_alpha_texture(Ref p_alpha_texture, unsigned int p_id) override; virtual void commit() override; - virtual void set_mesh_filter(const RBSet &p_mesh_ids) override; + virtual void set_mesh_filter(const HashSet &p_mesh_ids) override; virtual void clear_mesh_filter() override; static LightmapRaycaster *create_embree_raycaster(); diff --git a/modules/raycast/raycast_occlusion_cull.h b/modules/raycast/raycast_occlusion_cull.h index 779f6fb3c4..4474031991 100644 --- a/modules/raycast/raycast_occlusion_cull.h +++ b/modules/raycast/raycast_occlusion_cull.h @@ -86,11 +86,13 @@ private: RID scenario; RID instance; - bool operator<(const InstanceID &rhs) const { - if (instance == rhs.instance) { - return rhs.scenario < scenario; - } - return instance < rhs.instance; + static uint32_t hash(const InstanceID &p_ins) { + uint32_t h = hash_djb2_one_64(p_ins.scenario.get_id()); + return hash_djb2_one_64(p_ins.instance.get_id(), h); + } + bool operator==(const InstanceID &rhs) const { + return instance == rhs.instance && rhs.scenario == scenario; + ; } InstanceID() {} @@ -101,7 +103,7 @@ private: struct Occluder { PackedVector3Array vertices; PackedInt32Array indices; - RBSet users; + HashSet users; }; struct OccluderInstance { @@ -136,7 +138,7 @@ private: int current_scene_idx = 0; HashMap instances; - RBSet dirty_instances; // To avoid duplicates + HashSet dirty_instances; // To avoid duplicates LocalVector dirty_instances_array; // To iterate and split into threads LocalVector removed_instances; diff --git a/modules/raycast/static_raycaster.cpp b/modules/raycast/static_raycaster.cpp index 5d2dedf1a4..7659eea27f 100644 --- a/modules/raycast/static_raycaster.cpp +++ b/modules/raycast/static_raycaster.cpp @@ -94,7 +94,7 @@ void StaticRaycasterEmbree::commit() { rtcCommitScene(embree_scene); } -void StaticRaycasterEmbree::set_mesh_filter(const RBSet &p_mesh_ids) { +void StaticRaycasterEmbree::set_mesh_filter(const HashSet &p_mesh_ids) { for (const int &E : p_mesh_ids) { rtcDisableGeometry(rtcGetGeometry(embree_scene, E)); } diff --git a/modules/raycast/static_raycaster.h b/modules/raycast/static_raycaster.h index b52b5bccfc..e2909f9b56 100644 --- a/modules/raycast/static_raycaster.h +++ b/modules/raycast/static_raycaster.h @@ -41,7 +41,7 @@ private: static RTCDevice embree_device; RTCScene embree_scene; - RBSet filter_meshes; + HashSet filter_meshes; public: virtual bool intersect(Ray &p_ray) override; @@ -50,7 +50,7 @@ public: virtual void add_mesh(const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices, unsigned int p_id) override; virtual void commit() override; - virtual void set_mesh_filter(const RBSet &p_mesh_ids) override; + virtual void set_mesh_filter(const HashSet &p_mesh_ids) override; virtual void clear_mesh_filter() override; static StaticRaycaster *create_embree_raycaster(); -- cgit v1.2.3