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:
zhenyan121
2026-06-14 11:36:37 +08:00
committed by GitHub
parent 932463663f
commit f4114c2699
19 changed files with 384 additions and 239 deletions

View File

@@ -5,8 +5,15 @@ namespace Cubed {
Random::Random() {}
Random::Random(unsigned seed) { init(seed); }
bool Random::random_bool(double probability) {
std::bernoulli_distribution dist(probability);
return dist(m_engine);
if (probability <= 0.0)
return false;
if (probability >= 1.0)
return true;
const double MAX_VAL = 4294967295.0;
unsigned threshold = static_cast<unsigned>(probability * MAX_VAL);
return m_engine() <= threshold;
}
std::mt19937& Random::engine() { return m_engine; }
@@ -18,12 +25,23 @@ void Random::init(unsigned seed) {
m_engine.seed(seed);
}
int Random::random_int(int min, int max) {
std::uniform_int_distribution<int> dist(min, max);
return dist(m_engine);
unsigned range = static_cast<unsigned>(max - min) + 1;
const unsigned LIMIT =
(std::numeric_limits<unsigned>::max() / range) * range;
unsigned r;
do {
r = m_engine();
} while (r >= LIMIT);
return min + static_cast<int>(r % range);
}
float Random::random_float(float min, float max) {
std::uniform_real_distribution<float> dist(min, max);
return dist(m_engine);
}
unsigned r = m_engine() >> 8;
float t = static_cast<float>(r) * (1.0f / 16777216.0f);
float result = min + t * (max - min);
return result;
}
} // namespace Cubed