don't pass a reference to a temporary to physics_thread
This commit is contained in:
@ -15,7 +15,8 @@
|
||||
|
||||
class threaded_physics
|
||||
{
|
||||
struct add_mass {};
|
||||
struct add_mass
|
||||
{};
|
||||
|
||||
struct add_spring
|
||||
{
|
||||
@ -23,24 +24,25 @@ class threaded_physics
|
||||
size_t b;
|
||||
};
|
||||
|
||||
struct clear_graph {};
|
||||
struct clear_graph
|
||||
{};
|
||||
|
||||
using command = std::variant<add_mass, add_spring, clear_graph>;
|
||||
|
||||
struct physics_state
|
||||
{
|
||||
#ifdef TRACY
|
||||
#ifdef TRACY
|
||||
TracyLockable(std::mutex, command_mtx);
|
||||
#else
|
||||
#else
|
||||
std::mutex command_mtx;
|
||||
#endif
|
||||
#endif
|
||||
std::queue<command> pending_commands;
|
||||
|
||||
#ifdef TRACY
|
||||
#ifdef TRACY
|
||||
TracyLockable(std::mutex, data_mtx);
|
||||
#else
|
||||
#else
|
||||
std::mutex data_mtx;
|
||||
#endif
|
||||
#endif
|
||||
std::condition_variable_any data_ready_cnd;
|
||||
std::condition_variable_any data_consumed_cnd;
|
||||
Vector3 mass_center = Vector3Zero();
|
||||
@ -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;
|
||||
@ -78,17 +83,19 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
#ifdef ASYNC_OCTREE
|
||||
#ifdef ASYNC_OCTREE
|
||||
static auto set_octree_pool_thread_name(size_t idx) -> void;
|
||||
#endif
|
||||
#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
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user