mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
feat(dev_panel): split world tab; add chunk request logging and fix flag reset
This commit is contained in:
@@ -46,6 +46,7 @@ public:
|
||||
Window& window();
|
||||
ClientWorld& client_world();
|
||||
ServerWorld& server_world();
|
||||
const Argument& argument() const;
|
||||
|
||||
private:
|
||||
Camera m_camera;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
@@ -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,102 +459,122 @@ void DevPanel::show_settings_tab_item() {
|
||||
|
||||
void DevPanel::show_world_tab_item() {
|
||||
if (ImGui::BeginTabItem("world")) {
|
||||
if (m_text_editing.perlin_seed) {
|
||||
if (ImGui::InputText("ChunkGenerator Seed",
|
||||
perlin_noise_input_buffer,
|
||||
sizeof(perlin_noise_input_buffer),
|
||||
ImGuiInputTextFlags_CallbackCharFilter |
|
||||
ImGuiInputTextFlags_EnterReturnsTrue,
|
||||
filter_unsigned)) {
|
||||
ChunkGenerator::seed(static_cast<unsigned int>(
|
||||
std::strtoul(perlin_noise_input_buffer, nullptr, 10)));
|
||||
m_text_editing.perlin_seed = false;
|
||||
m_player->set_player_pos({0.0f, 255.0f, 0.0f});
|
||||
m_app.server_world().rebuild_world();
|
||||
}
|
||||
}
|
||||
if (!m_text_editing.perlin_seed) {
|
||||
ImGui::Text("ChunkGenerator Seed: %u", ChunkGenerator::seed());
|
||||
if (ImGui::IsItemClicked()) {
|
||||
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",
|
||||
m_app.server_world().pool_threads(),
|
||||
m_app.server_world().max_threads(), RESERVED_THREADS);
|
||||
ImGui::SliderInt("Set Pool Threads", &m_threads, 1,
|
||||
m_app.server_world().max_threads());
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Set")) {
|
||||
m_app.server_world().change_pool_threads(m_threads);
|
||||
}
|
||||
if (m_threads > m_app.server_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.server_world().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")) {
|
||||
m_app.server_world().rebuild_world();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Request Chunk Build")) {
|
||||
Logger::warn("This Request Chunk Build button is not finish");
|
||||
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();
|
||||
} else {
|
||||
m_app.server_world().stop_gen_thread();
|
||||
if (ImGui::BeginTabBar("World Kind")) {
|
||||
if (!m_app.argument().is_client) {
|
||||
if (ImGui::BeginTabItem("ServerWorld")) {
|
||||
show_server_world_table_bar();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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();
|
||||
if (ImGui::BeginTabItem("Client World")) {
|
||||
show_client_world_table_bar();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
/*
|
||||
if (ImGui::BeginTabItem("Cave")) {
|
||||
show_cave_table_bar();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("River")) {
|
||||
show_river_table_bar();
|
||||
ImGui::EndTabItem();
|
||||
}*/
|
||||
if (ImGui::BeginTabItem("Biome")) {
|
||||
show_biome_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,
|
||||
sizeof(perlin_noise_input_buffer),
|
||||
ImGuiInputTextFlags_CallbackCharFilter |
|
||||
ImGuiInputTextFlags_EnterReturnsTrue,
|
||||
filter_unsigned)) {
|
||||
ChunkGenerator::seed(static_cast<unsigned int>(
|
||||
std::strtoul(perlin_noise_input_buffer, nullptr, 10)));
|
||||
m_text_editing.perlin_seed = false;
|
||||
m_player->set_player_pos({0.0f, 255.0f, 0.0f});
|
||||
m_app.server_world().rebuild_world();
|
||||
}
|
||||
}
|
||||
if (!m_text_editing.perlin_seed) {
|
||||
ImGui::Text("ChunkGenerator Seed: %u", ChunkGenerator::seed());
|
||||
if (ImGui::IsItemClicked()) {
|
||||
m_text_editing.perlin_seed = true;
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
m_app.server_world().max_threads());
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Set")) {
|
||||
m_app.server_world().change_pool_threads(m_threads);
|
||||
}
|
||||
if (m_threads > m_app.server_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.");
|
||||
}
|
||||
|
||||
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))) {
|
||||
m_app.server_world().set_chunk_load_style(m_chunk_style);
|
||||
}
|
||||
if (ImGui::Button("Rebuild World")) {
|
||||
m_app.server_world().rebuild_world();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Request Chunk Build")) {
|
||||
Logger::warn("This Request Chunk Build button is not finish");
|
||||
m_app.server_world().need_gen(std::nullopt);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Checkbox("Gen Thread", &m_gen_thread_running)) {
|
||||
if (m_gen_thread_running) {
|
||||
m_app.server_world().start_gen_thread();
|
||||
} else {
|
||||
m_app.server_world().stop_gen_thread();
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::BeginTabBar("World Settings")) {
|
||||
if (ImGui::BeginTabItem("Time")) {
|
||||
show_time_table_bar();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
/*
|
||||
if (ImGui::BeginTabItem("Cave")) {
|
||||
show_cave_table_bar();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("River")) {
|
||||
show_river_table_bar();
|
||||
ImGui::EndTabItem();
|
||||
}*/
|
||||
if (ImGui::BeginTabItem("Biome")) {
|
||||
show_biome_table_bar();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
}
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
||||
void DevPanel::show_player_tab_item() {
|
||||
if (!m_player) {
|
||||
Logger::error("Player is Nullptr");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user