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:
zhenyan121
2026-06-22 13:34:45 +08:00
committed by GitHub
parent 5385876a8a
commit 7ffc349eb3
19 changed files with 501 additions and 601 deletions

View File

@@ -463,6 +463,29 @@ void DevPanel::show_world_tab_item() {
if (ImGui::SliderInt("Render Distance", &rendering_distance, 2, 128)) {
m_app.world().rendering_distance(rendering_distance);
}
ImGui::Text(
"Pool Threads %d Max Support Threads %d Reserved Threads %d",
m_app.world().pool_threads(), m_app.world().max_threads(),
RESERVED_THREADS);
ImGui::SliderInt("Set Pool Threads", &m_threads, 1,
m_app.world().max_threads());
ImGui::SameLine();
if (ImGui::Button("Set")) {
m_app.world().change_pool_threads(m_threads);
}
if (m_threads > m_app.world().max_threads() - RESERVED_THREADS) {
ImGui::TextColored(
ImVec4(1.0f, 1.0f, 0.0f, 1.0f),
"Waring: When the threads in the thread pool exceed \n(maximum "
"threads minus reserved threads), \nit may cause stuttering.");
}
static const char* chunk_load_style[] = {"Random", "Center"};
m_chunk_style = m_app.world().chunk_load_style();
if (ImGui::Combo("ChunkLoadStyle", &m_chunk_style, chunk_load_style,
IM_ARRAYSIZE(chunk_load_style))) {
m_app.world().set_chunk_load_style(m_chunk_style);
}
if (ImGui::Button("Rebuild World")) {
m_app.world().rebuild_world();
}
@@ -542,6 +565,8 @@ void DevPanel::show_player_tab_item() {
m_player_profile.pos[1],
m_player_profile.pos[2]});
}
ImGui::SliderFloat("Fly Y Speed", &m_player->fly_y_speed(), 0.0f,
100.0f);
ImGui::SliderFloat("Acceleration", &m_player->acceleration(), 1.0f,
200.0f);
ImGui::SliderFloat("Deceleration", &m_player->deceleration(), 1.0f,