inexorgame / vulkan-renderer

A new 3D game engine for Linux and Windows using C++20 and Vulkan API 1.3, in very early but ongoing development
https://inexor.org
MIT License
790 stars 34 forks source link

How to make handles to cube class both thread safe and efficient? #419

Open IAmNotHanni opened 3 years ago

IAmNotHanni commented 3 years ago

We are passing around a lot of pointers, smart pointers or const references to cubes in our code. This is necessary, as it's a major part of our engine. For example I'm working on the new octree collision (see upcoming pull request later) which looks like this:

std::optional<RayCubeCollision<Cube>>
    ray_cube_collision_check(const std::shared_ptr<Cube> cube, const glm::vec3 pos,
    const glm::vec3 dir, const std::optional<std::uint32_t> grid_level_counter) 

So in this code I am passing the cube as std::shared_ptr. This is fine, but clang-tidy suggests to pass it as const reference to a shared pointer. Jason Turner and Scott Meyers however say that this is not a good idea.

We have the following options:

Notes:

I think this is a common question which will is relevant for many code parts. What do you guys propose?

IAmNotHanni commented 3 years ago

So... I guess passing it as std::shared_ptr is the best option?