Skip to content

Commit 0a0aede

Browse files
committed
[collision-solver] Simplify class
1 parent cbed1d4 commit 0a0aede

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

include/inexor/vulkan-renderer/world/collision.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RayCubeCollision {
3131
/// @brief Default constructor
3232
/// @param The cube to check collisions with
3333
/// @note We need to pass cube as a std::shared_ptr by copy in this case because we want to ensure the lifetime
34-
/// of the object in multithreaded code. We are not accepting const references here, as they could become invalid.
34+
/// of the object in parallelized code. We are not accepting const references here, as they could become invalid.
3535
/// @param ray The start point of the ray
3636
/// @param dir The direction of the ray
3737
/// @param The intersection between ray and vertex geometry of the cube which was found

include/inexor/vulkan-renderer/world/collision_solver.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ class OctreeCollisionSolver {
3030
glm::vec3 direction, bool find_only_one_collision = true);
3131

3232
public:
33-
/// @brief Default constructor.
34-
/// @param octree_count The number of octrees
35-
explicit OctreeCollisionSolver(std::size_t octree_count);
3633

3734
// TODO: Implement min/max collision distance if required.
38-
// TODO: Start sorting only after a certain number of worlds.
35+
// TODO: Start sorting octrees by distance to camera only after a certain number of worlds.
36+
// TODO: Implement a bounding volume hierarchy (BVH) tree, for example an octree for all the octrees.
3937

4038
/// @brief Find a collision between a ray and an octree which is closest to the camera.
4139
/// @param worlds The octrees to check for collision

src/vulkan-renderer/application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void Application::load_octree_geometry() {
184184
m_worlds.emplace_back(std::make_shared<world::Cube>(1.0f, glm::vec3{0, 0, 0}));
185185
m_worlds.emplace_back(std::make_shared<world::Cube>(1.6f, glm::vec3{0, 10, 0}));
186186

187-
m_collision_solver = std::make_unique<world::OctreeCollisionSolver>(m_worlds.size());
187+
m_collision_solver = std::make_unique<world::OctreeCollisionSolver>();
188188

189189
m_worlds[0]->set_type(world::Cube::Type::OCTANT);
190190
m_worlds[1]->set_type(world::Cube::Type::SOLID);

src/vulkan-renderer/world/collision_query.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ std::optional<RayCubeCollision<Cube>> ray_cube_collision_check(const std::shared
149149
continue;
150150
}
151151

152-
// TODO: Implement min/max collision distance if required.
153-
154152
collision_candidates.emplace_back(
155153
std::make_pair(subcube, glm::distance2(subcube->center(), cube->center())));
156154
}

src/vulkan-renderer/world/collision_solver.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99

1010
namespace inexor::vulkan_renderer::world {
1111

12-
OctreeCollisionSolver::OctreeCollisionSolver(const std::size_t octree_count) {
13-
assert(octree_count > 0);
14-
m_collision_candidates.reserve(octree_count);
15-
}
16-
1712
std::vector<RayCubeCollision<Cube>>
1813
OctreeCollisionSolver::find_all_ray_octree_collisions(const std::vector<std::shared_ptr<world::Cube>> &worlds,
1914
const glm::vec3 position, const glm::vec3 direction,
@@ -29,6 +24,10 @@ OctreeCollisionSolver::find_all_ray_octree_collisions(const std::vector<std::sha
2924
// We need a critical section because we are modifying m_collision_candidates.
3025
std::scoped_lock lock(m_collision_solver_mutex);
3126
{
27+
// TODO: Optimize this! Avoid memory re-allocation if possible and benchmark it.
28+
m_collision_candidates.clear();
29+
m_collision_candidates.reserve(worlds.size());
30+
3231
for (const auto &world : worlds) {
3332
if (!is_bounding_box_and_bounding_sphere_hit(world, position, direction)) {
3433
continue;

0 commit comments

Comments
 (0)