Skip to content

Commit eaa20a2

Browse files
committed
[collision-solver] Correct critical section and simplify loop
1 parent 0a0aede commit eaa20a2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/vulkan-renderer/world/collision_solver.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@ OctreeCollisionSolver::find_all_ray_octree_collisions(const std::vector<std::sha
2222
found_collisions.reserve(worlds.size());
2323

2424
// We need a critical section because we are modifying m_collision_candidates.
25-
std::scoped_lock lock(m_collision_solver_mutex);
2625
{
26+
std::scoped_lock lock(m_collision_solver_mutex);
27+
2728
// TODO: Optimize this! Avoid memory re-allocation if possible and benchmark it.
2829
m_collision_candidates.clear();
2930
m_collision_candidates.reserve(worlds.size());
3031

3132
for (const auto &world : worlds) {
32-
if (!is_bounding_box_and_bounding_sphere_hit(world, position, direction)) {
33-
continue;
33+
if (is_bounding_box_and_bounding_sphere_hit(world, position, direction)) {
34+
m_collision_candidates.emplace_back(std::make_pair(world, glm::distance2(position, direction)));
3435
}
35-
36-
m_collision_candidates.emplace_back(std::make_pair(world, glm::distance2(position, direction)));
3736
}
3837

3938
// Sort the octree collision candidates by increasing square of distance between cube center and camera.

0 commit comments

Comments
 (0)