aboutsummaryrefslogtreecommitdiff
path: root/src/pipeline
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2020-10-06 11:22:51 +0200
committerCrozet Sébastien <developer@crozet.re>2020-10-06 11:22:51 +0200
commit17c31bcc57ec8d037ba6cc6ab5f7cfb6fa4bb09b (patch)
tree962e88b926b4ee085cd7b5df6ad03543d19f7917 /src/pipeline
parentcf86ee40a199dc84f7b8dd045e57b3a15bca79fb (diff)
downloadrapier-17c31bcc57ec8d037ba6cc6ab5f7cfb6fa4bb09b.tar.gz
rapier-17c31bcc57ec8d037ba6cc6ab5f7cfb6fa4bb09b.tar.bz2
rapier-17c31bcc57ec8d037ba6cc6ab5f7cfb6fa4bb09b.zip
WQuadtree query: reduce the amount of allocations.
Diffstat (limited to 'src/pipeline')
-rw-r--r--src/pipeline/query_pipeline.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/pipeline/query_pipeline.rs b/src/pipeline/query_pipeline.rs
index 10aa7ed..c5f0ded 100644
--- a/src/pipeline/query_pipeline.rs
+++ b/src/pipeline/query_pipeline.rs
@@ -64,15 +64,10 @@ impl QueryPipeline {
ray: &Ray,
max_toi: f32,
) -> Option<(ColliderHandle, &'a Collider, RayIntersection)> {
- // let t0 = instant::now();
- let inter = self.quadtree.cast_ray(ray, max_toi);
- // println!(
- // "Found {} interferences in time {}.",
- // inter.len(),
- // instant::now() - t0
- // );
+ // TODO: avoid allocation?
+ let mut inter = Vec::new();
+ self.quadtree.cast_ray(ray, max_toi, &mut inter);
- // let t0 = instant::now();
let mut best = f32::MAX;
let mut result = None;
@@ -85,7 +80,6 @@ impl QueryPipeline {
}
}
}
- // println!("Cast time: {}", instant::now() - t0);
result
}
@@ -107,8 +101,12 @@ impl QueryPipeline {
max_toi: f32,
mut callback: impl FnMut(ColliderHandle, &'a Collider, RayIntersection) -> bool,
) {
- // FIXME: this is a brute-force approach.
- for (handle, collider) in colliders.iter() {
+ // TODO: avoid allocation?
+ let mut inter = Vec::new();
+ self.quadtree.cast_ray(ray, max_toi, &mut inter);
+
+ for handle in inter {
+ let collider = &colliders[handle];
if let Some(inter) = collider.shape().cast_ray(collider.position(), ray, max_toi) {
if !callback(handle, collider, inter) {
return;