feat(dev_panel): split world tab; add chunk request logging and fix flag reset

This commit is contained in:
2026-06-27 12:07:39 +08:00
parent 7b6c11e904
commit 43395d4794
6 changed files with 120 additions and 87 deletions

View File

@@ -46,6 +46,7 @@ public:
Window& window();
ClientWorld& client_world();
ServerWorld& server_world();
const Argument& argument() const;
private:
Camera m_camera;

View File

@@ -58,6 +58,8 @@ private:
void show_chunk_table_bar();
void show_settings_tab_item();
void show_world_tab_item();
void show_server_world_table_bar();
void show_client_world_table_bar();
void show_player_tab_item();
void show_items_tab_item();
void show_shader_tab_item();

View File

@@ -353,5 +353,5 @@ TextureManager& App::texture_manager() { return m_texture_manager; }
Window& App::window() { return m_window; }
ClientWorld& App::client_world() { return m_client_world; }
ServerWorld& App::server_world() { return m_server.server_world(); }
const App::Argument& App::argument() const { return m_argument; }
} // namespace Cubed

View File

@@ -16,6 +16,7 @@ namespace Cubed {
static constexpr const char* THEMES[] = {"Dark", "Light"};
static constexpr const char* GAITS[] = {"Walk", "Run"};
static constexpr const char* GAME_MODES[] = {"Creative", "Spectator"};
static constexpr const char* CHUNK_LOAD_STYLE[] = {"Random", "Center"};
static char perlin_noise_input_buffer[64];
constexpr float TEMP_MIN = 0.0f;
@@ -458,9 +459,32 @@ void DevPanel::show_settings_tab_item() {
void DevPanel::show_world_tab_item() {
if (ImGui::BeginTabItem("world")) {
if (ImGui::BeginTabBar("World Kind")) {
if (!m_app.argument().is_client) {
if (ImGui::BeginTabItem("ServerWorld")) {
show_server_world_table_bar();
ImGui::EndTabItem();
}
}
if (ImGui::BeginTabItem("Client World")) {
show_client_world_table_bar();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
// ImGui::Text("Chunk Build Progress\n");
// ImGui::ProgressBar(m_app.world().chunk_gen_fraction());
// show_chunk_table_bar();
ImGui::EndTabItem();
}
}
void DevPanel::show_server_world_table_bar() {
if (m_text_editing.perlin_seed) {
if (ImGui::InputText("ChunkGenerator Seed",
perlin_noise_input_buffer,
if (ImGui::InputText("ChunkGenerator Seed", perlin_noise_input_buffer,
sizeof(perlin_noise_input_buffer),
ImGuiInputTextFlags_CallbackCharFilter |
ImGuiInputTextFlags_EnterReturnsTrue,
@@ -478,13 +502,8 @@ void DevPanel::show_world_tab_item() {
m_text_editing.perlin_seed = true;
}
}
static int rendering_distance =
m_app.client_world().rendering_distance();
if (ImGui::SliderInt("Render Distance", &rendering_distance, 2, 128)) {
m_app.client_world().rendering_distance(rendering_distance);
}
ImGui::Text(
"Pool Threads %d Max Support Threads %d Reserved Threads %d",
ImGui::Text("Pool Threads %d Max Support Threads %d Reserved Threads %d",
m_app.server_world().pool_threads(),
m_app.server_world().max_threads(), RESERVED_THREADS);
ImGui::SliderInt("Set Pool Threads", &m_threads, 1,
@@ -500,10 +519,9 @@ void DevPanel::show_world_tab_item() {
"threads minus reserved threads), \nit may cause stuttering.");
}
static const char* chunk_load_style[] = {"Random", "Center"};
m_chunk_style = m_app.server_world().chunk_load_style();
if (ImGui::Combo("ChunkLoadStyle", &m_chunk_style, chunk_load_style,
IM_ARRAYSIZE(chunk_load_style))) {
if (ImGui::Combo("ChunkLoadStyle", &m_chunk_style, CHUNK_LOAD_STYLE,
IM_ARRAYSIZE(CHUNK_LOAD_STYLE))) {
m_app.server_world().set_chunk_load_style(m_chunk_style);
}
if (ImGui::Button("Rebuild World")) {
@@ -515,10 +533,6 @@ void DevPanel::show_world_tab_item() {
m_app.server_world().need_gen(std::nullopt);
}
ImGui::SameLine();
if (ImGui::Button("Spawn Point")) {
m_player->set_player_pos({0.0f, 255.0f, 0.0f});
}
ImGui::SameLine();
if (ImGui::Checkbox("Gen Thread", &m_gen_thread_running)) {
if (m_gen_thread_running) {
m_app.server_world().start_gen_thread();
@@ -526,9 +540,7 @@ void DevPanel::show_world_tab_item() {
m_app.server_world().stop_gen_thread();
}
}
// ImGui::Text("Chunk Build Progress\n");
// ImGui::ProgressBar(m_app.world().chunk_gen_fraction());
show_chunk_table_bar();
if (ImGui::BeginTabBar("World Settings")) {
if (ImGui::BeginTabItem("Time")) {
show_time_table_bar();
@@ -550,7 +562,16 @@ void DevPanel::show_world_tab_item() {
ImGui::EndTabBar();
}
ImGui::EndTabItem();
}
void DevPanel::show_client_world_table_bar() {
static int rendering_distance = m_app.client_world().rendering_distance();
if (ImGui::SliderInt("Render Distance", &rendering_distance, 2, 128)) {
m_app.client_world().rendering_distance(rendering_distance);
// Config::get().set("world.rendering_distance", rendering_distance);
}
if (ImGui::Button("Spawn Point")) {
m_player->set_player_pos({0.0f, 255.0f, 0.0f});
}
}

View File

@@ -509,6 +509,7 @@ void ClientPlayer::update_player_chunk() {
ChunkPos chunk_pos = get_chunk_pos(x, z);
float dist = distance2(chunk_pos, m_last_chunk_pos);
if (dist > 2) {
Logger::info("Player request new chunk");
m_world.request_chunk();
m_last_chunk_pos = chunk_pos;
}

View File

@@ -309,7 +309,9 @@ void ClientWorld::change_pool_threads(int threads) {
void ClientWorld::hot_reload() {
auto& config = Config::get();
int dist = config.get<int>("world.rendering_distance");
Logger::info("Get Config Randering dist {}", dist);
m_rendering_distance = dist <= MAX_DISTANCE ? dist : MAX_DISTANCE;
request_chunk();
}
void ClientWorld::client_run(std::stop_token stoken) {
@@ -356,6 +358,7 @@ void ClientWorld::request_chunk() {
int z = std::floor(player_pos.z);
auto [chunk_x, chunk_z] = get_chunk_pos(x, z);
int radius = m_rendering_distance;
Logger::info("Client Chunk Radius {}", radius);
int r2 = radius * radius;
required_chunks.reserve(radius * radius);
@@ -386,6 +389,7 @@ void ClientWorld::request_chunk() {
}
}
if (need_send_pos.empty()) {
m_requesting_chunk = false;
return;
}
using enum ChunkLoadStyle;
@@ -420,6 +424,7 @@ void ClientWorld::request_chunk() {
p->set_z(pos.z);
m_client->send(make_packet(*req));
}
Logger::info("Send Chunk Request Success");
m_requesting_chunk = false;
}
@@ -564,6 +569,9 @@ int ClientWorld::rendering_distance() const {
void ClientWorld::rendering_distance(int rendering_distance) {
m_rendering_distance = rendering_distance;
Logger::info("Set Rendering dist {} , the value is {}", rendering_distance,
m_rendering_distance.load());
request_chunk();
}
const std::vector<ChunkRenderSnapshot>& ClientWorld::render_snapshots() const {
return m_render_snapshots;