don't pass a reference to a temporary to physics_thread

This commit is contained in:
2026-03-04 21:31:01 +01:00
parent 4e5ca6be6c
commit 08352dd997

View File

@ -15,7 +15,8 @@
class threaded_physics
{
struct add_mass {};
struct add_mass
{};
struct add_spring
{
@ -23,7 +24,8 @@ class threaded_physics
size_t b;
};
struct clear_graph {};
struct clear_graph
{};
using command = std::variant<add_mass, add_spring, clear_graph>;
@ -55,14 +57,17 @@ class threaded_physics
};
private:
std::optional<BS::thread_pool<>* const> thread_pool;
std::thread physics;
public:
physics_state state;
public:
explicit threaded_physics(const std::optional<BS::thread_pool<>* const> thread_pool = std::nullopt)
: physics(physics_thread, std::ref(state), std::ref(thread_pool)) {}
explicit threaded_physics(
const std::optional<BS::thread_pool<>* const> _thread_pool = std::nullopt)
: thread_pool(_thread_pool), physics(physics_thread, std::ref(state), std::ref(thread_pool))
{}
threaded_physics(const threaded_physics& copy) = delete;
auto operator=(const threaded_physics& copy) -> threaded_physics& = delete;
@ -82,13 +87,15 @@ private:
static auto set_octree_pool_thread_name(size_t idx) -> void;
#endif
static auto physics_thread(physics_state& state, std::optional<BS::thread_pool<>* const> thread_pool) -> void;
static auto physics_thread(physics_state& state,
std::optional<BS::thread_pool<>* const> thread_pool) -> void;
public:
auto clear_cmd() -> void;
auto add_mass_cmd() -> void;
auto add_spring_cmd(size_t a, size_t b) -> void;
auto add_mass_springs_cmd(size_t num_masses, const std::vector<std::pair<size_t, size_t>>& springs) -> void;
auto add_mass_springs_cmd(size_t num_masses,
const std::vector<std::pair<size_t, size_t>>& springs) -> void;
};
#endif