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 Frame Advance #8939

Merged
merged 6 commits into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
50 changes: 28 additions & 22 deletions Common/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static const DefMappingStruct defaultQwertyKeyboardKeyMap[] = {
{VIRTKEY_UNTHROTTLE, NKCODE_TAB},
{VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE},
{VIRTKEY_PAUSE , NKCODE_ESCAPE},
{VIRTKEY_FRAME_ADVANCE, NKCODE_F},
{VIRTKEY_REWIND , NKCODE_DEL},
{VIRTKEY_ANALOG_LIGHTLY, NKCODE_SHIFT_RIGHT},
};
Expand Down Expand Up @@ -103,6 +104,7 @@ static const DefMappingStruct defaultAzertyKeyboardKeyMap[] = {
{VIRTKEY_RAPID_FIRE, NKCODE_SHIFT_LEFT},
{VIRTKEY_UNTHROTTLE, NKCODE_TAB},
{VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE},
{VIRTKEY_FRAME_ADVANCE, NKCODE_F},
{VIRTKEY_PAUSE , NKCODE_ESCAPE},
{VIRTKEY_REWIND , NKCODE_DEL},
{VIRTKEY_ANALOG_LIGHTLY, NKCODE_SHIFT_RIGHT},
Expand Down Expand Up @@ -133,6 +135,7 @@ static const DefMappingStruct defaultQwertzKeyboardKeyMap[] = {
{VIRTKEY_RAPID_FIRE, NKCODE_SHIFT_LEFT},
{VIRTKEY_UNTHROTTLE, NKCODE_TAB},
{VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE},
{VIRTKEY_FRAME_ADVANCE, NKCODE_F},
{VIRTKEY_PAUSE , NKCODE_ESCAPE},
{VIRTKEY_REWIND , NKCODE_DEL},
{VIRTKEY_ANALOG_LIGHTLY, NKCODE_SHIFT_RIGHT},
Expand Down Expand Up @@ -204,6 +207,7 @@ static const DefMappingStruct defaultBlackberryQWERTYKeyMap[] = {
{VIRTKEY_UNTHROTTLE , NKCODE_TAB},
{VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE},
{VIRTKEY_PAUSE , NKCODE_ESCAPE},
{VIRTKEY_FRAME_ADVANCE, NKCODE_F},
{VIRTKEY_REWIND , NKCODE_DEL},
};

Expand All @@ -218,34 +222,34 @@ static const DefMappingStruct defaultPadMap[] = {
{CTRL_RIGHT , JOYSTICK_AXIS_HAT_X, +1},
{CTRL_UP , JOYSTICK_AXIS_HAT_Y, -1},
{CTRL_DOWN , JOYSTICK_AXIS_HAT_Y, +1},
{CTRL_START , NKCODE_BUTTON_START},
{CTRL_START , NKCODE_BUTTON_START},
{CTRL_SELECT , NKCODE_BUTTON_SELECT},
{CTRL_LTRIGGER , NKCODE_BUTTON_L1},
{CTRL_RTRIGGER , NKCODE_BUTTON_R1},
{VIRTKEY_UNTHROTTLE , NKCODE_BUTTON_R2},
{CTRL_LTRIGGER , NKCODE_BUTTON_L1},
{CTRL_RTRIGGER , NKCODE_BUTTON_R1},
{VIRTKEY_UNTHROTTLE , NKCODE_BUTTON_R2},
{VIRTKEY_PAUSE , NKCODE_BUTTON_THUMBR},
{VIRTKEY_SPEED_TOGGLE, NKCODE_BUTTON_L2},
{VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1},
{VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1},
{VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1},
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1},
{VIRTKEY_SPEED_TOGGLE, NKCODE_BUTTON_L2},
{VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1},
{VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1},
{VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1},
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1},
#else
{CTRL_CROSS , NKCODE_BUTTON_2},
{CTRL_CIRCLE , NKCODE_BUTTON_3},
{CTRL_SQUARE , NKCODE_BUTTON_4},
{CTRL_TRIANGLE , NKCODE_BUTTON_1},
{CTRL_CROSS , NKCODE_BUTTON_2},
{CTRL_CIRCLE , NKCODE_BUTTON_3},
{CTRL_SQUARE , NKCODE_BUTTON_4},
{CTRL_TRIANGLE , NKCODE_BUTTON_1},
{CTRL_UP , NKCODE_DPAD_UP},
{CTRL_RIGHT , NKCODE_DPAD_RIGHT},
{CTRL_DOWN , NKCODE_DPAD_DOWN},
{CTRL_LEFT , NKCODE_DPAD_LEFT},
{CTRL_START , NKCODE_BUTTON_10},
{CTRL_SELECT , NKCODE_BUTTON_9},
{CTRL_LTRIGGER , NKCODE_BUTTON_7},
{CTRL_RTRIGGER , NKCODE_BUTTON_8},
{VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1},
{VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1},
{VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1},
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1},
{CTRL_SELECT , NKCODE_BUTTON_9},
{CTRL_LTRIGGER , NKCODE_BUTTON_7},
{CTRL_RTRIGGER , NKCODE_BUTTON_8},
{VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1},
{VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1},
{VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1},
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1},
#endif
};

