Skip to content

Commit

Permalink
Add keybinding to rewind (backspace by default), if rewind states are…
Browse files Browse the repository at this point in the history
… enabled. Disable rewind on mobile.
  • Loading branch information
hrydgard committed Dec 5, 2013
1 parent 78604f4 commit cd2adf8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
27 changes: 17 additions & 10 deletions Common/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static const DefMappingStruct defaultQwertyKeyboardKeyMap[] = {
{VIRTKEY_UNTHROTTLE , NKCODE_TAB},
{VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE},
{VIRTKEY_PAUSE , NKCODE_ESCAPE},
{VIRTKEY_REWIND , NKCODE_DEL},
};

static const DefMappingStruct defaultAzertyKeyboardKeyMap[] = {
Expand Down Expand Up @@ -95,6 +96,7 @@ static const DefMappingStruct defaultAzertyKeyboardKeyMap[] = {
{VIRTKEY_UNTHROTTLE , NKCODE_TAB},
{VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE},
{VIRTKEY_PAUSE , NKCODE_ESCAPE},
{VIRTKEY_REWIND , NKCODE_DEL},
};

static const DefMappingStruct defaultQwertzKeyboardKeyMap[] = {
Expand Down Expand Up @@ -123,6 +125,7 @@ static const DefMappingStruct defaultQwertzKeyboardKeyMap[] = {
{VIRTKEY_UNTHROTTLE , NKCODE_TAB},
{VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE},
{VIRTKEY_PAUSE , NKCODE_ESCAPE},
{VIRTKEY_REWIND , NKCODE_DEL},
};

static const DefMappingStruct default360KeyMap[] = {
Expand Down Expand Up @@ -190,6 +193,7 @@ static const DefMappingStruct defaultBlackberryQWERTYKeyMap[] = {
{VIRTKEY_UNTHROTTLE , NKCODE_TAB},
{VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE},
{VIRTKEY_PAUSE , NKCODE_ESCAPE},
{VIRTKEY_REWIND , NKCODE_DEL},
};

static const DefMappingStruct defaultPadMap[] = {
Expand Down Expand Up @@ -279,17 +283,17 @@ void UpdateConfirmCancelKeys() {
int confirmKey = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CROSS : CTRL_CIRCLE;
int cancelKey = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CIRCLE : CTRL_CROSS;

for(auto i = g_controllerMap[confirmKey].begin(); i != g_controllerMap[confirmKey].end(); ++i) {
for (auto i = g_controllerMap[confirmKey].begin(); i != g_controllerMap[confirmKey].end(); ++i) {
confirmKeys.push_back((keycode_t)i->keyCode);
}

for(auto i = g_controllerMap[cancelKey].begin(); i != g_controllerMap[cancelKey].end(); ++i) {
for (auto i = g_controllerMap[cancelKey].begin(); i != g_controllerMap[cancelKey].end(); ++i) {
cancelKeys.push_back((keycode_t)i->keyCode);
}

// Push several hard-coded keys before submitting to native.
const keycode_t hardcodedConfirmKeys[] = {
NKCODE_SPACE,
const keycode_t hardcodedConfirmKeys[] = {
NKCODE_SPACE,
NKCODE_ENTER,
};

Expand All @@ -299,9 +303,9 @@ void UpdateConfirmCancelKeys() {
confirmKeys.push_back(hardcodedConfirmKeys[i]);
}

const keycode_t hardcodedCancelKeys[] = {
NKCODE_ESCAPE,
NKCODE_BACK,
const keycode_t hardcodedCancelKeys[] = {
NKCODE_ESCAPE,
NKCODE_BACK,
};

for (size_t i = 0; i < ARRAY_SIZE(hardcodedCancelKeys); i++) {
Expand Down Expand Up @@ -329,7 +333,6 @@ void SetDefaultKeyMap(DefaultMaps dmap, bool replace) {
bool qwertz = false;
#ifdef _WIN32
HKL localeId = GetKeyboardLayout(0);

// TODO: Is this list complete enough?
switch ((int)localeId & 0xFFFF) {
case 0x407:
Expand Down Expand Up @@ -427,7 +430,7 @@ const KeyMap_IntStrPair key_names[] = {
{NKCODE_F10, "F10"},
{NKCODE_F11, "F11"},
{NKCODE_F12, "F12"},

{NKCODE_GRAVE, "`"},
{NKCODE_SLASH, "/"},
{NKCODE_BACKSLASH, "\\"},
Expand All @@ -454,7 +457,8 @@ const KeyMap_IntStrPair key_names[] = {
{NKCODE_ALT_RIGHT, "RAlt"},
{NKCODE_SPACE, "Space"},
{NKCODE_WINDOW, "Windows"},
{NKCODE_DEL, "Del"},
{NKCODE_DEL, "Backspace"},
{NKCODE_FORWARD_DEL, "Delete"},
{NKCODE_MOVE_HOME, "Home"},
{NKCODE_MOVE_END, "End"},
{NKCODE_ESCAPE, "Esc"},
Expand Down Expand Up @@ -602,6 +606,9 @@ const KeyMap_IntStrPair psp_button_names[] = {
{VIRTKEY_UNTHROTTLE, "Unthrottle"},
{VIRTKEY_SPEED_TOGGLE, "SpeedToggle"},
{VIRTKEY_PAUSE, "Pause"},
#ifndef USING_GLES2
{VIRTKEY_REWIND, "Rewind"},
#endif

{VIRTKEY_AXIS_RIGHT_Y_MAX, "RightAn.Up"},
{VIRTKEY_AXIS_RIGHT_Y_MIN, "RightAn.Down"},
Expand Down
1 change: 1 addition & 0 deletions Common/KeyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum {
VIRTKEY_AXIS_RIGHT_Y_MIN = 0x10009,
VIRTKEY_AXIS_RIGHT_X_MAX = 0x1000a,
VIRTKEY_AXIS_RIGHT_Y_MAX = 0x1000b,
VIRTKEY_REWIND = 0x1000c,
VIRTKEY_LAST,
VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
};
Expand Down
3 changes: 3 additions & 0 deletions Core/SaveState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,16 @@ namespace SaveState
return;

rewindLastTime = time_now();
DEBUG_LOG(BOOT, "saving rewind state");
rewindStates.Save();
}

void Process()
{
#ifndef USING_GLES2
if (g_Config.iRewindFlipFrequency != 0 && gpuStats.numFlips != 0)
CheckRewindState();
#endif

if (!needsProcess)
return;
Expand Down
8 changes: 8 additions & 0 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ void EmuScreen::onVKeyDown(int virtualKeyCode) {
case VIRTKEY_AXIS_RIGHT_Y_MAX:
setVKeyAnalogY(CTRL_STICK_RIGHT, VIRTKEY_AXIS_RIGHT_Y_MIN, VIRTKEY_AXIS_RIGHT_Y_MAX);
break;

case VIRTKEY_REWIND:
if (SaveState::CanRewind()) {
SaveState::Rewind();
} else {
osm.Show(s->T("norewind", "No rewind save states available"), 2.0);
}
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ void GameSettingsScreen::CreateViews() {
systemSettings->Add(new CheckBox(&g_Config.bSeparateCPUThread, s->T("Multithreaded (experimental)")))->SetEnabled(!PSP_IsInited());
systemSettings->Add(new CheckBox(&g_Config.bSeparateIOThread, s->T("I/O on thread (experimental)")))->SetEnabled(!PSP_IsInited());
systemSettings->Add(new PopupSliderChoice(&g_Config.iLockedCPUSpeed, 0, 1000, s->T("Change CPU Clock", "Change CPU Clock (0 = default)"), screenManager()));
#ifndef USING_GLES2
systemSettings->Add(new PopupSliderChoice(&g_Config.iRewindFlipFrequency, 0, 1800, s->T("Rewind Snapshot Frequency", "Rewind Snapshot Frequency (0 = off, mem hog)"), screenManager()));
#endif

systemSettings->Add(new CheckBox(&g_Config.bAtomicAudioLocks, s->T("Atomic Audio locks (experimental)")))->SetEnabled(!PSP_IsInited());

Expand Down
2 changes: 1 addition & 1 deletion UI/OnScreenDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DrawBuffer;

class OnScreenMessages {
public:
void Show(const std::string &message, float duration_s = 1.0f, uint32_t color = 0xFFFFFF, int icon = -1, bool checkUnique = false);
void Show(const std::string &message, float duration_s = 1.0f, uint32_t color = 0xFFFFFF, int icon = -1, bool checkUnique = true);
void ShowOnOff(const std::string &message, bool b, float duration_s = 1.0f, uint32_t color = 0xFFFFFF, int icon = -1);
void Draw(DrawBuffer &draw);
bool IsEmpty() const { return messages_.empty(); }
Expand Down

0 comments on commit cd2adf8

Please sign in to comment.