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();
|
AudioEngine& get_audio();
|
||||||
Config& get_config();
|
Config& get_config();
|
||||||
WorldScene& world_scene();
|
WorldScene& world_scene();
|
||||||
|
void set_direct_exit();
|
||||||
template <typename Fn>
|
template <typename Fn>
|
||||||
void register_ticktimer(std::string_view id, TickType threshold, Fn&& f) {
|
void register_ticktimer(std::string_view id, TickType threshold, Fn&& f) {
|
||||||
m_ticktimers.emplace(
|
m_ticktimers.emplace(
|
||||||
@@ -153,7 +154,7 @@ private:
|
|||||||
|
|
||||||
tbb::concurrent_unordered_map<std::string, TickTimer> m_ticktimers;
|
tbb::concurrent_unordered_map<std::string, TickTimer> m_ticktimers;
|
||||||
std::unordered_map<std::string, Timer> m_timers;
|
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_game_running{false};
|
||||||
std::atomic<bool> m_receive_exit{false};
|
std::atomic<bool> m_receive_exit{false};
|
||||||
std::atomic<int> m_rendering_distance{24};
|
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; }
|
AudioEngine& ClientWorld::get_audio() { return m_audio; }
|
||||||
Config& ClientWorld::get_config() { return m_config; }
|
Config& ClientWorld::get_config() { return m_config; }
|
||||||
WorldScene& ClientWorld::world_scene() { return m_world_scene; }
|
WorldScene& ClientWorld::world_scene() { return m_world_scene; }
|
||||||
|
void ClientWorld::set_direct_exit() { m_exit_direct = true; }
|
||||||
void ClientWorld::request_exit() {
|
void ClientWorld::request_exit() {
|
||||||
if (m_receive_exit) {
|
if (m_receive_exit) {
|
||||||
return;
|
return;
|
||||||
@@ -738,7 +738,7 @@ void ClientWorld::request_exit() {
|
|||||||
m_client->send(make_packet(*req));
|
m_client->send(make_packet(*req));
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
while (!m_receive_exit) {
|
while (!m_receive_exit) {
|
||||||
if (m_client->is_connect_error()) {
|
if (m_client->is_connect_error() || m_exit_direct) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(milliseconds(DEFAULT_PER_TICK_TIME));
|
std::this_thread::sleep_for(milliseconds(DEFAULT_PER_TICK_TIME));
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ WorldScene::~WorldScene() {
|
|||||||
void WorldScene::update(float dt) {
|
void WorldScene::update(float dt) {
|
||||||
if (m_client->is_connect_error()) {
|
if (m_client->is_connect_error()) {
|
||||||
set_error(m_client->get_error_string());
|
set_error(m_client->get_error_string());
|
||||||
|
m_client->clear_error();
|
||||||
|
m_client_world.set_direct_exit();
|
||||||
}
|
}
|
||||||
if (m_error_ui.has_error()) {
|
if (m_error_ui.has_error()) {
|
||||||
m_error_ui.update(dt);
|
m_error_ui.update(dt);
|
||||||
@@ -46,7 +48,6 @@ void WorldScene::update(float dt) {
|
|||||||
if (m_paused) {
|
if (m_paused) {
|
||||||
m_pasue_menu.update(dt);
|
m_pasue_menu.update(dt);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
m_hud_ui.update(dt);
|
m_hud_ui.update(dt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,6 +291,7 @@ void WorldScene::set_pause(bool pause) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorldScene::set_error(std::string_view error) {
|
void WorldScene::set_error(std::string_view error) {
|
||||||
|
Logger::error("WorldScene Error Set {}", error);
|
||||||
m_error_ui.set_error(error);
|
m_error_ui.set_error(error);
|
||||||
set_pause(true);
|
set_pause(true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user