mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-22 02:27:01 +08:00
fix: add thread safety for cave and river path mutexes
This commit is contained in:
@@ -17,11 +17,13 @@ public:
|
||||
|
||||
int cave_sum() const;
|
||||
float& cave_probability();
|
||||
std::shared_mutex& path_mutex();
|
||||
|
||||
private:
|
||||
CaveHashMap m_paths;
|
||||
unsigned m_seed = 0;
|
||||
Random m_random;
|
||||
float m_cave_probability = 0.035f;
|
||||
std::shared_mutex m_path_mutex;
|
||||
};
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -12,6 +12,7 @@ class RiverWorm {
|
||||
|
||||
public:
|
||||
RiverWorm();
|
||||
~RiverWorm();
|
||||
RiverHashMap& paths();
|
||||
void init(unsigned world_seed);
|
||||
void reload(unsigned world_seed);
|
||||
@@ -21,12 +22,14 @@ public:
|
||||
|
||||
int river_sum() const;
|
||||
float& river_probability();
|
||||
std::shared_mutex& paths_mutex();
|
||||
|
||||
private:
|
||||
RiverHashMap m_paths;
|
||||
unsigned m_seed = 0;
|
||||
Random m_random;
|
||||
float m_probability = 0.01f;
|
||||
std::shared_mutex m_paths_mutex;
|
||||
};
|
||||
|
||||
}; // namespace Cubed
|
||||
@@ -104,6 +104,7 @@ private:
|
||||
|
||||
void submit_new_chunks();
|
||||
void poll_finished_chunks();
|
||||
void wait_all_chunk_tasks();
|
||||
|
||||
public:
|
||||
World();
|
||||
|
||||
@@ -48,7 +48,14 @@ public:
|
||||
for (auto& w : m_workers) {
|
||||
w.request_stop();
|
||||
}
|
||||
|
||||
m_cv.notify_all();
|
||||
|
||||
for (auto& w : m_workers) {
|
||||
if (w.joinable()) {
|
||||
w.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
template <typename F> auto enqueue(F&& f) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user