Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a bug in qt_node.collect_collisions() where a colliding hazard … #8

Merged
merged 1 commit into from
Feb 13, 2025
Merged
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
40 changes: 23 additions & 17 deletions jagua-rs/src/collision_detection/quadtree/qt_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,39 +181,45 @@ impl QTNode {
T: QTQueryable,
{
match self.hazards.strongest(detected) {
None => (),
Some(strongest_hazard) => match entity.collides_with(&self.bbox) {
false => (),
true => match strongest_hazard.presence {
QTHazPresence::None => (),
QTHazPresence::Entire => detected.push(strongest_hazard.entity),
QTHazPresence::Partial(_) => match &self.children {
None => (), //No more hazards to check
Some(_) => match entity.collides_with(&self.bbox) {
false => (), //Entity does not collide with the node
true => {
let active_hazards = self.hazards.active_hazards().iter();
match self.children.as_ref() {
Some(children) => {
//Check if any of the children intersect with the entity
//Children present, detect all Entire hazards now, wait with the Partial ones
for hz in active_hazards {
if let QTHazPresence::Entire = hz.presence {
if !detected.contains(&hz.entity) {
detected.push(hz.entity);
}
}
}

//Check all children
children
.iter()
.for_each(|child| child.collect_collisions(entity, detected))
.for_each(|child| child.collect_collisions(entity, detected));
}
None => {
//Check if any of the partially present (and active) hazards collide with the entity
self.hazards.active_hazards().iter().for_each(|hz| {
//No children, detect all Entire hazards and check the Partial ones
for hz in active_hazards {
if !detected.contains(&hz.entity) {
match &hz.presence {
QTHazPresence::None => (),
QTHazPresence::Entire => {
unreachable!("should have been handled above")
}
QTHazPresence::Entire => detected.push(hz.entity),
QTHazPresence::Partial(p_haz) => {
if p_haz.collides_with(entity) {
detected.push(hz.entity);
}
}
}
}
})
}
}
},
},
}
}
},
}
}
Expand Down