Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
GH Action committed Mar 2, 2024
1 parent d04f26a commit 9439f7f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/sokol/app.zig
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ pub const Desc = extern struct {
html5_bubble_wheel_events: bool = false,
html5_bubble_key_events: bool = false,
html5_bubble_char_events: bool = false,
html5_use_emsc_set_main_loop: bool = false,
html5_emsc_set_main_loop_simulate_infinite_loop: bool = false,
ios_keyboard_resizes_canvas: bool = false,
};
pub const Html5FetchError = enum(i32) {
Expand Down
18 changes: 15 additions & 3 deletions src/sokol/c/sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,8 @@ typedef struct sapp_desc {
bool html5_bubble_wheel_events; // same for wheel events
bool html5_bubble_key_events; // if true, bubble up *all* key events to browser, not just key events that represent characters
bool html5_bubble_char_events; // if true, bubble up character events to browser
bool html5_use_emsc_set_main_loop; // if true, use emscripten_set_main_loop() instead of emscripten_request_animation_frame_loop()
bool html5_emsc_set_main_loop_simulate_infinite_loop; // this will be passed as the simulate_infinite_loop arg to emscripten_set_main_loop()
bool ios_keyboard_resizes_canvas; // if true, showing the iOS keyboard shrinks the canvas
} sapp_desc;

Expand Down Expand Up @@ -5854,7 +5856,7 @@ _SOKOL_PRIVATE void _sapp_emsc_unregister_eventhandlers(void) {
#endif
}

_SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame(double time, void* userData) {
_SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame_animation_loop(double time, void* userData) {
_SOKOL_UNUSED(userData);
_sapp_timing_external(&_sapp.timing, time / 1000.0);

Expand All @@ -5881,6 +5883,13 @@ _SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame(double time, void* userData) {
return EM_TRUE;
}

_SOKOL_PRIVATE void _sapp_emsc_frame_main_loop(void) {
const double time = emscripten_performance_now();
if (!_sapp_emsc_frame_animation_loop(time, 0)) {
emscripten_cancel_main_loop();
}
}

_SOKOL_PRIVATE void _sapp_emsc_run(const sapp_desc* desc) {
_sapp_init_state(desc);
sapp_js_init(&_sapp.html5_canvas_selector[1]);
Expand Down Expand Up @@ -5911,8 +5920,11 @@ _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);

if (_sapp.desc.html5_use_emsc_set_main_loop) {
emscripten_set_main_loop(_sapp_emsc_frame_main_loop, 0, _sapp.desc.html5_emsc_set_main_loop_simulate_infinite_loop);
} else {
emscripten_request_animation_frame_loop(_sapp_emsc_frame_animation_loop, 0);
}
// 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
}
Expand Down

0 comments on commit 9439f7f

Please sign in to comment.