Skip to content

Commit

Permalink
Core/ST: Undo savestate load
Browse files Browse the repository at this point in the history
Implemented in core among with its accompanying part in the view.
  • Loading branch information
Aurumaker72 committed Dec 6, 2024
1 parent 6a4d49d commit 6e3c4a6
Show file tree
Hide file tree
Showing 9 changed files with 872 additions and 757 deletions.
1,557 changes: 803 additions & 754 deletions core/memory/savestates.cpp

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions core/memory/savestates.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace Savestates
* \brief Executes a savestate operation to a path
* \param path The savestate's path
* \param job The job to set
* \param callback The callback to call when the operation is complete. Can be null.
* \param callback The callback to call when the operation is complete.
* \param ignore_warnings Whether warnings, such as those about ROM compatibility, shouldn't be shown.
* \warning The operation won't complete immediately. Must be called via AsyncExecutor unless calls are originating from the emu thread.
*/
Expand All @@ -88,7 +88,7 @@ namespace Savestates
* \brief Executes a savestate operation to a slot
* \param slot The slot to construct the savestate path with.
* \param job The job to set
* \param callback The callback to call when the operation is complete. Can be null.
* \param callback The callback to call when the operation is complete.
* \param ignore_warnings Whether warnings, such as those about ROM compatibility, shouldn't be shown.
* \warning The operation won't complete immediately. Must be called via AsyncExecutor unless calls are originating from the emu thread.
*/
Expand All @@ -98,9 +98,15 @@ namespace Savestates
* Executes a savestate operation in-memory.
* \param buffer The buffer to use for the operation. Can be empty if the <see cref="job"/> is <see cref="e_st_job::save"/>.
* \param job The job to set.
* \param callback The callback to call when the operation is complete. Can be null.
* \param callback The callback to call when the operation is complete.
* \param ignore_warnings Whether warnings, such as those about ROM compatibility, shouldn't be shown.
* \warning The operation won't complete immediately. Must be called via AsyncExecutor unless calls are originating from the emu thread.
*/
void do_memory(const std::vector<uint8_t>& buffer, Job job, const t_savestate_callback& callback = nullptr, bool ignore_warnings = false);

/**
* Gets the undo savestate buffer. Will be empty will no undo savestate is available.
*/
std::vector<uint8_t> get_undo_savestate();

}
6 changes: 6 additions & 0 deletions shared/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ t_config get_default_config()
.down_cmd = Action::LoadAs,
};

config.undo_load_state_hotkey = {
.identifier = L"Undo load state",
.down_cmd = Action::UndoLoadState,
};

