Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add selectable savestates #550

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions src/program/GameEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <future>
#include <stdint.h>

#define MAX_SELECTABLE_SAVESTATE 9

GameEvents::GameEvents(Context* c, MovieFile* m) : context(c), movie(m) {}

void GameEvents::init()
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/program/GameEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/program/KeyMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ KeyMapping::KeyMapping(void* c)
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"});

/* Add flags mapping */
input_list[INPUTLIST_FLAG].push_back({SingleInput::IT_FLAG, SingleInput::FLAG_RESTART, "Restart"});
Expand Down
6 changes: 5 additions & 1 deletion src/program/KeyMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ typedef int HotKeyType; enum
HOTKEY_LOADBRANCH9,
HOTKEY_LOADBRANCH_BACKTRACK,
HOTKEY_TOGGLE_FASTFORWARD, // Toggle fastforward
HOTKEY_LEN
HOTKEY_LEN,
HOTKEY_SAVESTATE_SELECTED,
HOTKEY_LOADSTATE_SELECTED,
HOTKEY_SELECTSTATE_NEXT,
HOTKEY_SELECTSTATE_PREVIOUS
};

struct HotKey {
Expand Down