mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
refactor: river (#10)
* fix: correct snowy grass block texture * refactor: river generation * fix: water placement error due to interpolation * perf: improve river naturalness * feat: add river tab item * fix: path truncation
This commit is contained in:
@@ -15,27 +15,5 @@ void BiomeBuilder::build_bottom() {
|
||||
}
|
||||
}
|
||||
}
|
||||
void BiomeBuilder::fill_water() {
|
||||
ChunkGenerator& chunk_generator = get_chunk_generator();
|
||||
Chunk& chunk = chunk_generator.chunk();
|
||||
auto& m_blocks = chunk.blocks();
|
||||
auto& neighbor = chunk_generator.neighbor_biome();
|
||||
auto& heightmap = chunk.heightmap();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (neighbor[i] == BiomeType::RIVER) {
|
||||
for (int x = 0; x < SIZE_X; x++) {
|
||||
for (int z = 0; z < SIZE_Z; z++) {
|
||||
if (heightmap[x][z] >= SEA_LEVEL) {
|
||||
continue;
|
||||
}
|
||||
int height = heightmap[x][z];
|
||||
for (int y = height; y < SEA_LEVEL; y++) {
|
||||
m_blocks[Chunk::index(x, y, z)] = 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Cubed
|
||||
@@ -29,7 +29,7 @@ void DesertBuilder::build_blocks() {
|
||||
}
|
||||
}
|
||||
|
||||
void DesertBuilder::build_vegetation() { fill_water(); }
|
||||
void DesertBuilder::build_vegetation() {}
|
||||
|
||||
ChunkGenerator& DesertBuilder::get_chunk_generator() {
|
||||
return m_chunk_generator;
|
||||
|
||||
@@ -52,7 +52,6 @@ void ForestBuilder::build_vegetation() {
|
||||
}
|
||||
}
|
||||
}
|
||||
fill_water();
|
||||
}
|
||||
|
||||
ChunkGenerator& ForestBuilder::get_chunk_generator() {
|
||||
|
||||
@@ -25,7 +25,7 @@ void MountainBuilder::build_blocks() {
|
||||
}
|
||||
}
|
||||
|
||||
void MountainBuilder::build_vegetation() { fill_water(); }
|
||||
void MountainBuilder::build_vegetation() {}
|
||||
|
||||
ChunkGenerator& MountainBuilder::get_chunk_generator() {
|
||||
return m_chunk_generator;
|
||||
|
||||
@@ -29,7 +29,7 @@ void PlainBuilder::build_blocks() {
|
||||
}
|
||||
}
|
||||
|
||||
void PlainBuilder::build_vegetation() { fill_water(); }
|
||||
void PlainBuilder::build_vegetation() {}
|
||||
|
||||
ChunkGenerator& PlainBuilder::get_chunk_generator() {
|
||||
return m_chunk_generator;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "Cubed/gameplay/builders/river_builder.hpp"
|
||||
|
||||
#include "Cubed/gameplay/chunk.hpp"
|
||||
#include "Cubed/gameplay/chunk_generator.hpp"
|
||||
namespace Cubed {
|
||||
RiverBuilder::RiverBuilder(ChunkGenerator& chunk_generator)
|
||||
@@ -12,6 +11,7 @@ void RiverBuilder::build_biome() {
|
||||
};
|
||||
|
||||
void RiverBuilder::build_blocks() {
|
||||
/*
|
||||
auto& m_chunk = m_chunk_generator.chunk();
|
||||
auto& m_blocks = m_chunk.blocks();
|
||||
auto& m_heightmap = m_chunk.heightmap();
|
||||
@@ -33,9 +33,11 @@ void RiverBuilder::build_blocks() {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void RiverBuilder::build_vegetation() {
|
||||
/*
|
||||
auto& m_chunk = m_chunk_generator.chunk();
|
||||
auto& m_blocks = m_chunk.blocks();
|
||||
auto& m_heightmap = m_chunk.heightmap();
|
||||
@@ -50,6 +52,7 @@ void RiverBuilder::build_vegetation() {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
ChunkGenerator& RiverBuilder::get_chunk_generator() {
|
||||
|
||||
@@ -29,7 +29,7 @@ void SnowyPlainBuilder::build_blocks() {
|
||||
}
|
||||
}
|
||||
|
||||
void SnowyPlainBuilder::build_vegetation() { fill_water(); }
|
||||
void SnowyPlainBuilder::build_vegetation() {}
|
||||
|
||||
ChunkGenerator& SnowyPlainBuilder::get_chunk_generator() {
|
||||
return m_chunk_generator;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace Cubed {
|
||||
CaveCarver::CaveCarver() {}
|
||||
|
||||
std::unordered_map<int, CavePath>& CaveCarver::paths() { return m_paths; }
|
||||
std::unordered_map<unsigned, CavePath>& CaveCarver::paths() { return m_paths; }
|
||||
|
||||
void CaveCarver::init(unsigned world_seed) {
|
||||
m_seed = world_seed;
|
||||
@@ -19,13 +19,17 @@ void CaveCarver::reload(unsigned world_seed) {
|
||||
init(world_seed);
|
||||
}
|
||||
|
||||
void CaveCarver::add_path(const glm::vec3& pos) {
|
||||
m_paths.emplace(m_sum, CavePath{m_seed, m_sum, pos});
|
||||
void CaveCarver::add_path(const glm::vec3& pos, unsigned chunk_seed) {
|
||||
m_paths.emplace(chunk_seed, CavePath{m_seed, m_sum, pos});
|
||||
m_sum++;
|
||||
}
|
||||
|
||||
void CaveCarver::try_to_add_path(const ChunkPos& chunk_pos,
|
||||
unsigned chunk_seed) {
|
||||
auto it = m_paths.find(chunk_seed);
|
||||
if (it != m_paths.end()) {
|
||||
return;
|
||||
}
|
||||
Random random{chunk_seed};
|
||||
if (random.random_bool(static_cast<double>(m_cave_probability))) {
|
||||
const int CHUNK_MIN_X = chunk_pos.x * CHUNK_SIZE;
|
||||
@@ -38,7 +42,7 @@ void CaveCarver::try_to_add_path(const ChunkPos& chunk_pos,
|
||||
int x = random.random_int(CHUNK_MIN_X, CHUNK_MAX_X);
|
||||
int y = random.random_int(CHUNK_MIN_Y + 1, max_y);
|
||||
int z = random.random_int(CHUNK_MIN_Z, CHUNK_MAX_Z);
|
||||
add_path(glm::vec3{x, y, z});
|
||||
add_path(glm::vec3{x, y, z}, chunk_seed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ void Chunk::gen_vertex_data(
|
||||
auto is_cull =
|
||||
[&](const std::vector<BlockType>* chunk_blocks) {
|
||||
if (chunk_blocks == nullptr) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
int x, y, z;
|
||||
y = world_ny;
|
||||
@@ -294,6 +294,7 @@ void Chunk::gen_phase_six(
|
||||
}
|
||||
m_generator->blend_surface_blocks_borders(neighbor_block);
|
||||
m_generator->generate_cave();
|
||||
m_generator->generate_river();
|
||||
}
|
||||
|
||||
void Chunk::gen_phase_seven() {
|
||||
|
||||
@@ -539,11 +539,17 @@ void ChunkGenerator::blend_surface_blocks_borders(
|
||||
// Update the top block if the type changed
|
||||
if (final_type != type_self) {
|
||||
// top block
|
||||
if (m_chunk.biome() == BiomeType::RIVER && final_type == 1) {
|
||||
final_type = 2;
|
||||
if (final_type == 7 && top_y > SEA_LEVEL) {
|
||||
if (type_self == 7) {
|
||||
m_blocks[Chunk::index(x, top_y, z)] = 0;
|
||||
} else {
|
||||
m_blocks[Chunk::index(x, top_y, z)] = type_self;
|
||||
}
|
||||
|
||||
} else {
|
||||
m_blocks[Chunk::index(x, top_y, z)] = final_type;
|
||||
}
|
||||
|
||||
m_blocks[Chunk::index(x, top_y, z)] = final_type;
|
||||
// bottom block
|
||||
unsigned fill_type = 2;
|
||||
if (final_type == 1) {
|
||||
@@ -552,7 +558,11 @@ void ChunkGenerator::blend_surface_blocks_borders(
|
||||
fill_type = 4;
|
||||
}
|
||||
for (int y = top_y - 5; y < top_y; y++) {
|
||||
m_blocks[Chunk::index(x, y, z)] = fill_type;
|
||||
if (fill_type == 7 && y > SEA_LEVEL) {
|
||||
m_blocks[Chunk::index(x, y, z)] = 0;
|
||||
} else {
|
||||
m_blocks[Chunk::index(x, y, z)] = fill_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -650,6 +660,76 @@ void ChunkGenerator::generate_cave() {
|
||||
}
|
||||
}
|
||||
|
||||
void ChunkGenerator::generate_river() {
|
||||
|
||||
auto& river_worm = m_chunk.world().river_worm();
|
||||
auto& paths = river_worm.paths();
|
||||
const auto& chunk_pos = m_chunk.chunk_pos();
|
||||
auto& blocks = m_chunk.blocks();
|
||||
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;
|
||||
const int CHUNK_MIN_Y = 0;
|
||||
const int CHUNK_MAX_Y = SIZE_Y - 1;
|
||||
|
||||
bool is_river = false;
|
||||
|
||||
for (auto& [id, path] : paths) {
|
||||
for (const auto& point : path.points()) {
|
||||
if (m_chunk.biome() == BiomeType::DESERT) {
|
||||
path.clear_chunk(chunk_pos);
|
||||
continue;
|
||||
}
|
||||
const glm::vec3& center = point.pos;
|
||||
float rad_xz = point.rad_xz;
|
||||
float rad_y = point.rad_y;
|
||||
|
||||
int min_x = static_cast<int>(std::floor(center.x - rad_xz));
|
||||
int max_x = static_cast<int>(std::floor(center.x + rad_xz));
|
||||
int min_z = static_cast<int>(std::floor(center.z - rad_xz));
|
||||
int max_z = static_cast<int>(std::floor(center.z + rad_xz));
|
||||
int min_y = static_cast<int>(std::floor(center.y - rad_y));
|
||||
int max_y = static_cast<int>(std::floor(center.y + rad_y));
|
||||
|
||||
min_x = std::max(min_x, CHUNK_MIN_X);
|
||||
max_x = std::min(max_x, CHUNK_MAX_X);
|
||||
min_z = std::max(min_z, CHUNK_MIN_Z);
|
||||
max_z = std::min(max_z, CHUNK_MAX_Z);
|
||||
min_y = std::max(min_y, CHUNK_MIN_Y);
|
||||
max_y = std::min(max_y, CHUNK_MAX_Y);
|
||||
|
||||
for (int wx = min_x; wx <= max_x; ++wx) {
|
||||
int x = wx - CHUNK_MIN_X;
|
||||
for (int wz = min_z; wz <= max_z; ++wz) {
|
||||
int z = wz - CHUNK_MIN_Z;
|
||||
for (int wy = min_y; wy <= max_y; ++wy) {
|
||||
int y = wy;
|
||||
glm::vec3 pos(static_cast<float>(wx),
|
||||
static_cast<float>(wy),
|
||||
static_cast<float>(wz));
|
||||
if (point.contains(pos)) {
|
||||
if (y > SEA_LEVEL) {
|
||||
blocks[Chunk::index(x, y, z)] = 0;
|
||||
continue;
|
||||
}
|
||||
is_river = true;
|
||||
if (blocks[Chunk::index(x, y, z)] == 0) {
|
||||
continue;
|
||||
}
|
||||
blocks[Chunk::index(x, y, z)] = 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
path.clear_chunk(chunk_pos);
|
||||
}
|
||||
if (is_river) {
|
||||
m_chunk.biome(RIVER);
|
||||
}
|
||||
}
|
||||
|
||||
Chunk& ChunkGenerator::chunk() { return m_chunk; }
|
||||
|
||||
Random& ChunkGenerator::random() { return m_random; }
|
||||
|
||||
93
src/gameplay/river_path.cpp
Normal file
93
src/gameplay/river_path.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "Cubed/constants.hpp"
|
||||
#include "Cubed/gameplay/river.path.hpp"
|
||||
#include "Cubed/tools/cubed_hash.hpp"
|
||||
#include "Cubed/tools/math_tools.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
namespace Cubed {
|
||||
RiverPath::RiverPath(unsigned int world_seed, int path_id,
|
||||
const glm::vec3& start_pos) {
|
||||
m_path_id = path_id;
|
||||
m_seed = HASH::combine_32(world_seed, path_id);
|
||||
m_random.init(m_seed);
|
||||
m_yaw = m_random.random_float(0.0f, 360.0f);
|
||||
m_pitch = 0.0f;
|
||||
m_start_path_point.pos = start_pos;
|
||||
m_start_path_point.rad_xz =
|
||||
m_random.random_float(m_radius_xz_min, m_radius_xz_max);
|
||||
m_start_path_point.rad_y =
|
||||
m_random.random_float(m_radius_y_min, m_radius_y_max);
|
||||
m_step = m_random.random_int(m_step_min, m_step_max);
|
||||
m_points.reserve(m_step + 1);
|
||||
m_points.push_back(m_start_path_point);
|
||||
collect_path_points();
|
||||
precompute_chunk_coverage();
|
||||
}
|
||||
|
||||
void RiverPath::collect_path_points() {
|
||||
for (int i = 0; i < m_step; i++) {
|
||||
|
||||
m_yaw = std::fmod(m_yaw, 360.0f);
|
||||
if (m_yaw < 0.0f)
|
||||
m_yaw += 360.0f;
|
||||
|
||||
float dx = std::cos(glm::radians(m_pitch)) *
|
||||
std::sin(glm::radians(m_yaw)) * m_step_len;
|
||||
float dy = std::sin(glm::radians(m_pitch)) * m_step_len;
|
||||
float dz = std::cos(glm::radians(m_pitch)) *
|
||||
std::cos(glm::radians(m_yaw)) * m_step_len;
|
||||
|
||||
m_points[i].tangent = glm::normalize(glm::vec3{dx, dy, dz});
|
||||
|
||||
float t = Math::smootherstep(0, m_step - 1, i);
|
||||
|
||||
float drad_xz = m_start_path_point.rad_xz * (1.0f - t);
|
||||
float drad_y = m_start_path_point.rad_y * (1.0f - t);
|
||||
drad_xz = std::max(drad_xz, 4.0f);
|
||||
drad_y = std::max(drad_y, 4.0f);
|
||||
m_points.emplace_back(m_points[i].pos + glm::vec3{dx, dy, dz}, drad_xz,
|
||||
drad_y);
|
||||
|
||||
m_yaw += m_random.random_float(m_delta_angle_min, m_delta_angle_max);
|
||||
}
|
||||
auto n = m_points.size();
|
||||
if (n >= 2) {
|
||||
m_points[n - 1].tangent = m_points[n - 2].tangent;
|
||||
}
|
||||
}
|
||||
|
||||
void RiverPath::precompute_chunk_coverage() {
|
||||
for (const auto& point : m_points) {
|
||||
float rad = point.rad_xz;
|
||||
const glm::vec3& center = point.pos;
|
||||
|
||||
int min_cx =
|
||||
static_cast<int>(std::floor((center.x - rad) / CHUNK_SIZE));
|
||||
int max_cx =
|
||||
static_cast<int>(std::floor((center.x + rad) / CHUNK_SIZE));
|
||||
int min_cz =
|
||||
static_cast<int>(std::floor((center.z - rad) / CHUNK_SIZE));
|
||||
int max_cz =
|
||||
static_cast<int>(std::floor((center.z + rad) / CHUNK_SIZE));
|
||||
|
||||
for (int cx = min_cx; cx <= max_cx; ++cx)
|
||||
for (int cz = min_cz; cz <= max_cz; ++cz)
|
||||
m_pending_chunks.insert({cx, cz});
|
||||
}
|
||||
}
|
||||
|
||||
void RiverPath::clear_chunk(const ChunkPos& pos) {
|
||||
m_pending_chunks.erase(pos);
|
||||
}
|
||||
const std::vector<PathPoint>& RiverPath::points() const { return m_points; }
|
||||
bool RiverPath::is_finished() const { return m_pending_chunks.empty(); }
|
||||
|
||||
float& RiverPath::radius_xz_min() { return m_radius_xz_min; }
|
||||
float& RiverPath::radius_xz_max() { return m_radius_xz_max; }
|
||||
float& RiverPath::radius_y_min() { return m_radius_y_min; }
|
||||
float& RiverPath::radius_y_max() { return m_radius_y_max; }
|
||||
float& RiverPath::delta_angle_min() { return m_delta_angle_min; }
|
||||
float& RiverPath::delta_angle_max() { return m_delta_angle_max; }
|
||||
int& RiverPath::step_min() { return m_step_min; }
|
||||
int& RiverPath::step_max() { return m_step_max; }
|
||||
} // namespace Cubed
|
||||
53
src/gameplay/river_worm.cpp
Normal file
53
src/gameplay/river_worm.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "Cubed/gameplay/river_worm.hpp"
|
||||
|
||||
#include "Cubed/constants.hpp"
|
||||
|
||||
namespace Cubed {
|
||||
RiverWorm::RiverWorm() {}
|
||||
|
||||
std::unordered_map<unsigned, RiverPath>& RiverWorm::paths() { return m_paths; }
|
||||
|
||||
void RiverWorm::init(unsigned world_seed) {
|
||||
m_seed = world_seed;
|
||||
m_sum = 0;
|
||||
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{m_seed, m_sum, pos});
|
||||
m_sum++;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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::erase_if(m_paths,
|
||||
[](const auto& kv) { return kv.second.is_finished(); });
|
||||
}
|
||||
|
||||
int RiverWorm::river_sum() const { return m_sum; }
|
||||
float& RiverWorm::river_probability() { return m_probability; }
|
||||
} // namespace Cubed
|
||||
@@ -64,6 +64,7 @@ Player& World::get_player(const std::string& name) {
|
||||
|
||||
void World::init_world() {
|
||||
m_cave_carcer.init(ChunkGenerator::seed());
|
||||
m_river_worm.init(ChunkGenerator::seed());
|
||||
m_chunks.reserve(MAX_DISTANCE * MAX_DISTANCE * 4);
|
||||
auto t1 = std::chrono::system_clock::now();
|
||||
|
||||
@@ -339,15 +340,17 @@ void World::gen_chunks_internal() {
|
||||
m_chunk_gen_fraction = 0.0f;
|
||||
m_chunk_gen_finished = false;
|
||||
ChunkPosSet required_chunks;
|
||||
compute_required_chunks(required_chunks);
|
||||
ChunkHashMap temp_neighbor;
|
||||
compute_required_chunks(required_chunks, temp_neighbor);
|
||||
|
||||
ASSERT_MSG(!required_chunks.empty(), "required chunks is empty!!");
|
||||
|
||||
std::vector<ChunkPos> need_gen_chunks_pos;
|
||||
|
||||
sync_and_collect_missing_chunks(need_gen_chunks_pos, required_chunks);
|
||||
|
||||
Logger::info("New Gen Chunks Sum: {}", need_gen_chunks_pos.size());
|
||||
|
||||
Logger::info("Temp Chunks sum {}", temp_neighbor.size());
|
||||
if (need_gen_chunks_pos.empty()) {
|
||||
m_could_gen = true;
|
||||
m_chunk_gen_fraction = 1.0f;
|
||||
@@ -364,26 +367,27 @@ void World::gen_chunks_internal() {
|
||||
ConstChunkMap new_chunks_neighbor;
|
||||
// affected neighbor
|
||||
ChunkPtrUpdateList affected_neighbor;
|
||||
ChunkHashMap temp_neighbor;
|
||||
|
||||
build_neighbor_context_for_new_chunks(
|
||||
new_chunks_neighbor, affected_neighbor, new_chunks, temp_neighbor);
|
||||
build_neighbor_context_for_new_chunks(new_chunks_neighbor,
|
||||
affected_neighbor, new_chunks);
|
||||
|
||||
// Logger::info("Temp neighbor sum {}", temp_neighbor.size());
|
||||
// build new chunk, but the neighbor in m_chunks also need to re-build
|
||||
|
||||
for (auto& [pos, chunk] : new_chunks) {
|
||||
chunk.gen_phase_one();
|
||||
m_cave_carcer.try_to_add_path(pos, chunk.seed());
|
||||
m_river_worm.try_to_add_path(pos, chunk.seed());
|
||||
}
|
||||
// precompute path to ensure the continuity of the path
|
||||
for (auto& [pos, chunk] : temp_neighbor) {
|
||||
chunk.gen_phase_one();
|
||||
m_cave_carcer.try_to_add_path(pos, chunk.seed());
|
||||
m_river_worm.try_to_add_path(pos, chunk.seed());
|
||||
}
|
||||
|
||||
// for (auto& [pos, chunk] : temp_neighbor) {
|
||||
// chunk.gen_phase_one();
|
||||
// m_cave_carcer.try_to_add_path(pos, chunk.seed());
|
||||
// }
|
||||
|
||||
m_chunk_gen_fraction = 0.2f;
|
||||
|
||||
/*
|
||||
std::array<const Chunk*, 8> neighbor_chunks;
|
||||
for (auto& [pos, chunks] : new_chunks) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
@@ -391,13 +395,14 @@ void World::gen_chunks_internal() {
|
||||
auto it = new_chunks_neighbor.find(neighbor_pos);
|
||||
if (it == new_chunks_neighbor.end()) {
|
||||
neighbor_chunks[i] = nullptr;
|
||||
ASSERT_MSG(false, "Cant Find Neighbot");
|
||||
// ASSERT_MSG(false, "Cant Find Neighbot");
|
||||
continue;
|
||||
}
|
||||
neighbor_chunks[i] = it->second;
|
||||
}
|
||||
chunks.gen_phase_two(neighbor_chunks);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
for (auto& [pos, chunks] : temp_neighbor) {
|
||||
@@ -545,6 +550,7 @@ void World::gen_chunks_internal() {
|
||||
}
|
||||
}
|
||||
m_cave_carcer.cleanup_finished_caves();
|
||||
m_river_worm.cleanup_finished_rivers();
|
||||
m_chunk_gen_fraction = 1.0f;
|
||||
m_chunk_gen_finished = true;
|
||||
}
|
||||
@@ -554,7 +560,8 @@ void World::sync_player_pos(glm::vec3& player_pos) {
|
||||
player_pos = m_gen_player_pos;
|
||||
}
|
||||
|
||||
void World::compute_required_chunks(ChunkPosSet& required_chunks) {
|
||||
void World::compute_required_chunks(ChunkPosSet& required_chunks,
|
||||
ChunkHashMap& temp_neighbor) {
|
||||
glm::vec3 player_pos;
|
||||
sync_player_pos(player_pos);
|
||||
|
||||
@@ -569,6 +576,18 @@ void World::compute_required_chunks(ChunkPosSet& required_chunks) {
|
||||
required_chunks.emplace(u, v);
|
||||
}
|
||||
}
|
||||
int max_path_len = std::max(CavePath::step_max(), RiverPath::step_max());
|
||||
half = std::ceil(static_cast<float>(max_path_len) / CHUNK_SIZE) * 2;
|
||||
for (int u = chunk_x - half; u <= chunk_x + half; ++u) {
|
||||
for (int v = chunk_z - half; v <= chunk_z + half; ++v) {
|
||||
ChunkPos pos{u, v};
|
||||
auto it = required_chunks.find(pos);
|
||||
if (it != required_chunks.end()) {
|
||||
continue;
|
||||
}
|
||||
temp_neighbor.emplace(pos, Chunk(*this, pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void World::sync_and_collect_missing_chunks(
|
||||
@@ -593,7 +612,7 @@ void World::sync_and_collect_missing_chunks(
|
||||
|
||||
void World::build_neighbor_context_for_new_chunks(
|
||||
ConstChunkMap& new_chunks_neighbor, ChunkPtrUpdateList& affected_neighbor,
|
||||
const ChunkUpdateList& new_chunks, ChunkHashMap& temp_neighbor) {
|
||||
const ChunkUpdateList& new_chunks) {
|
||||
{
|
||||
std::lock_guard lk(m_chunks_mutex);
|
||||
for (auto& [pos, chunk] : new_chunks) {
|
||||
@@ -602,8 +621,6 @@ void World::build_neighbor_context_for_new_chunks(
|
||||
if (it != m_chunks.end()) {
|
||||
new_chunks_neighbor.insert({it->first, &(it->second)});
|
||||
affected_neighbor.push_back({it->first, &(it->second)});
|
||||
} else {
|
||||
temp_neighbor.emplace(pos + dir, Chunk(*this, pos + dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -611,9 +628,6 @@ void World::build_neighbor_context_for_new_chunks(
|
||||
for (auto& [pos, chunk] : new_chunks) {
|
||||
new_chunks_neighbor.insert({pos, &chunk});
|
||||
}
|
||||
for (auto& [pos, chunk] : temp_neighbor) {
|
||||
new_chunks_neighbor.insert({pos, &chunk});
|
||||
}
|
||||
}
|
||||
|
||||
void World::build_neighbor_context_for_affected_neighbors(
|
||||
@@ -860,6 +874,7 @@ void World::rebuild_world() {
|
||||
m_is_rebuilding = true;
|
||||
stop_gen_thread();
|
||||
m_cave_carcer.reload(ChunkGenerator::seed());
|
||||
m_river_worm.reload(ChunkGenerator::seed());
|
||||
{
|
||||
std::scoped_lock lk(m_chunks_mutex, m_new_chunk_queue_mutex);
|
||||
m_chunks.clear();
|
||||
@@ -882,5 +897,5 @@ void World::rendering_distance(int rendering_distance) {
|
||||
}
|
||||
|
||||
CaveCarver& World::cave_carcer() { return m_cave_carcer; }
|
||||
|
||||
RiverWorm& World::river_worm() { return m_river_worm; }
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user