diff --git a/README-ZN.md b/README-ZN.md
index b3960aa..6f1b306 100644
--- a/README-ZN.md
+++ b/README-ZN.md
@@ -69,9 +69,8 @@ cmake --build build
若需支持或反馈,请通过本仓库的 GitHub issues 板块联系我们。您的反馈对改进本系列教程至关重要!
## 请我喝咖啡
-[](https://ko-fi.com/ziyugamedev)
-[](https://afdian.com/a/ziyugamedev)
-
+
+
## QQ 交流群和我的微信二维码
diff --git a/README.md b/README.md
index 0d23ddc..777b5ac 100644
--- a/README.md
+++ b/README.md
@@ -69,9 +69,8 @@ If you encounter trouble downloading from GitHub (especially on networks in main
For support or feedback, please contact us through the GitHub issues section of this repository. Your feedback is crucial for making this series of tutorials better!
## Buy Me a Coffee
-[](https://ko-fi.com/ziyugamedev)
-[](https://afdian.com/a/ziyugamedev)
-
+
+
## QQ Discussion Group and My WeChat QR Code
diff --git a/src/engine/core/game_app.cpp b/src/engine/core/game_app.cpp
index f949d5b..e0cc04c 100644
--- a/src/engine/core/game_app.cpp
+++ b/src/engine/core/game_app.cpp
@@ -36,6 +36,7 @@ void GameApp::run() {
}
#ifdef __EMSCRIPTEN__
+ web_main_loop_cancelled_ = false;
// WebAssembly 环境下使用回调函数
// 0 表示无限帧率(由浏览器 requestAnimationFrame 控制),1 表示模拟无限循环
emscripten_set_main_loop_arg([](void* arg) {
@@ -51,24 +52,50 @@ void GameApp::run() {
}
void GameApp::oneIter() {
+#ifdef __EMSCRIPTEN__
+ if (!is_running_) {
+ if (!web_main_loop_cancelled_) {
+ emscripten_cancel_main_loop();
+ web_main_loop_cancelled_ = true;
+ close();
+ }
+ return;
+ }
+#else
if (!is_running_) return; // 防止在退出标志设置后的额外调用
+#endif
time_->update();
float delta_time = time_->getDeltaTime();
input_manager_->update(); // 每帧首先更新输入管理器
handleEvents();
+ if (!is_running_) {
+#ifdef __EMSCRIPTEN__
+ if (!web_main_loop_cancelled_) {
+ emscripten_cancel_main_loop();
+ web_main_loop_cancelled_ = true;
+ close();
+ }
+#endif
+ return;
+ }
+
update(delta_time);
+ if (!is_running_) {
+#ifdef __EMSCRIPTEN__
+ if (!web_main_loop_cancelled_) {
+ emscripten_cancel_main_loop();
+ web_main_loop_cancelled_ = true;
+ close();
+ }
+#endif
+ return;
+ }
+
render();
// spdlog::info("delta_time: {}", delta_time);
-
-#ifdef __EMSCRIPTEN__
- if (!is_running_) {
- emscripten_cancel_main_loop();
- close();
- }
-#endif
}
void GameApp::registerSceneSetup(std::function func)
diff --git a/src/engine/core/game_app.h b/src/engine/core/game_app.h
index 0a2c9c6..53984e1 100644
--- a/src/engine/core/game_app.h
+++ b/src/engine/core/game_app.h
@@ -46,6 +46,9 @@ private:
SDL_Window* window_ = nullptr;
SDL_Renderer* sdl_renderer_ = nullptr;
bool is_running_ = false;
+#ifdef __EMSCRIPTEN__
+ bool web_main_loop_cancelled_ = false;
+#endif
/// @brief 游戏场景设置函数,用于在运行游戏前设置初始场景 (GameApp不再决定初始场景是什么)
std::function scene_setup_func_;