mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
refactor: chunk load (#21)
* feat(renderer): add fog effect based on render distance * refactor(gameplay): remove dead code and simplify chunk neighbor context Remove the large commented-out `init_chunks()` function, and eliminate the `affected_neighbor` tracking in `gen_chunks_internal()`. This simplifies the neighbor context building and removes unused vertex data regeneration for affected neighbors. * refactor(gameplay): move chunk generation phases into gen_chunk method Consolidate multiple phase generation calls into a single gen_chunk() method on Chunk, which handles neighbor generation and ensures thread safety. Simplify World::gen_chunks_internal by using gen_chunk() instead of manual phase orchestration. * fix(gameplay): use gen_phase_one to get seed * feat(world): integrate thread pool and async chunk generation * fix(renderer): correct shader uniform name and remove unused uniform * feat(gameplay): add temporary chunk flag to prevent path clearing * fix: add thread safety for cave and river path mutexes * refactor: remove unused uniforms and set cameraPos uniform outside lambda * feat(world): add dynamic thread pool resizing * feat(world): add thread pool size management and UI controls * feat(world): add ChunkLoadStyle enum and rename chunk_pos to get_chunk_pos * feat(player): add configurable fly Y speed * refactor(world): add thread pool start/stop and auto-detect threads Extract thread pool starting and stopping into dedicated methods. Set default pool threads to 0 to enable automatic detection of available cores, and ensure thread pool is properly managed during world rebuild. * fix: include shared_mutex header * fix(gameplay): simplify set_chunk_load_style switch and fix fallthrough bug * fix(world): add missing include for <utility>
This commit is contained in:
@@ -723,18 +723,24 @@ void ChunkGenerator::generate_cave() {
|
||||
auto& paths = cave_carver.paths();
|
||||
const auto& chunk_pos = m_chunk.chunk_pos();
|
||||
auto& blocks = m_chunk.blocks();
|
||||
{
|
||||
std::shared_lock lock(cave_carver.path_mutex());
|
||||
for (auto& [id, path] : paths) {
|
||||
|
||||
for (auto& [id, path] : paths) {
|
||||
|
||||
carve_worm(path.points(), chunk_pos, [&](int x, int y, int z) -> void {
|
||||
int idx = Chunk::index(x, y, z);
|
||||
if (blocks[idx] == 7)
|
||||
return;
|
||||
if (y < WORLD_SIZE_Y - 1 && blocks[Chunk::index(x, y + 1, z)] == 7)
|
||||
return;
|
||||
blocks[idx] = 0;
|
||||
});
|
||||
path.clear_chunk(chunk_pos);
|
||||
carve_worm(path.points(), chunk_pos,
|
||||
[&](int x, int y, int z) -> void {
|
||||
int idx = Chunk::index(x, y, z);
|
||||
if (blocks[idx] == 7)
|
||||
return;
|
||||
if (y < WORLD_SIZE_Y - 1 &&
|
||||
blocks[Chunk::index(x, y + 1, z)] == 7)
|
||||
return;
|
||||
blocks[idx] = 0;
|
||||
});
|
||||
if (!m_chunk.is_temp_chunk()) {
|
||||
path.clear_chunk(chunk_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,29 +750,36 @@ void ChunkGenerator::generate_river() {
|
||||
auto& paths = river_worm.paths();
|
||||
const auto& chunk_pos = m_chunk.chunk_pos();
|
||||
auto& blocks = m_chunk.blocks();
|
||||
|
||||
bool is_river = false;
|
||||
|
||||
for (auto& [id, path] : paths) {
|
||||
if ((m_chunk.biome() == BiomeType::DESERT) ||
|
||||
(m_chunk.biome() == BiomeType::OCEAN)) {
|
||||
path.clear_chunk(chunk_pos);
|
||||
continue;
|
||||
{
|
||||
std::shared_lock lock(river_worm.paths_mutex());
|
||||
for (auto& [id, path] : paths) {
|
||||
if ((m_chunk.biome() == BiomeType::DESERT) ||
|
||||
(m_chunk.biome() == BiomeType::OCEAN)) {
|
||||
if (!m_chunk.is_temp_chunk()) {
|
||||
path.clear_chunk(chunk_pos);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
carve_worm(path.points(), chunk_pos,
|
||||
[&](int x, int y, int z) -> void {
|
||||
int idx = Chunk::index(x, y, z);
|
||||
if (y > SEA_LEVEL) {
|
||||
blocks[idx] = 0;
|
||||
return;
|
||||
}
|
||||
is_river = true;
|
||||
if (blocks[idx] == 0) {
|
||||
return;
|
||||
}
|
||||
blocks[idx] = 7;
|
||||
});
|
||||
if (!m_chunk.is_temp_chunk()) {
|
||||
path.clear_chunk(chunk_pos);
|
||||
}
|
||||
}
|
||||
carve_worm(path.points(), chunk_pos, [&](int x, int y, int z) -> void {
|
||||
int idx = Chunk::index(x, y, z);
|
||||
if (y > SEA_LEVEL) {
|
||||
blocks[idx] = 0;
|
||||
return;
|
||||
}
|
||||
is_river = true;
|
||||
if (blocks[idx] == 0) {
|
||||
return;
|
||||
}
|
||||
blocks[idx] = 7;
|
||||
});
|
||||
path.clear_chunk(chunk_pos);
|
||||
}
|
||||
|
||||
if (is_river) {
|
||||
m_chunk.biome(RIVER);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user