initial implementation of undo save state

This commit is contained in:
radius 2016-06-02 23:33:52 -05:00
parent a5dbae0505
commit a86cf6b99d
8 changed files with 57 additions and 6 deletions

View File

@ -54,9 +54,6 @@ ifeq ($(DEBUG), 1)
OPTIMIZE_FLAG = -O0 -g
else
OPTIMIZE_FLAG = -O3 -ffast-math
ifneq ($(findstring Win32,$(OS)),)
LDFLAGS += -mwindows
endif
endif
CFLAGS += -Wall $(OPTIMIZE_FLAG) $(INCLUDE_DIRS) $(DEBUG_FLAG) -I.

View File

@ -1494,9 +1494,26 @@ static void command_event_save_state(const char *path,
*
* Loads a state with path being @path.
**/
static void command_event_load_state(const char *path, char *s, size_t len)
static void command_event_load_state(const char *path, char *s, size_t len, bool undo)
{
settings_t *settings = config_get_ptr();
char buf[PATH_MAX_LENGTH] = {0};
if (!undo) {
/* TODO: Fence with a setting */
strlcpy(buf, path, sizeof(buf));
snprintf(buf, sizeof(buf), "%s", path);
path_remove_extension(buf);
snprintf(buf, sizeof(buf), "%s.undo", buf);
if(!content_save_state(buf))
{
snprintf(s, len, "%s \"%s\".",
"Failed to save undo information\n",
buf);
return;
}
}
if (!content_load_state(path))
{
@ -1518,6 +1535,7 @@ static void command_event_main_state(unsigned cmd)
{
retro_ctx_size_info_t info;
char path[PATH_MAX_LENGTH] = {0};
char buf[PATH_MAX_LENGTH] = {0};
char msg[128] = {0};
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
@ -1541,7 +1559,13 @@ static void command_event_main_state(unsigned cmd)
command_event_save_state(path, msg, sizeof(msg));
break;
case CMD_EVENT_LOAD_STATE:
command_event_load_state(path, msg, sizeof(msg));
command_event_load_state(path, msg, sizeof(msg), false);
break;
case CMD_EVENT_UNDO_LOAD_STATE:
strlcpy(buf, path, sizeof(buf));
path_remove_extension(buf);
snprintf(buf, sizeof(buf), "%s.undo", buf);
command_event_load_state(buf, msg, sizeof(msg), true);
break;
}
}
@ -1661,6 +1685,9 @@ bool command_event(enum event_command cmd, void *data)
return false;
#endif
command_event_main_state(cmd);
break;
case CMD_EVENT_UNDO_LOAD_STATE:
command_event_main_state(cmd);
break;
case CMD_EVENT_RESIZE_WINDOWED_SCALE:

View File

@ -48,6 +48,7 @@ enum event_command
CMD_EVENT_LOAD_CORE_PERSIST,
CMD_EVENT_UNLOAD_CORE,
CMD_EVENT_LOAD_STATE,
CMD_EVENT_UNDO_LOAD_STATE,
CMD_EVENT_SAVE_STATE,
CMD_EVENT_SAVE_STATE_DECREMENT,
CMD_EVENT_SAVE_STATE_INCREMENT,

View File

@ -51,6 +51,9 @@ bool content_load_state(const char *path);
/* Save a state from memory to disk. */
bool content_save_state(const char *path);
/* Load a state backup from disk to memory. */
bool content_undo_load_state(const char *path);
bool content_does_not_need_content(void);
void content_set_does_not_need_content(void);

View File

@ -1272,8 +1272,15 @@ static int action_ok_load_state(const char *path,
if (generic_action_ok_command(CMD_EVENT_LOAD_STATE) == -1)
return menu_cbs_exit();
return generic_action_ok_command(CMD_EVENT_RESUME);
}
}
static int action_ok_undo_load_state(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
if (generic_action_ok_command(CMD_EVENT_UNDO_LOAD_STATE) == -1)
return menu_cbs_exit();
return generic_action_ok_command(CMD_EVENT_RESUME);
}
static int action_ok_save_state(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
@ -2373,6 +2380,10 @@ static int menu_cbs_init_bind_ok_compare_label(menu_file_list_cbs_t *cbs,
case MENU_LABEL_LOADSTATE:
BIND_ACTION_OK(cbs, action_ok_load_state);
break;
case MENU_LABEL_UNDOLOADSTATE:
printf ("first test\n");
BIND_ACTION_OK(cbs, action_ok_undo_load_state);
break;
case MENU_LABEL_RESUME_CONTENT:
BIND_ACTION_OK(cbs, action_ok_resume_content);
break;

View File

@ -658,6 +658,8 @@ static const char *menu_hash_to_str_us_label(uint32_t hash)
return "savestate";
case MENU_LABEL_LOAD_STATE:
return "loadstate";
case MENU_LABEL_UNDO_LOAD_STATE:
return "undoloadstate";
case MENU_LABEL_RESUME_CONTENT:
return "resume_content";
case MENU_LABEL_INPUT_DRIVER:
@ -1374,6 +1376,8 @@ const char *menu_hash_to_str_us(uint32_t hash)
return "Save State";
case MENU_LABEL_VALUE_LOAD_STATE:
return "Load State";
case MENU_LABEL_VALUE_UNDO_LOAD_STATE:
return "Undo Load State";
case MENU_LABEL_VALUE_RESUME_CONTENT:
return "Resume";
case MENU_LABEL_VALUE_INPUT_DRIVER:

View File

@ -2276,6 +2276,11 @@ static int menu_displaylist_parse_load_content_settings(
menu_hash_to_str(MENU_LABEL_LOAD_STATE),
MENU_SETTING_ACTION_LOADSTATE, 0, 0);
menu_entries_add(info->list,
menu_hash_to_str(MENU_LABEL_VALUE_UNDO_LOAD_STATE),
menu_hash_to_str(MENU_LABEL_UNDO_LOAD_STATE),
MENU_SETTING_ACTION_LOADSTATE, 0, 0);
menu_entries_add(info->list,
menu_hash_to_str(MENU_LABEL_VALUE_CORE_OPTIONS),
menu_hash_to_str(MENU_LABEL_CORE_OPTIONS),

View File

@ -298,8 +298,10 @@ extern "C" {
#define MENU_LABEL_VALUE_NO_CORES_AVAILABLE 0xe16bfd0dU
#define MENU_LABEL_SAVE_STATE 0x3a4849b5U
#define MENU_LABEL_VALUE_LOAD_STATE 0xd23ba706U
#define MENU_LABEL_VALUE_UNDO_LOAD_STATE 0xc83f09fcU
#define MENU_LABEL_VALUE_SAVE_STATE 0x3e182415U
#define MENU_LABEL_LOAD_STATE 0xa39eb286U
#define MENU_LABEL_UNDO_LOAD_STATE 0x464aaf5cU
#define MENU_LABEL_REWIND 0x1931d5aeU
#define MENU_LABEL_NETPLAY_FLIP_PLAYERS 0x801425abU
#define MENU_LABEL_CHEAT_INDEX_MINUS 0x57f58b6cU
@ -955,6 +957,7 @@ extern "C" {
#define MENU_LABEL_CUSTOM_BIND_DEFAULTS 0xe88f7b13U
#define MENU_LABEL_SAVESTATE 0x3a4849b5U
#define MENU_LABEL_LOADSTATE 0xa39eb286U
#define MENU_LABEL_UNDOLOADSTATE 0x464aaf5cU
#define MENU_LABEL_RESUME_CONTENT 0xd9f088b0U
#define MENU_LABEL_VALUE_RESUME_CONTENT 0xae6e5911U
#define MENU_LABEL_VALUE_RESUME 0xce8ac2f6U