优化web版退出逻辑,优化readme图片大小

This commit is contained in:
Ziyu
2026-02-25 10:19:53 +08:00
parent 018917a9b4
commit 42d796bb83
4 changed files with 41 additions and 13 deletions
+2 -3
View File
@@ -69,9 +69,8 @@ cmake --build build
若需支持或反馈,请通过本仓库的 GitHub issues 板块联系我们。您的反馈对改进本系列教程至关重要!
## 请我喝咖啡
[!["Buy Me A Coffee"](https://storage.ko-fi.com/cdn/kofi2.png?v=3)](https://ko-fi.com/ziyugamedev)
[!["Support me on Afdian"](https://pic1.afdiancdn.com/static/img/welcome/button-sponsorme.png)](https://afdian.com/a/ziyugamedev)
<a href="https://ko-fi.com/ziyugamedev"><img src="https://storage.ko-fi.com/cdn/kofi2.png?v=3" alt="Buy Me A Coffee" width="200" /></a>
<a href="https://afdian.com/a/ziyugamedev"><img src="https://pic1.afdiancdn.com/static/img/welcome/button-sponsorme.png" alt="Support me on Afdian" width="200" /></a>
## QQ 交流群和我的微信二维码
+2 -3
View File
@@ -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
[!["Buy Me A Coffee"](https://storage.ko-fi.com/cdn/kofi2.png?v=3)](https://ko-fi.com/ziyugamedev)
[!["Support me on Afdian"](https://pic1.afdiancdn.com/static/img/welcome/button-sponsorme.png)](https://afdian.com/a/ziyugamedev)
<a href="https://ko-fi.com/ziyugamedev"><img src="https://storage.ko-fi.com/cdn/kofi2.png?v=3" alt="Buy Me A Coffee" width="200" /></a>
<a href="https://afdian.com/a/ziyugamedev"><img src="https://pic1.afdiancdn.com/static/img/welcome/button-sponsorme.png" alt="Support me on Afdian" width="200" /></a>
## QQ Discussion Group and My WeChat QR Code
+34 -7
View File
@@ -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<void(engine::scene::SceneManager &)> func)
+3
View File
@@ -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<void(engine::scene::SceneManager&)> scene_setup_func_;