// returns true if the game state was changed (loaded) bool PLAYBACK::setPlaybackAboveOrToFrame(int frame, bool forceStateReload) { bool state_changed = false; // search backwards for an earlier frame with valid savestate int i = greenzone.getSize() - 1; if (i > frame) i = frame; for (; i >= 0; i--) { if (!forceStateReload && !state_changed && i == currFrameCounter) { // we can remain at current game state break; } else if (!greenzone.isSavestateEmpty(i)) { state_changed = true; // after we once tried loading a savestate, we cannot use currFrameCounter state anymore, because the game state might have been corrupted by this loading attempt if (greenzone.loadSavestateOfFrame(i)) break; } } if (i < 0) { // couldn't find a savestate restartPlaybackFromZeroGround(); state_changed = true; } return state_changed; }
void PLAYBACK::ensurePlaybackIsInsideGreenzone(bool executeLua) { // set the Playback cursor to the frame or at least above the frame if (setPlaybackAboveOrToFrame(greenzone.getSize() - 1)) { // since the game state was changed by this jump, we must update possible Lua callbacks and other tools that would normally only update in FCEUI_Emulate if (executeLua) ForceExecuteLuaFrameFunctions(); Update_RAM_Search(); // Update_RAM_Watch() is also called. } // follow the Playback cursor, but in case of seeking don't follow it pianoRoll.followPlaybackCursorIfNeeded(false); }
void PLAYBACK::handleMiddleButtonClick() { if (emuPausedState) { // Unpause or start seeking // works only when right mouse button is released if (GetAsyncKeyState(GetSystemMetrics(SM_SWAPBUTTON) ? VK_LBUTTON : VK_RBUTTON) >= 0) { if (GetAsyncKeyState(VK_SHIFT) < 0) { // if Shift is held, seek to nearest Marker int last_frame = markersManager.getMarkersArraySize() - 1; // the end of movie Markers int target_frame = currFrameCounter + 1; for (; target_frame <= last_frame; ++target_frame) if (markersManager.getMarkerAtFrame(target_frame)) break; if (target_frame <= last_frame) startSeekingToFrame(target_frame); } else if (GetAsyncKeyState(VK_CONTROL) < 0) { // if Ctrl is held, seek to Selection cursor or replay from Selection cursor int selection_beginning = selection.getCurrentRowsSelectionBeginning(); if (selection_beginning > currFrameCounter) { startSeekingToFrame(selection_beginning); } else if (selection_beginning < currFrameCounter) { int saved_currFrameCounter = currFrameCounter; if (selection_beginning < 0) selection_beginning = 0; jump(selection_beginning); startSeekingToFrame(saved_currFrameCounter); } } else if (getPauseFrame() < 0 && getLastPosition() >= greenzone.getSize()) { restoreLastPosition(); } else { unpauseEmulation(); } } } else { pauseEmulation(); } }