summaryrefslogtreecommitdiff
path: root/modules/raycast
diff options
context:
space:
mode:
Diffstat (limited to 'modules/raycast')
-rw-r--r--modules/raycast/lightmap_raycaster.cpp10
-rw-r--r--modules/raycast/lightmap_raycaster.h6
-rw-r--r--modules/raycast/raycast_occlusion_cull.cpp27
-rw-r--r--modules/raycast/raycast_occlusion_cull.h20
-rw-r--r--modules/raycast/register_types.cpp12
-rw-r--r--modules/raycast/register_types.h6
-rw-r--r--modules/raycast/static_raycaster.cpp10
-rw-r--r--modules/raycast/static_raycaster.h4
8 files changed, 52 insertions, 43 deletions
diff --git a/modules/raycast/lightmap_raycaster.cpp b/modules/raycast/lightmap_raycaster.cpp
index ecc256bff9..9b35b5616e 100644
--- a/modules/raycast/lightmap_raycaster.cpp
+++ b/modules/raycast/lightmap_raycaster.cpp
@@ -152,17 +152,17 @@ void LightmapRaycasterEmbree::commit() {
rtcCommitScene(embree_scene);
}
-void LightmapRaycasterEmbree::set_mesh_filter(const Set<int> &p_mesh_ids) {
- for (Set<int>::Element *E = p_mesh_ids.front(); E; E = E->next()) {
- rtcDisableGeometry(rtcGetGeometry(embree_scene, E->get()));
+void LightmapRaycasterEmbree::set_mesh_filter(const HashSet<int> &p_mesh_ids) {
+ for (const int &E : p_mesh_ids) {
+ rtcDisableGeometry(rtcGetGeometry(embree_scene, E));
}
rtcCommitScene(embree_scene);
filter_meshes = p_mesh_ids;
}
void LightmapRaycasterEmbree::clear_mesh_filter() {
- for (Set<int>::Element *E = filter_meshes.front(); E; E = E->next()) {
- rtcEnableGeometry(rtcGetGeometry(embree_scene, E->get()));
+ for (const int &E : filter_meshes) {
+ rtcEnableGeometry(rtcGetGeometry(embree_scene, E));
}
rtcCommitScene(embree_scene);
filter_meshes.clear();
diff --git a/modules/raycast/lightmap_raycaster.h b/modules/raycast/lightmap_raycaster.h
index c420e617e5..4266b46ea8 100644
--- a/modules/raycast/lightmap_raycaster.h
+++ b/modules/raycast/lightmap_raycaster.h
@@ -52,8 +52,8 @@ private:
static void filter_function(const struct RTCFilterFunctionNArguments *p_args);
- Map<unsigned int, AlphaTextureData> alpha_textures;
- Set<int> filter_meshes;
+ HashMap<unsigned int, AlphaTextureData> alpha_textures;
+ HashSet<int> filter_meshes;
public:
virtual bool intersect(Ray &p_ray) override;
@@ -64,7 +64,7 @@ public:
virtual void set_mesh_alpha_texture(Ref<Image> p_alpha_texture, unsigned int p_id) override;
virtual void commit() override;
- virtual void set_mesh_filter(const Set<int> &p_mesh_ids) override;
+ virtual void set_mesh_filter(const HashSet<int> &p_mesh_ids) override;
virtual void clear_mesh_filter() override;
static LightmapRaycaster *create_embree_raycaster();
diff --git a/modules/raycast/raycast_occlusion_cull.cpp b/modules/raycast/raycast_occlusion_cull.cpp
index 2e0d17fb28..89e75f774e 100644
--- a/modules/raycast/raycast_occlusion_cull.cpp
+++ b/modules/raycast/raycast_occlusion_cull.cpp
@@ -85,7 +85,7 @@ void RaycastOcclusionCull::RaycastHZBuffer::update_camera_rays(const Transform3D
td.z_near = p_cam_projection.get_z_near();
td.z_far = p_cam_projection.get_z_far() * 1.05f;
td.camera_pos = p_cam_transform.origin;
- td.camera_dir = -p_cam_transform.basis.get_axis(2);
+ td.camera_dir = -p_cam_transform.basis.get_column(2);
td.camera_orthogonal = p_cam_orthogonal;
CameraMatrix inv_camera_matrix = p_cam_projection.inverse();
@@ -223,9 +223,9 @@ void RaycastOcclusionCull::occluder_set_mesh(RID p_occluder, const PackedVector3
occluder->vertices = p_vertices;
occluder->indices = p_indices;
- for (Set<InstanceID>::Element *E = occluder->users.front(); E; E = E->next()) {
- RID scenario_rid = E->get().scenario;
- RID instance_rid = E->get().instance;
+ for (const InstanceID &E : occluder->users) {
+ RID scenario_rid = E.scenario;
+ RID instance_rid = E.instance;
ERR_CONTINUE(!scenarios.has(scenario_rid));
Scenario &scenario = scenarios[scenario_rid];
ERR_CONTINUE(!scenario.instances.has(instance_rid));
@@ -454,10 +454,9 @@ bool RaycastOcclusionCull::Scenario::update(ThreadWorkPool &p_thread_pool) {
next_scene = rtcNewScene(raycast_singleton->ebr_device);
rtcSetSceneBuildQuality(next_scene, RTCBuildQuality(raycast_singleton->build_quality));
- const RID *inst_rid = nullptr;
- while ((inst_rid = instances.next(inst_rid))) {
- OccluderInstance *occ_inst = instances.getptr(*inst_rid);
- Occluder *occ = raycast_singleton->occluder_owner.get_or_null(occ_inst->occluder);
+ for (const KeyValue<RID, OccluderInstance> &E : instances) {
+ const OccluderInstance *occ_inst = &E.value;
+ const Occluder *occ = raycast_singleton->occluder_owner.get_or_null(occ_inst->occluder);
if (!occ || !occ_inst->enabled) {
continue;
@@ -548,7 +547,7 @@ void RaycastOcclusionCull::buffer_update(RID p_buffer, const Transform3D &p_cam_
buffer.update_camera_rays(p_cam_transform, p_cam_projection, p_cam_orthogonal, p_thread_pool);
scenario.raycast(buffer.camera_rays, buffer.camera_ray_masks.ptr(), buffer.camera_rays_tile_count, p_thread_pool);
- buffer.sort_rays(-p_cam_transform.basis.get_axis(2), p_cam_orthogonal);
+ buffer.sort_rays(-p_cam_transform.basis.get_column(2), p_cam_orthogonal);
buffer.update_mips();
}
@@ -573,9 +572,8 @@ void RaycastOcclusionCull::set_build_quality(RS::ViewportOcclusionCullingBuildQu
build_quality = p_quality;
- const RID *scenario_rid = nullptr;
- while ((scenario_rid = scenarios.next(scenario_rid))) {
- scenarios[*scenario_rid].dirty = true;
+ for (KeyValue<RID, Scenario> &K : scenarios) {
+ K.value.dirty = true;
}
}
@@ -596,9 +594,8 @@ RaycastOcclusionCull::RaycastOcclusionCull() {
}
RaycastOcclusionCull::~RaycastOcclusionCull() {
- const RID *scenario_rid = nullptr;
- while ((scenario_rid = scenarios.next(scenario_rid))) {
- Scenario &scenario = scenarios[*scenario_rid];
+ for (KeyValue<RID, Scenario> &K : scenarios) {
+ Scenario &scenario = K.value;
if (scenario.commit_thread) {
scenario.commit_thread->wait_to_finish();
memdelete(scenario.commit_thread);
diff --git a/modules/raycast/raycast_occlusion_cull.h b/modules/raycast/raycast_occlusion_cull.h
index a22e52dd17..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;
- Set<InstanceID> users;
+ HashSet<InstanceID, InstanceID> users;
};
struct OccluderInstance {
@@ -115,7 +117,7 @@ private:
struct Scenario {
struct RaycastThreadData {
- CameraRayTile *rays;
+ CameraRayTile *rays = nullptr;
const uint32_t *masks;
};
@@ -124,7 +126,7 @@ private:
uint32_t vertex_count;
Transform3D xform;
const Vector3 *read;
- Vector3 *write;
+ Vector3 *write = nullptr;
};
Thread *commit_thread = nullptr;
@@ -136,7 +138,7 @@ private:
int current_scene_idx = 0;
HashMap<RID, OccluderInstance> instances;
- Set<RID> dirty_instances; // To avoid duplicates
+ HashSet<RID> dirty_instances; // To avoid duplicates
LocalVector<RID> dirty_instances_array; // To iterate and split into threads
LocalVector<RID> removed_instances;
diff --git a/modules/raycast/register_types.cpp b/modules/raycast/register_types.cpp
index 053039a85b..42de1d971d 100644
--- a/modules/raycast/register_types.cpp
+++ b/modules/raycast/register_types.cpp
@@ -36,7 +36,11 @@
RaycastOcclusionCull *raycast_occlusion_cull = nullptr;
-void register_raycast_types() {
+void initialize_raycast_module(ModuleInitializationLevel p_level) {
+ if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
+ return;
+ }
+
#ifdef TOOLS_ENABLED
LightmapRaycasterEmbree::make_default_raycaster();
StaticRaycasterEmbree::make_default_raycaster();
@@ -44,7 +48,11 @@ void register_raycast_types() {
raycast_occlusion_cull = memnew(RaycastOcclusionCull);
}
-void unregister_raycast_types() {
+void uninitialize_raycast_module(ModuleInitializationLevel p_level) {
+ if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
+ return;
+ }
+
if (raycast_occlusion_cull) {
memdelete(raycast_occlusion_cull);
}
diff --git a/modules/raycast/register_types.h b/modules/raycast/register_types.h
index 0abc5eb63a..a917285390 100644
--- a/modules/raycast/register_types.h
+++ b/modules/raycast/register_types.h
@@ -28,5 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-void register_raycast_types();
-void unregister_raycast_types();
+#include "modules/register_module_types.h"
+
+void initialize_raycast_module(ModuleInitializationLevel p_level);
+void uninitialize_raycast_module(ModuleInitializationLevel p_level);
diff --git a/modules/raycast/static_raycaster.cpp b/modules/raycast/static_raycaster.cpp
index 9df6d5ff43..7659eea27f 100644
--- a/modules/raycast/static_raycaster.cpp
+++ b/modules/raycast/static_raycaster.cpp
@@ -94,17 +94,17 @@ void StaticRaycasterEmbree::commit() {
rtcCommitScene(embree_scene);
}
-void StaticRaycasterEmbree::set_mesh_filter(const Set<int> &p_mesh_ids) {
- for (Set<int>::Element *E = p_mesh_ids.front(); E; E = E->next()) {
- rtcDisableGeometry(rtcGetGeometry(embree_scene, E->get()));
+void StaticRaycasterEmbree::set_mesh_filter(const HashSet<int> &p_mesh_ids) {
+ for (const int &E : p_mesh_ids) {
+ rtcDisableGeometry(rtcGetGeometry(embree_scene, E));
}
rtcCommitScene(embree_scene);
filter_meshes = p_mesh_ids;
}
void StaticRaycasterEmbree::clear_mesh_filter() {
- for (Set<int>::Element *E = filter_meshes.front(); E; E = E->next()) {
- rtcEnableGeometry(rtcGetGeometry(embree_scene, E->get()));
+ for (const int &E : filter_meshes) {
+ rtcEnableGeometry(rtcGetGeometry(embree_scene, E));
}
rtcCommitScene(embree_scene);
filter_meshes.clear();
diff --git a/modules/raycast/static_raycaster.h b/modules/raycast/static_raycaster.h
index cce19ba60d..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;
- Set<int> filter_meshes;
+ HashSet<int> 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 Set<int> &p_mesh_ids) override;
+ virtual void set_mesh_filter(const HashSet<int> &p_mesh_ids) override;
virtual void clear_mesh_filter() override;
static StaticRaycaster *create_embree_raycaster();