mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
refactor: world generation (#17)
* refactor: use TBB for concurrent hash maps and parallelize chunk processing * fix: tbb link fail * refactor(chunk): remove biome check for caves in rivers and oceans * refactor(random): replace std distributions with custom implementations Avoid overhead and platform-dependent behavior of `<random>` distributions by using direct engine operations and integer arithmetic. This ensures deterministic, cross-platform results and improves performance. * refactor(generation): use chunk seed for cave and river paths - Use per-chunk seed instead of global path_id for cave and river generation. - Remove unused m_sum variables and m_path_id members. - Clamp river yaw within 10 degrees of initial direction. - Fix river radius interpolation (use t instead of 1-t). - Lower sea level from 64 to 63.
This commit is contained in:
@@ -5,11 +5,11 @@
|
||||
namespace Cubed {
|
||||
RiverWorm::RiverWorm() {}
|
||||
|
||||
std::unordered_map<unsigned, RiverPath>& RiverWorm::paths() { return m_paths; }
|
||||
RiverWorm::RiverHashMap& RiverWorm::paths() { return m_paths; }
|
||||
|
||||
void RiverWorm::init(unsigned world_seed) {
|
||||
m_seed = world_seed;
|
||||
m_sum = 0;
|
||||
|
||||
m_random.init(m_seed);
|
||||
}
|
||||
|
||||
@@ -20,15 +20,16 @@ void RiverWorm::reload(unsigned world_seed) {
|
||||
}
|
||||
|
||||
void RiverWorm::add_path(const glm::vec3& pos, unsigned chunk_seed) {
|
||||
m_paths.emplace(chunk_seed, RiverPath{m_seed, m_sum, pos});
|
||||
m_sum++;
|
||||
m_paths.emplace(chunk_seed, RiverPath{chunk_seed, m_seed, pos});
|
||||
}
|
||||
|
||||
void RiverWorm::try_to_add_path(const ChunkPos& chunk_pos,
|
||||
unsigned chunk_seed) {
|
||||
auto it = m_paths.find(chunk_seed);
|
||||
if (it != m_paths.end()) {
|
||||
return;
|
||||
{
|
||||
RiverHashMap::const_accessor acc;
|
||||
if (m_paths.find(acc, chunk_seed)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Random random{chunk_seed};
|
||||
if (random.random_bool(static_cast<double>(m_probability))) {
|
||||
@@ -44,10 +45,17 @@ void RiverWorm::try_to_add_path(const ChunkPos& chunk_pos,
|
||||
}
|
||||
|
||||
void RiverWorm::cleanup_finished_rivers() {
|
||||
std::erase_if(m_paths,
|
||||
[](const auto& kv) { return kv.second.is_finished(); });
|
||||
std::vector<unsigned> finished_keys;
|
||||
for (const auto& pair : m_paths) {
|
||||
if (pair.second.is_finished()) {
|
||||
finished_keys.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
for (const auto& key : finished_keys) {
|
||||
m_paths.erase(key);
|
||||
}
|
||||
}
|
||||
|
||||
int RiverWorm::river_sum() const { return m_sum; }
|
||||
int RiverWorm::river_sum() const { return m_paths.size(); }
|
||||
float& RiverWorm::river_probability() { return m_probability; }
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user