Skip to content

Commit

Permalink
Add vsync option
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanaobrien committed Mar 7, 2024
1 parent 79003cd commit e3006dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile.emscripten
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ endif
LIBS := -s USE_ZLIB=1

LDFLAGS := -L. --no-heap-copy $(LIBS) -s TOTAL_STACK=$(STACK_MEMORY) -s TOTAL_MEMORY=$(HEAP_MEMORY) -s NO_EXIT_RUNTIME=1 -s EXPORTED_RUNTIME_METHODS="['callMain', 'cwrap', 'getValue', 'FS', 'PATH', 'ERRNO_CODES']" \
-s EXPORTED_FUNCTIONS=['_main','_malloc','_load_state','_ejs_set_variable','_simulate_input','_shader_enable','_save_state_info','_set_cheat','_cmd_take_screenshot','_system_restart','_cmd_savefiles','_get_core_options','_cmd_save_state','_supports_states','_reset_cheat','_toggleMainLoop','_save_file_path','_get_disk_count','_set_current_disk','_get_current_disk','_refresh_save_files','_toggle_fastforward','_set_ff_ratio','_toggle_slow_motion','_set_sm_ratio','_toggle_rewind','_set_rewind_granularity','_get_current_frame_count','_ejs_set_keyboard_enabled'] \
-s EXPORTED_FUNCTIONS=['_main','_malloc','_load_state','_ejs_set_variable','_simulate_input','_shader_enable','_save_state_info','_set_cheat','_cmd_take_screenshot','_system_restart','_cmd_savefiles','_get_core_options','_cmd_save_state','_supports_states','_reset_cheat','_toggleMainLoop','_save_file_path','_get_disk_count','_set_current_disk','_get_current_disk','_refresh_save_files','_toggle_fastforward','_set_ff_ratio','_toggle_slow_motion','_set_sm_ratio','_toggle_rewind','_set_rewind_granularity','_get_current_frame_count','_ejs_set_keyboard_enabled','_set_vsync'] \
-lidbfs.js \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
-s GL_ENABLE_GET_PROC_ADDRESS=1 \
Expand Down
14 changes: 13 additions & 1 deletion gfx/drivers_context/emscriptenegl_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,23 @@ typedef struct
unsigned fb_height;
} emscripten_ctx_data_t;

bool vsync = true;

static void gfx_ctx_emscripten_swap_interval(void *data, int interval)
{
emscripten_set_main_loop_timing(EM_TIMING_SETIMMEDIATE, 0);
if (interval == 0 || !vsync)
emscripten_set_main_loop_timing(EM_TIMING_SETIMMEDIATE, 0);
else
emscripten_set_main_loop_timing(EM_TIMING_RAF, interval);
}

#ifdef EMULATORJS
void set_vsync(int enabled) {
vsync = (enabled == 1);
gfx_ctx_emscripten_swap_interval(NULL, 1);
}
#endif

static void gfx_ctx_emscripten_get_canvas_size(int *width, int *height)
{
EmscriptenFullscreenChangeEvent fullscreen_status;
Expand Down

0 comments on commit e3006dd

Please sign in to comment.