config.save_to_slot_1_hotkey = {
.identifier = L"Save to slot 1",
.down_cmd = Action::SaveSlot1,
Expand Down Expand Up @@ -578,6 +583,7 @@ mINI::INIStructure handle_config_ini(bool is_reading, mINI::INIStructure ini)
HANDLE_P_VALUE(piano_roll_constrain_edit_to_column)
HANDLE_P_VALUE(piano_roll_undo_stack_size)
HANDLE_P_VALUE(piano_roll_keep_selection_visible)
HANDLE_P_VALUE(st_undo_load)
HANDLE_P_VALUE(use_summercart)
HANDLE_P_VALUE(wii_vc_emulation)
HANDLE_P_VALUE(is_float_exception_propagation_enabled)
Expand Down
7 changes: 7 additions & 0 deletions shared/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum class Action
LoadSlot,
SaveAs,
LoadAs,
UndoLoadState,
SaveSlot1,
SaveSlot2,
SaveSlot3,
Expand Down Expand Up @@ -168,6 +169,7 @@ typedef struct Config
t_hotkey load_current_hotkey;
t_hotkey save_as_hotkey;
t_hotkey load_as_hotkey;
t_hotkey undo_load_state_hotkey;
t_hotkey save_to_slot_1_hotkey;
t_hotkey save_to_slot_2_hotkey;
t_hotkey save_to_slot_3_hotkey;
Expand Down Expand Up @@ -488,6 +490,11 @@ typedef struct Config
/// </summary>
int32_t piano_roll_keep_selection_visible;

/// <summary>
/// Whether undo savestate load functionality is enabled.
/// </summary>
int32_t st_undo_load = 1;

/// <summary>
/// SD card emulation
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions view/gui/FrontendService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ void FrontendService::set_default_hotkey_keys(t_config* config)
config->load_as_hotkey.key = 'M';
config->load_as_hotkey.ctrl = true;

config->undo_load_state_hotkey.key = 'Z';
config->undo_load_state_hotkey.ctrl = true;

config->save_to_slot_1_hotkey.key = '1';
config->save_to_slot_1_hotkey.shift = true;

Expand Down
35 changes: 35 additions & 0 deletions view/gui/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const std::map<Action, int> ACTION_ID_MAP = {
{Action::LoadSlot, IDM_LOAD_SLOT},
{Action::SaveAs, IDM_SAVE_STATE_AS},
{Action::LoadAs, IDM_LOAD_STATE_AS},
{Action::UndoLoadState, IDM_UNDO_LOAD_STATE},
{Action::SaveSlot1, (ID_SAVE_1 - 1) + 1},
{Action::SaveSlot2, (ID_SAVE_1 - 1) + 2},
{Action::SaveSlot3, (ID_SAVE_1 - 1) + 3},
Expand Down Expand Up @@ -1328,6 +1329,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
EnableMenuItem(g_main_menu, IDM_LOAD_SLOT, emu_launched ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(g_main_menu, IDM_SAVE_STATE_AS, emu_launched ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(g_main_menu, IDM_LOAD_STATE_AS, emu_launched ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(g_main_menu, IDM_UNDO_LOAD_STATE, (emu_launched && g_config.st_undo_load) ? MF_ENABLED : MF_GRAYED);
for (int i = IDM_SELECT_1; i < IDM_SELECT_10; ++i)
{
EnableMenuItem(g_main_menu, i, emu_launched ? MF_ENABLED : MF_GRAYED);
Expand Down Expand Up @@ -1771,6 +1773,39 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
});
}
break;
case IDM_UNDO_LOAD_STATE:
{
++g_vr_wait_before_input_poll;
AsyncExecutor::invoke_async([=]
{
--g_vr_wait_before_input_poll;

auto buf = Savestates::get_undo_savestate();

if (buf.empty())
{
Statusbar::post(L"No load to undo");
return;
}

Savestates::do_memory(buf, Savestates::Job::Load, [](const CoreResult result, auto)
{
if (result == CoreResult::Ok)
{
Statusbar::post(L"Undid load");
return;
}

if (result == CoreResult::ST_Cancelled)
{
return;
}

Statusbar::post(L"Failed to undo load");
});
});
}
break;
case IDM_START_MOVIE_RECORDING:
{
BetterEmulationLock lock;
Expand Down
7 changes: 7 additions & 0 deletions view/gui/features/ConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,13 @@ void get_config_listview_items(std::vector<t_options_group>& groups, std::vector
return emu_launched;
},
},
t_options_item{
.group_id = core_group.id,
.name = L"Undo Savestate Load",
.tooltip = L"Whether undo savestate load functionality is enabled.",
.data = &g_config.st_undo_load,
.type = t_options_item::Type::Bool,
},
t_options_item{
.group_id = core_group.id,
.name = L"Counter Factor",
Expand Down
1 change: 1 addition & 0 deletions view/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@
#define IDC_SEEKER_SUBTEXT 40091
#define IDC_VERSION_TEXT 40092
#define IDC_PLUGIN_WARNING 40093
#define IDM_UNDO_LOAD_STATE 40094
#define IDC_STATIC -1

// Next default values for new objects
Expand Down
1 change: 1 addition & 0 deletions view/rsrc.rc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ BEGIN
MENUITEM "Load State", IDM_LOAD_SLOT, GRAYED
MENUITEM "&Save State As...", IDM_SAVE_STATE_AS, GRAYED
MENUITEM "&Load State As...", IDM_LOAD_STATE_AS, GRAYED
MENUITEM "Undo Load State", IDM_UNDO_LOAD_STATE, GRAYED
MENUITEM SEPARATOR
POPUP "Current Save S&tate"
BEGIN
Expand Down

0 comments on commit 6e3c4a6

Please sign in to comment.