mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
refactor(dev_panel): remove seed editing and server rebuild world, move client rebuild
- Remove text editing for perlin seed and filter function - Remove ServerWorld::rebuild_world() method and its atomic flag - Move 'Rebuild World' button to client world tab - Remove unused perlin_noise_input_buffer
This commit is contained in:
@@ -26,9 +26,6 @@ class DevPanel {
|
|||||||
int gait = 0;
|
int gait = 0;
|
||||||
float pos[3] = {0.0f, 0.0f, 0.0f};
|
float pos[3] = {0.0f, 0.0f, 0.0f};
|
||||||
};
|
};
|
||||||
struct TextEditing {
|
|
||||||
bool perlin_seed = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DevPanel(App& app);
|
DevPanel(App& app);
|
||||||
@@ -40,7 +37,6 @@ private:
|
|||||||
ConfigView m_config;
|
ConfigView m_config;
|
||||||
ClientPlayer* m_player;
|
ClientPlayer* m_player;
|
||||||
PlayerProfile m_player_profile;
|
PlayerProfile m_player_profile;
|
||||||
TextEditing m_text_editing;
|
|
||||||
bool m_need_save_config = false;
|
bool m_need_save_config = false;
|
||||||
bool m_gen_thread_running = true;
|
bool m_gen_thread_running = true;
|
||||||
int m_theme = 0;
|
int m_theme = 0;
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
void hot_reload();
|
void hot_reload();
|
||||||
|
|
||||||
void rebuild_world();
|
|
||||||
int rendering_distance() const;
|
int rendering_distance() const;
|
||||||
void rendering_distance(int rendering_distance);
|
void rendering_distance(int rendering_distance);
|
||||||
void start_gen_thread();
|
void start_gen_thread();
|
||||||
@@ -131,7 +130,6 @@ private:
|
|||||||
std::atomic<bool> m_could_gen{true};
|
std::atomic<bool> m_could_gen{true};
|
||||||
std::atomic<bool> m_gen_running{false};
|
std::atomic<bool> m_gen_running{false};
|
||||||
std::atomic<bool> m_need_gen_chunk{false};
|
std::atomic<bool> m_need_gen_chunk{false};
|
||||||
std::atomic<bool> m_is_rebuilding{false};
|
|
||||||
std::atomic<bool> m_init{false};
|
std::atomic<bool> m_init{false};
|
||||||
std::atomic<bool> m_stopped{false};
|
std::atomic<bool> m_stopped{false};
|
||||||
std::atomic<int> m_rendering_distance{24};
|
std::atomic<int> m_rendering_distance{24};
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ static constexpr const char* THEMES[] = {"Dark", "Light"};
|
|||||||
static constexpr const char* GAITS[] = {"Walk", "Run"};
|
static constexpr const char* GAITS[] = {"Walk", "Run"};
|
||||||
static constexpr const char* GAME_MODES[] = {"Creative", "Spectator"};
|
static constexpr const char* GAME_MODES[] = {"Creative", "Spectator"};
|
||||||
static constexpr const char* CHUNK_LOAD_STYLE[] = {"Random", "Center"};
|
static constexpr const char* CHUNK_LOAD_STYLE[] = {"Random", "Center"};
|
||||||
static char perlin_noise_input_buffer[64];
|
|
||||||
|
|
||||||
constexpr float TEMP_MIN = 0.0f;
|
constexpr float TEMP_MIN = 0.0f;
|
||||||
constexpr float TEMP_MAX = 1.0f;
|
constexpr float TEMP_MAX = 1.0f;
|
||||||
@@ -47,16 +46,6 @@ constexpr float DELTA_ANGLE_MAX = 30.0f;
|
|||||||
constexpr int PATH_STEP_MIN = 1;
|
constexpr int PATH_STEP_MIN = 1;
|
||||||
constexpr int PATH_STEP_MAX = 1000;
|
constexpr int PATH_STEP_MAX = 1000;
|
||||||
|
|
||||||
static int filter_unsigned(ImGuiInputTextCallbackData* data) {
|
|
||||||
if (data->EventFlag == ImGuiInputTextFlags_CallbackCharFilter) {
|
|
||||||
char c = data->EventChar;
|
|
||||||
if (c < '0' || c > '9') {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
DevPanel::DevPanel(App& app) : m_app(app) {}
|
DevPanel::DevPanel(App& app) : m_app(app) {}
|
||||||
|
|
||||||
void DevPanel::init() {
|
void DevPanel::init() {
|
||||||
@@ -483,25 +472,8 @@ void DevPanel::show_world_tab_item() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DevPanel::show_server_world_table_bar() {
|
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());
|
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",
|
ImGui::Text("Pool Threads %d Max Support Threads %d Reserved Threads %d",
|
||||||
m_app.server_world().gen_pool_threads(),
|
m_app.server_world().gen_pool_threads(),
|
||||||
@@ -525,12 +497,8 @@ void DevPanel::show_server_world_table_bar() {
|
|||||||
IM_ARRAYSIZE(CHUNK_LOAD_STYLE))) {
|
IM_ARRAYSIZE(CHUNK_LOAD_STYLE))) {
|
||||||
m_app.server_world().set_chunk_load_style(m_chunk_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")) {
|
if (ImGui::Button("Request Chunk Build")) {
|
||||||
Logger::warn("This Request Chunk Build button is not finish");
|
|
||||||
m_app.server_world().need_gen(m_player->get_uuid());
|
m_app.server_world().need_gen(m_player->get_uuid());
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
@@ -572,6 +540,10 @@ void DevPanel::show_client_world_table_bar() {
|
|||||||
m_app.client_world().rendering_distance(rendering_distance);
|
m_app.client_world().rendering_distance(rendering_distance);
|
||||||
// Config::get().set("world.rendering_distance", rendering_distance);
|
// Config::get().set("world.rendering_distance", rendering_distance);
|
||||||
}
|
}
|
||||||
|
if (ImGui::Button("Rebuild World")) {
|
||||||
|
m_app.client_world().rebuild_world();
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Spawn Point")) {
|
if (ImGui::Button("Spawn Point")) {
|
||||||
m_player->set_player_pos({0.0f, 255.0f, 0.0f});
|
m_player->set_player_pos({0.0f, 255.0f, 0.0f});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -504,40 +504,6 @@ void ServerWorld::hot_reload() {
|
|||||||
m_rendering_distance = dist <= MAX_DISTANCE ? dist : MAX_DISTANCE;
|
m_rendering_distance = dist <= MAX_DISTANCE ? dist : MAX_DISTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerWorld::rebuild_world() {
|
|
||||||
if (m_is_rebuilding.exchange(true)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
stop_gen_thread();
|
|
||||||
stop_thread_pool();
|
|
||||||
stop_server_thread();
|
|
||||||
m_cave_carcer.reload(ChunkGenerator::seed());
|
|
||||||
m_river_worm.reload(ChunkGenerator::seed());
|
|
||||||
|
|
||||||
m_chunks.clear();
|
|
||||||
|
|
||||||
{
|
|
||||||
std::lock_guard lock(m_new_chunk_mutex);
|
|
||||||
m_new_chunks.clear();
|
|
||||||
}
|
|
||||||
m_could_gen = true;
|
|
||||||
ChunkGenerator::reload();
|
|
||||||
start_thread_pool();
|
|
||||||
start_gen_thread();
|
|
||||||
start_server_thread();
|
|
||||||
Arena arena;
|
|
||||||
auto* rsp = Arena::Create<S2C_ClearAllChunks>(&arena);
|
|
||||||
rsp->set_clear(true);
|
|
||||||
{
|
|
||||||
std::lock_guard lock(m_player_mutex);
|
|
||||||
for (auto& [uuid, player] : m_players) {
|
|
||||||
player.get_session()->send(make_packet(*rsp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_is_rebuilding = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServerWorld::update() {
|
void ServerWorld::update() {
|
||||||
// poll_finished_chunks();
|
// poll_finished_chunks();
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user