mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
fix(client_world): add direct exit flag to break connection error loop
This commit is contained in:
@@ -101,6 +101,7 @@ public:
|
||||
AudioEngine& get_audio();
|
||||
Config& get_config();
|
||||
WorldScene& world_scene();
|
||||
void set_direct_exit();
|
||||
template <typename Fn>
|
||||
void register_ticktimer(std::string_view id, TickType threshold, Fn&& f) {
|
||||
m_ticktimers.emplace(
|
||||
@@ -153,7 +154,7 @@ private:
|
||||
|
||||
tbb::concurrent_unordered_map<std::string, TickTimer> m_ticktimers;
|
||||
std::unordered_map<std::string, Timer> m_timers;
|
||||
|
||||
std::atomic<bool> m_exit_direct{false};
|
||||
std::atomic<bool> m_game_running{false};
|
||||
std::atomic<bool> m_receive_exit{false};
|
||||
std::atomic<int> m_rendering_distance{24};
|
||||
|
||||
@@ -727,7 +727,7 @@ AABB ClientWorld::get_block_aabb(const glm::ivec3& pos) {
|
||||
AudioEngine& ClientWorld::get_audio() { return m_audio; }
|
||||
Config& ClientWorld::get_config() { return m_config; }
|
||||
WorldScene& ClientWorld::world_scene() { return m_world_scene; }
|
||||
|
||||
void ClientWorld::set_direct_exit() { m_exit_direct = true; }
|
||||
void ClientWorld::request_exit() {
|
||||
if (m_receive_exit) {
|
||||
return;
|
||||
@@ -738,7 +738,7 @@ void ClientWorld::request_exit() {
|
||||
m_client->send(make_packet(*req));
|
||||
int cnt = 0;
|
||||
while (!m_receive_exit) {
|
||||
if (m_client->is_connect_error()) {
|
||||
if (m_client->is_connect_error() || m_exit_direct) {
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(milliseconds(DEFAULT_PER_TICK_TIME));
|
||||
|
||||
@@ -20,6 +20,8 @@ WorldScene::~WorldScene() {
|
||||
void WorldScene::update(float dt) {
|
||||
if (m_client->is_connect_error()) {
|
||||
set_error(m_client->get_error_string());
|
||||
m_client->clear_error();
|
||||
m_client_world.set_direct_exit();
|
||||
}
|
||||
if (m_error_ui.has_error()) {
|
||||
m_error_ui.update(dt);
|
||||
@@ -46,7 +48,6 @@ void WorldScene::update(float dt) {
|
||||
if (m_paused) {
|
||||
m_pasue_menu.update(dt);
|
||||
} else {
|
||||
|
||||
m_hud_ui.update(dt);
|
||||
}
|
||||
}
|
||||
@@ -290,6 +291,7 @@ void WorldScene::set_pause(bool pause) {
|
||||
}
|
||||
|
||||
void WorldScene::set_error(std::string_view error) {
|
||||
Logger::error("WorldScene Error Set {}", error);
|
||||
m_error_ui.set_error(error);
|
||||
set_pause(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user