From cd52c81400b648c5be011194796cb75622bd9c72 Mon Sep 17 00:00:00 2001 From: negative-seven <21268649+negative-seven@users.noreply.github.com> Date: Tue, 15 Aug 2023 18:21:05 +0200 Subject: [PATCH 1/2] Add selectable savestates --- src/program/GameEvents.cpp | 46 ++++++++++++++++++++++++++++++++++++-- src/program/GameEvents.h | 3 +++ src/program/KeyMapping.cpp | 4 ++++ src/program/KeyMapping.h | 4 ++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/program/GameEvents.cpp b/src/program/GameEvents.cpp index 872a1ac0..102f632d 100644 --- a/src/program/GameEvents.cpp +++ b/src/program/GameEvents.cpp @@ -33,6 +33,8 @@ #include #include +#define MAX_SELECTABLE_SAVESTATE 9 + GameEvents::GameEvents(Context* c, MovieFile* m) : context(c), movie(m) {} void GameEvents::init() @@ -109,6 +111,7 @@ bool GameEvents::processEvent(GameEvents::EventType type, struct HotKey &hk) case HOTKEY_SAVESTATE8: case HOTKEY_SAVESTATE9: case HOTKEY_SAVESTATE_BACKTRACK: + case HOTKEY_SAVESTATE_SELECTED: { /* Perform a savestate: * - save the moviefile if we are recording @@ -122,7 +125,13 @@ bool GameEvents::processEvent(GameEvents::EventType type, struct HotKey &hk) } /* Slot number */ - int statei = hk.type - HOTKEY_SAVESTATE1 + 1; + int statei; + if (hk.type == HOTKEY_SAVESTATE_SELECTED) { + statei = selectedSavestateId; + } + else { + statei = hk.type - HOTKEY_SAVESTATE1 + 1; + } /* Perform savestate */ int message = SaveStateList::save(statei, context, *movie); @@ -146,6 +155,7 @@ bool GameEvents::processEvent(GameEvents::EventType type, struct HotKey &hk) case HOTKEY_LOADSTATE8: case HOTKEY_LOADSTATE9: case HOTKEY_LOADSTATE_BACKTRACK: + case HOTKEY_LOADSTATE_SELECTED: case HOTKEY_LOADBRANCH1: case HOTKEY_LOADBRANCH2: case HOTKEY_LOADBRANCH3: @@ -180,7 +190,13 @@ bool GameEvents::processEvent(GameEvents::EventType type, struct HotKey &hk) bool load_branch = (hk.type >= HOTKEY_LOADBRANCH1) && (hk.type <= HOTKEY_LOADBRANCH_BACKTRACK); /* Slot number */ - int statei = hk.type - (load_branch?HOTKEY_LOADBRANCH1:HOTKEY_LOADSTATE1) + 1; + int statei; + if (hk.type == HOTKEY_LOADSTATE_SELECTED) { + statei = selectedSavestateId; + } + else { + statei = hk.type - (load_branch?HOTKEY_LOADBRANCH1:HOTKEY_LOADSTATE1) + 1; + } /* Perform state loading */ int error = SaveStateList::load(statei, context, *movie, load_branch); @@ -268,6 +284,32 @@ bool GameEvents::processEvent(GameEvents::EventType type, struct HotKey &hk) return false; } + case HOTKEY_SELECTSTATE_NEXT: + if (selectedSavestateId >= MAX_SELECTABLE_SAVESTATE) { + selectedSavestateId = 1; + } + else { + selectedSavestateId++; + } + + sendMessage(MSGN_OSD_MSG); + sendString("State " + std::to_string(selectedSavestateId) + " selected"); + + return false; + + case HOTKEY_SELECTSTATE_PREVIOUS: + if (selectedSavestateId <= 1) { + selectedSavestateId = MAX_SELECTABLE_SAVESTATE; + } + else { + selectedSavestateId--; + } + + sendMessage(MSGN_OSD_MSG); + sendString("State " + std::to_string(selectedSavestateId) + " selected"); + + return false; + case HOTKEY_READWRITE: /* Switch between movie write and read-only */ switch (context->config.sc.recording) { diff --git a/src/program/GameEvents.h b/src/program/GameEvents.h index 813b8846..19d749d8 100644 --- a/src/program/GameEvents.h +++ b/src/program/GameEvents.h @@ -58,6 +58,9 @@ class GameEvents : public QObject { /* Indicate if at least one savestate was performed, for backtrack savestate */ bool didASavestate = false; + /* Track selected savestate id */ + int selectedSavestateId = 1; + protected: Context* context; MovieFile* movie; diff --git a/src/program/KeyMapping.cpp b/src/program/KeyMapping.cpp index e7c34b19..be0216ad 100644 --- a/src/program/KeyMapping.cpp +++ b/src/program/KeyMapping.cpp @@ -60,6 +60,7 @@ KeyMapping::KeyMapping(void* c) hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F8 | XK_Shift_Flag}, HOTKEY_SAVESTATE8, "Save State 8"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F9 | XK_Shift_Flag}, HOTKEY_SAVESTATE9, "Save State 9"}); hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SAVESTATE_BACKTRACK, "Save Backtrack State"}); + hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SAVESTATE_SELECTED, "Save Selected State"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F1}, HOTKEY_LOADSTATE1, "Load State 1"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F2}, HOTKEY_LOADSTATE2, "Load State 2"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F3}, HOTKEY_LOADSTATE3, "Load State 3"}); @@ -70,6 +71,7 @@ KeyMapping::KeyMapping(void* c) hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F8}, HOTKEY_LOADSTATE8, "Load State 8"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F9}, HOTKEY_LOADSTATE9, "Load State 9"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F10}, HOTKEY_LOADSTATE_BACKTRACK, "Load Backtrack State"}); + hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_LOADSTATE_SELECTED, "Load Selected State"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F1 | XK_Control_Flag}, HOTKEY_LOADBRANCH1, "Load Branch 1"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F2 | XK_Control_Flag}, HOTKEY_LOADBRANCH2, "Load Branch 2"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F3 | XK_Control_Flag}, HOTKEY_LOADBRANCH3, "Load Branch 3"}); @@ -80,6 +82,8 @@ KeyMapping::KeyMapping(void* c) hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F8 | XK_Control_Flag}, HOTKEY_LOADBRANCH8, "Load Branch 8"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F9 | XK_Control_Flag}, HOTKEY_LOADBRANCH9, "Load Branch 9"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F10 | XK_Control_Flag}, HOTKEY_LOADBRANCH_BACKTRACK, "Load Backtrack Branch"}); + hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SELECTSTATE_NEXT, "Select Next State"}); + hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SELECTSTATE_PREVIOUS, "Select Previous State"}); hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_TOGGLE_ENCODE, "Toggle encode"}); /* Add flags mapping */ diff --git a/src/program/KeyMapping.h b/src/program/KeyMapping.h index b90ff28f..7d42d406 100644 --- a/src/program/KeyMapping.h +++ b/src/program/KeyMapping.h @@ -55,6 +55,7 @@ typedef int HotKeyType; enum HOTKEY_SAVESTATE8, HOTKEY_SAVESTATE9, HOTKEY_SAVESTATE_BACKTRACK, + HOTKEY_SAVESTATE_SELECTED, HOTKEY_LOADSTATE1, // Load the entire state of the game HOTKEY_LOADSTATE2, HOTKEY_LOADSTATE3, @@ -65,6 +66,7 @@ typedef int HotKeyType; enum HOTKEY_LOADSTATE8, HOTKEY_LOADSTATE9, HOTKEY_LOADSTATE_BACKTRACK, + HOTKEY_LOADSTATE_SELECTED, HOTKEY_TOGGLE_ENCODE, // Start/stop audio/video encoding HOTKEY_CALIBRATE_MOUSE, // Calibrate mouse cursor position HOTKEY_LOADBRANCH1, // Load state and movie @@ -77,6 +79,8 @@ typedef int HotKeyType; enum HOTKEY_LOADBRANCH8, HOTKEY_LOADBRANCH9, HOTKEY_LOADBRANCH_BACKTRACK, + HOTKEY_SELECTSTATE_NEXT, + HOTKEY_SELECTSTATE_PREVIOUS, HOTKEY_TOGGLE_FASTFORWARD, // Toggle fastforward HOTKEY_LEN }; From d44d9b9c180608c45885a3da6ab75943ca293264 Mon Sep 17 00:00:00 2001 From: negative-seven <21268649+negative-seven@users.noreply.github.com> Date: Sat, 7 Oct 2023 02:49:10 +0200 Subject: [PATCH 2/2] Move selectable savestate hotkeys to end of list for config file backwards compatibility --- src/program/KeyMapping.cpp | 6 +++--- src/program/KeyMapping.h | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/program/KeyMapping.cpp b/src/program/KeyMapping.cpp index be0216ad..8b8df60a 100644 --- a/src/program/KeyMapping.cpp +++ b/src/program/KeyMapping.cpp @@ -60,7 +60,6 @@ KeyMapping::KeyMapping(void* c) hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F8 | XK_Shift_Flag}, HOTKEY_SAVESTATE8, "Save State 8"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F9 | XK_Shift_Flag}, HOTKEY_SAVESTATE9, "Save State 9"}); hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SAVESTATE_BACKTRACK, "Save Backtrack State"}); - hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SAVESTATE_SELECTED, "Save Selected State"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F1}, HOTKEY_LOADSTATE1, "Load State 1"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F2}, HOTKEY_LOADSTATE2, "Load State 2"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F3}, HOTKEY_LOADSTATE3, "Load State 3"}); @@ -71,7 +70,6 @@ KeyMapping::KeyMapping(void* c) hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F8}, HOTKEY_LOADSTATE8, "Load State 8"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F9}, HOTKEY_LOADSTATE9, "Load State 9"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F10}, HOTKEY_LOADSTATE_BACKTRACK, "Load Backtrack State"}); - hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_LOADSTATE_SELECTED, "Load Selected State"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F1 | XK_Control_Flag}, HOTKEY_LOADBRANCH1, "Load Branch 1"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F2 | XK_Control_Flag}, HOTKEY_LOADBRANCH2, "Load Branch 2"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F3 | XK_Control_Flag}, HOTKEY_LOADBRANCH3, "Load Branch 3"}); @@ -82,9 +80,11 @@ KeyMapping::KeyMapping(void* c) hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F8 | XK_Control_Flag}, HOTKEY_LOADBRANCH8, "Load Branch 8"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F9 | XK_Control_Flag}, HOTKEY_LOADBRANCH9, "Load Branch 9"}); hotkey_list.push_back({{SingleInput::IT_KEYBOARD, XK_F10 | XK_Control_Flag}, HOTKEY_LOADBRANCH_BACKTRACK, "Load Backtrack Branch"}); + hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_TOGGLE_ENCODE, "Toggle encode"}); + hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SAVESTATE_SELECTED, "Save Selected State"}); + hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_LOADSTATE_SELECTED, "Load Selected State"}); hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SELECTSTATE_NEXT, "Select Next State"}); hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_SELECTSTATE_PREVIOUS, "Select Previous State"}); - hotkey_list.push_back({{SingleInput::IT_NONE, 0}, HOTKEY_TOGGLE_ENCODE, "Toggle encode"}); /* Add flags mapping */ input_list[INPUTLIST_FLAG].push_back({SingleInput::IT_FLAG, SingleInput::FLAG_RESTART, "Restart"}); diff --git a/src/program/KeyMapping.h b/src/program/KeyMapping.h index 7d42d406..395aeee5 100644 --- a/src/program/KeyMapping.h +++ b/src/program/KeyMapping.h @@ -55,7 +55,6 @@ typedef int HotKeyType; enum HOTKEY_SAVESTATE8, HOTKEY_SAVESTATE9, HOTKEY_SAVESTATE_BACKTRACK, - HOTKEY_SAVESTATE_SELECTED, HOTKEY_LOADSTATE1, // Load the entire state of the game HOTKEY_LOADSTATE2, HOTKEY_LOADSTATE3, @@ -66,7 +65,6 @@ typedef int HotKeyType; enum HOTKEY_LOADSTATE8, HOTKEY_LOADSTATE9, HOTKEY_LOADSTATE_BACKTRACK, - HOTKEY_LOADSTATE_SELECTED, HOTKEY_TOGGLE_ENCODE, // Start/stop audio/video encoding HOTKEY_CALIBRATE_MOUSE, // Calibrate mouse cursor position HOTKEY_LOADBRANCH1, // Load state and movie @@ -79,10 +77,12 @@ typedef int HotKeyType; enum HOTKEY_LOADBRANCH8, HOTKEY_LOADBRANCH9, HOTKEY_LOADBRANCH_BACKTRACK, - HOTKEY_SELECTSTATE_NEXT, - HOTKEY_SELECTSTATE_PREVIOUS, HOTKEY_TOGGLE_FASTFORWARD, // Toggle fastforward - HOTKEY_LEN + HOTKEY_LEN, + HOTKEY_SAVESTATE_SELECTED, + HOTKEY_LOADSTATE_SELECTED, + HOTKEY_SELECTSTATE_NEXT, + HOTKEY_SELECTSTATE_PREVIOUS }; struct HotKey {