Skip to content

Commit

Permalink
Update save state method
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanaobrien committed Feb 6, 2024
1 parent 498e68c commit 3883012
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 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','_get_state_info','_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'] \
-lidbfs.js \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
-s ALLOW_MEMORY_GROWTH=1 \
Expand Down
1 change: 0 additions & 1 deletion retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -5870,7 +5870,6 @@ static unsigned emscripten_frame_count = 0;
void emscripten_mainloop(void)
{
#ifdef EMULATORJS
ejs_check_save();
if (EJS_PENDING_SCREENSHOT) {
const char *path = "/screenshot.png";
video_driver_state_t *video_st = video_state_get_ptr();
Expand Down
60 changes: 24 additions & 36 deletions tasks/task_save.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,47 +1312,32 @@ static void task_push_load_and_save_state(const char *path, void *data,
}

#ifdef EMULATORJS
void* state_data;
char myString[1000];

void save_state_ejs(void)
void save_state_info(void)
{
memset(myString, '\0', sizeof(myString));
if (state_data)
free(state_data);
if (!core_info_current_supports_savestate()) {
strcpy(myString, "Not Supported||0");
return;
}
size_t serial_size = core_serialize_size();
if (serial_size == 0) {
strcpy(myString, "Size is zero||0");
return;
}
state_data = content_get_serialized_data(&serial_size);
if (!state_data) {
strcpy(myString, "Error writing data||0");
return;
}
sprintf(myString, "%zu|%zu|1", serial_size, (unsigned long)state_data);
}
size_t serial_size;
void *data = NULL;

char* get_state_info(void) {
return myString;
}
if (!core_info_current_supports_savestate()) {
return;
}

bool ejs_pending_save = false;
serial_size = core_serialize_size();
if (serial_size == 0) {
return;
}

void save_state_info(void)
{
emscripten_resume_main_loop();
ejs_pending_save = true;
}
void ejs_check_save(void)
{
if (!ejs_pending_save) return;
save_state_ejs();
ejs_pending_save = false;
data = content_get_serialized_data(&serial_size);
if (!data) {
return;
}
remove("/current.state");
FILE *f = fopen("/current.state", "wb");
if (f == NULL) {
return;
}
fwrite(data, 1, serial_size, f);
fclose(f);
}

bool supports_states(void)
Expand Down Expand Up @@ -1451,6 +1436,9 @@ bool content_auto_save_state(const char *path)
**/
bool content_save_state(const char *path, bool save_to_disk)
{
#ifdef EMULATORJS
return false;
#endif
size_t serial_size;
void *data = NULL;

Expand Down

0 comments on commit 3883012

Please sign in to comment.