mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
* 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.
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
#include "Cubed/gameplay/river_worm.hpp"
|
|
|
|
#include "Cubed/constants.hpp"
|
|
|
|
namespace Cubed {
|
|
RiverWorm::RiverWorm() {}
|
|
|
|
RiverWorm::RiverHashMap& RiverWorm::paths() { return m_paths; }
|
|
|
|
void RiverWorm::init(unsigned world_seed) {
|
|
m_seed = world_seed;
|
|
|
|
m_random.init(m_seed);
|
|
}
|
|
|
|
void RiverWorm::reload(unsigned world_seed) {
|
|
m_seed = world_seed;
|
|
m_paths.clear();
|
|
init(world_seed);
|
|
}
|
|
|
|
void RiverWorm::add_path(const glm::vec3& pos, unsigned chunk_seed) {
|
|
m_paths.emplace(chunk_seed, RiverPath{chunk_seed, m_seed, pos});
|
|
}
|
|
|
|
void RiverWorm::try_to_add_path(const ChunkPos& chunk_pos,
|
|
unsigned chunk_seed) {
|
|
{
|
|
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))) {
|
|
const int CHUNK_MIN_X = chunk_pos.x * CHUNK_SIZE;
|
|
const int CHUNK_MIN_Z = chunk_pos.z * CHUNK_SIZE;
|
|
const int CHUNK_MAX_X = CHUNK_MIN_X + SIZE_X - 1;
|
|
const int CHUNK_MAX_Z = CHUNK_MIN_Z + SIZE_Z - 1;
|
|
int x = random.random_int(CHUNK_MIN_X, CHUNK_MAX_X);
|
|
int y = SEA_LEVEL + 2;
|
|
int z = random.random_int(CHUNK_MIN_Z, CHUNK_MAX_Z);
|
|
add_path(glm::vec3{x, y, z}, chunk_seed);
|
|
}
|
|
}
|
|
|
|
void RiverWorm::cleanup_finished_rivers() {
|
|
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_paths.size(); }
|
|
float& RiverWorm::river_probability() { return m_probability; }
|
|
} // namespace Cubed
|