Expand Down Expand Up @@ -583,7 +587,7 @@ const KeyMap_IntStrPair key_names[] = {
{NKCODE_NUMPAD_7, "Num7"},
{NKCODE_NUMPAD_8, "Num8"},
{NKCODE_NUMPAD_9, "Num9"},

{NKCODE_LANGUAGE_SWITCH, "Language"},
{NKCODE_MANNER_MODE, "Manner"},
{NKCODE_3D_MODE, "3D Mode"},
Expand All @@ -607,7 +611,7 @@ const KeyMap_IntStrPair key_names[] = {
{NKCODE_EXT_MOUSEWHEEL_UP, "MWheelU"},
{NKCODE_EXT_MOUSEWHEEL_DOWN, "MWheelD"},

{NKCODE_START_QUESTION, "¿"},
{NKCODE_START_QUESTION, "¿"},
{NKCODE_LEFTBRACE, "{"},
{NKCODE_RIGHTBRACE, "}"},
};
Expand Down Expand Up @@ -672,6 +676,7 @@ const KeyMap_IntStrPair psp_button_names[] = {
{VIRTKEY_UNTHROTTLE, "Unthrottle"},
{VIRTKEY_SPEED_TOGGLE, "SpeedToggle"},
{VIRTKEY_PAUSE, "Pause"},
{VIRTKEY_FRAME_ADVANCE, "Frame Advance"},
#ifndef MOBILE_DEVICE
{VIRTKEY_REWIND, "Rewind"},
#endif
Expand Down Expand Up @@ -980,6 +985,7 @@ void AutoConfForPad(const std::string &name) {
// Add a couple of convenient keyboard mappings by default, too.
g_controllerMap[VIRTKEY_PAUSE].push_back(KeyDef(DEVICE_ID_KEYBOARD, NKCODE_ESCAPE));
g_controllerMap[VIRTKEY_UNTHROTTLE].push_back(KeyDef(DEVICE_ID_KEYBOARD, NKCODE_TAB));
g_controllerMap[VIRTKEY_FRAME_ADVANCE].push_back(KeyDef(DEVICE_ID_KEYBOARD, NKCODE_F));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Right now it looks like once you start advancing, you're "trapped" into advancing. In fact, if frameStep_ isn't a member of EmuScreen, restarting the game won't even help. That sounds dangerous, and doubly dangerous if we have a default key shortcut for the feature.

Maybe we should only have it enabled if you configure a key for it?

-[Unknown]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get out of advancing, you can use F8 to resume.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best just remove default mapping, it's not a feature that most users will ever care about and does not need a default key. Even worse in place where most people would set their controls when using keyboards which many does even through gamepads are cheap.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, I thought it kept the flag set that it was advancing frame by frame for some reason. But good to remove the default still, indeed.

-[Unknown]

#endif
}

Expand Down
1 change: 1 addition & 0 deletions Common/KeyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ enum {
VIRTKEY_ANALOG_LIGHTLY = 0x10011,
VIRTKEY_AXIS_SWAP = 0x10012,
VIRTKEY_DEVMENU = 0x10013,
VIRTKEY_FRAME_ADVANCE = 0x10014,
VIRTKEY_LAST,
VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
};
Expand Down
10 changes: 5 additions & 5 deletions Core/HLE/sceCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const u32 CTRL_EMU_RAPIDFIRE_MASK = CTRL_UP | CTRL_DOWN | CTRL_LEFT | CTRL_RIGHT
static void __CtrlUpdateLatch()
{
lock_guard guard(ctrlMutex);

// Copy in the current data to the current buffer.
ctrlBufs[ctrlBuf] = ctrlCurrent;
u32 buttons = ctrlCurrent.buttons;
Expand All @@ -119,7 +119,7 @@ static void __CtrlUpdateLatch()
latch.btnRelease |= ~buttons;
dialogBtnMake |= buttons & changed;
ctrlLatchBufs++;

ctrlOldButtons = buttons;

ctrlBufs[ctrlBuf].frame = (u32) CoreTiming::GetGlobalTimeUs();
Expand Down Expand Up @@ -327,7 +327,7 @@ void __CtrlInit()
void __CtrlDoState(PointerWrap &p)
{
lock_guard guard(ctrlMutex);

auto s = p.Section("sceCtrl", 1, 3);
if (!s)
return;
Expand Down Expand Up @@ -519,7 +519,7 @@ static u32 sceCtrlReadLatch(u32 latchDataPtr)
return __CtrlResetLatch();
}

static const HLEFunction sceCtrl[] =
static const HLEFunction sceCtrl[] =
{
{0X3E65A0EA, nullptr, "sceCtrlInit", '?', "" }, //(int unknown), init with 0
{0X1F4011E6, &WrapU_U<sceCtrlSetSamplingMode>, "sceCtrlSetSamplingMode", 'x', "x" },
Expand All @@ -538,7 +538,7 @@ static const HLEFunction sceCtrl[] =
{0X6841BE1A, nullptr, "sceCtrlSetRapidFire", '?', "" },
{0XA7144800, &WrapI_II<sceCtrlSetIdleCancelThreshold>, "sceCtrlSetIdleCancelThreshold", 'i', "ii"},
{0X687660FA, &WrapI_UU<sceCtrlGetIdleCancelThreshold>, "sceCtrlGetIdleCancelThreshold", 'i', "xx"},
};
};

void Register_sceCtrl()
{
Expand Down
33 changes: 29 additions & 4 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,22 @@
#include "Windows/MainWindow.h"
#endif

bool frameStep_;
Copy link
Collaborator

@unknownbrackets unknownbrackets Aug 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be static or else be a member of EmuScreen. That way it will reset if you select a new game.

-[Unknown]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just decided to always reset it without making it part of EmuScreen.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but in that case they should be static. That means if some other .cpp file has a lastNumFlips (like say, some cheating or networking feature, or some other TAS code), it won't be the same variable.

-[Unknown]


static void __EmuScreenVblank()
{
if (frameStep_)
{
frameStep_ = false;
Core_EnableStepping(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, in EmuScreen this might actually be a better place:

https://github.com/RisingFog/ppsspp/blob/842a29b0aedd2e5db59128f3b25b06d803d27386/UI/EmuScreen.cpp#L980

This will be once per displayed frame though, so importantly:

  • If frameskip is enabled, it will not happen for skipped frames.
  • If the game runs at 30fps, it will be at 30fps.

-[Unknown]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't get it to update the screen properly while frame advancing.

}
}

EmuScreen::EmuScreen(const std::string &filename)
: bootPending_(true), gamePath_(filename), invalid_(true), quit_(false), pauseTrigger_(false), saveStatePreviewShownTime_(0.0), saveStatePreview_(nullptr) {
memset(axisState_, 0, sizeof(axisState_));
saveStateSlot_ = SaveState::GetCurrentSlot();
__DisplayListenVblank(__EmuScreenVblank);
}

void EmuScreen::bootGame(const std::string &filename) {
Expand Down Expand Up @@ -174,7 +186,7 @@ void EmuScreen::bootComplete() {
NOTICE_LOG(BOOT, "Loading %s...", PSP_CoreParameter().fileToStart.c_str());
autoLoad();

I18NCategory *sc = GetI18NCategory("Screen");
I18NCategory *sc = GetI18NCategory("Screen");

#ifndef MOBILE_DEVICE
if (g_Config.bFirstRun) {
Expand Down Expand Up @@ -341,7 +353,7 @@ bool EmuScreen::touch(const TouchInput &touch) {
}

void EmuScreen::onVKeyDown(int virtualKeyCode) {
I18NCategory *sc = GetI18NCategory("Screen");
I18NCategory *sc = GetI18NCategory("Screen");

switch (virtualKeyCode) {
case VIRTKEY_UNTHROTTLE:
Expand All @@ -363,6 +375,19 @@ void EmuScreen::onVKeyDown(int virtualKeyCode) {
pauseTrigger_ = true;
break;

case VIRTKEY_FRAME_ADVANCE:
// If game is running, pause emulation immediately. Otherwise, advance a single frame.
if (Core_IsStepping())
{
frameStep_ = true;
Core_EnableStepping(false);
}
else if (!frameStep_)
{
Core_EnableStepping(true);
}
break;

case VIRTKEY_AXIS_SWAP:
KeyMap::SwapAxis();
break;
Expand Down Expand Up @@ -778,7 +803,7 @@ void EmuScreen::update(InputState &input) {
}

float delta_y = tiltInputCurve(normalized_input_y * 2.0 * (g_Config.iTiltSensitivityY)) ;

if (g_Config.bInvertTiltY) {
delta_y *= -1;
}
Expand All @@ -787,7 +812,7 @@ void EmuScreen::update(InputState &input) {
leftstick_x += clamp1(delta_x);
__CtrlSetAnalogX(clamp1(leftstick_x), CTRL_STICK_LEFT);


leftstick_y += clamp1(delta_y);
__CtrlSetAnalogY(clamp1(leftstick_y), CTRL_STICK_LEFT);
}
Expand Down