From 0212d66fea02a7222f65ca3669795eb9ec3c4020 Mon Sep 17 00:00:00 2001 From: ambrus Date: Sat, 7 Oct 2023 11:35:43 -0600 Subject: [PATCH] Using emscripten_set_main_loop in sokol app allows async calls such as wget. --- sokol_app.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sokol_app.h b/sokol_app.h index e0b061321..e9eb51f0a 100644 --- a/sokol_app.h +++ b/sokol_app.h @@ -5782,8 +5782,8 @@ _SOKOL_PRIVATE void _sapp_emsc_unregister_eventhandlers() { #endif } -_SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame(double time, void* userData) { - _SOKOL_UNUSED(userData); +_SOKOL_PRIVATE void _sapp_emsc_frame() { + const double time = emscripten_performance_now(); _sapp_timing_external(&_sapp.timing, time / 1000.0); #if defined(SOKOL_WGPU) @@ -5824,9 +5824,8 @@ _SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame(double time, void* userData) { _sapp_emsc_unregister_eventhandlers(); _sapp_call_cleanup(); _sapp_discard_state(); - return EM_FALSE; + emscripten_cancel_main_loop(); } - return EM_TRUE; } _SOKOL_PRIVATE void _sapp_emsc_run(const sapp_desc* desc) { @@ -5859,7 +5858,7 @@ _SOKOL_PRIVATE void _sapp_emsc_run(const sapp_desc* desc) { sapp_set_icon(&desc->icon); /* start the frame loop */ - emscripten_request_animation_frame_loop(_sapp_emsc_frame, 0); + emscripten_set_main_loop(_sapp_emsc_frame, 0, false); /* NOT A BUG: do not call _sapp_discard_state() here, instead this is called in _sapp_emsc_frame() when the application is ordered to quit