diff --git a/src/drivers/win/input.cpp b/src/drivers/win/input.cpp index eaa8956d..af60d249 100644 --- a/src/drivers/win/input.cpp +++ b/src/drivers/win/input.cpp @@ -1531,7 +1531,7 @@ int FCEUD_TestCommandState(int c) // else // keys_nr=GetKeyboard_nr(); } - else if(c != EMUCMD_SPEED_TURBO) // TODO: this should be made more general by detecting if the command has an "off" function, but right now Turbo is the only command that has it + else if(c != EMUCMD_SPEED_TURBO && c != EMUCMD_TASEDIT_REWIND) // TODO: this should be made more general by detecting if the command has an "off" function { keys=GetKeyboard_jd(); keys_nr=GetKeyboard_nr(); diff --git a/src/drivers/win/mapinput.cpp b/src/drivers/win/mapinput.cpp index d8d492f5..a776c48d 100644 --- a/src/drivers/win/mapinput.cpp +++ b/src/drivers/win/mapinput.cpp @@ -70,9 +70,10 @@ static struct { EMUCMD_SCRIPT_RELOAD, SCAN_L | CMD_KEY_SHIFT, }, { EMUCMD_OPENROM, SCAN_O | CMD_KEY_CTRL, }, { EMUCMD_CLOSEROM, SCAN_W | CMD_KEY_CTRL, }, - { EMUCMD_RELOADROM, SCAN_R | CMD_KEY_CTRL | CMD_KEY_SHIFT , }, + { EMUCMD_RELOADROM, SCAN_R | CMD_KEY_CTRL | CMD_KEY_SHIFT , }, { EMUCMD_MISC_UNDOREDOSAVESTATE, SCAN_Z | CMD_KEY_CTRL, }, { EMUCMD_MISC_TOGGLEFULLSCREEN, SCAN_ENTER | CMD_KEY_ALT, }, + { EMUCMD_TASEDIT_REWIND, SCAN_GRAVE, }, }; #define NUM_DEFAULT_MAPPINGS (sizeof(DefaultCommandMapping)/sizeof(DefaultCommandMapping[0])) diff --git a/src/drivers/win/tasedit.cpp b/src/drivers/win/tasedit.cpp index 49586dbb..76ae7f8f 100644 --- a/src/drivers/win/tasedit.cpp +++ b/src/drivers/win/tasedit.cpp @@ -24,6 +24,7 @@ using namespace std; int old_multitrack_recording_joypad, multitrack_recording_joypad; bool old_movie_readonly; bool TASEdit_focus = false; +bool Tasedit_rewind_now = false; int listItems; // number of items per list page // saved FCEU config int saved_eoptions; @@ -417,7 +418,7 @@ void SingleClick(LPNMITEMACTIVATE info) { // click on the "icons" column - jump to the frame ClearSelection(); - playback.JumpToFrame(row_index); + playback.jump(row_index); RedrawList(); } else if(column_index == COLUMN_FRAMENUM || column_index == COLUMN_FRAMENUM2) { @@ -450,7 +451,7 @@ void DoubleClick(LPNMITEMACTIVATE info) { // double click sends playback to the frame ClearSelection(); - playback.JumpToFrame(row_index); + playback.jump(row_index); RedrawList(); } else if(column_index >= COLUMN_JOYPAD1_A && column_index <= COLUMN_JOYPAD4_R) { @@ -1034,9 +1035,7 @@ void OpenProject() tempstr.append(".tas"); splitpath(tempstr.c_str(), drv, dir, name, ext); //Split the path... project.SetProjectName(name); - std::string filename = name; //Get the filename - filename.append(ext); //Shove the extension back onto it... - project.SetProjectFile(filename); //And update the project's filename. + project.SetProjectFile(tempstr); //Set the fm2 name std::string thisfm2name = name; thisfm2name.append(".fm2"); @@ -1096,9 +1095,7 @@ bool SaveProjectAs() splitpath(tempstr.c_str(), drv, dir, name, ext); //Split it up... project.SetProjectName(name); - std::string filename = name; //Grab the name... - filename.append(ext); //Stick extension back on... - project.SetProjectFile(filename); //And update the project's filename. + project.SetProjectFile(tempstr); std::string thisfm2name = name; thisfm2name.append(".fm2"); //Setup the fm2 name project.SetFM2Name(thisfm2name); //Set the project's fm2 name @@ -1425,17 +1422,13 @@ BOOL CALLBACK WndprocTasEdit(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar if (selectionFrames.size()) ClearFrames(); break; case TASEDIT_REWIND_FULL: - //rewinds to beginning of greenzone - playback.JumpToFrame(greenzone.FindBeginningOfGreenZone()); - FollowPlayback(); + playback.RewindFull(); break; case TASEDIT_PLAYSTOP: playback.ToggleEmulationPause(); break; case TASEDIT_FORWARD_FULL: - //moves to the end of greenzone - playback.JumpToFrame(greenzone.greenZoneCount-1); - FollowPlayback(); + playback.ForwardFull(); break; case ACCEL_CTRL_F: case CHECK_FOLLOW_CURSOR: @@ -1741,6 +1734,7 @@ void EnterTasEdit() project.init(); history.init(TasEdit_undo_levels); SetFocus(hwndHistoryList); + greenzone.TryDumpIncremental(lagFlag != 0); FCEU_DispMessage("Tasedit engaged",0); } } diff --git a/src/drivers/win/taseditlib/greenzone.cpp b/src/drivers/win/taseditlib/greenzone.cpp index cb9ce979..dbccc43f 100644 --- a/src/drivers/win/taseditlib/greenzone.cpp +++ b/src/drivers/win/taseditlib/greenzone.cpp @@ -22,8 +22,9 @@ GREENZONE::GREENZONE() void GREENZONE::init() { - clearGreenzone(); + + currMovieData.frames_flags.resize(currMovieData.records.size()); reset(); } void GREENZONE::reset() @@ -42,7 +43,15 @@ void GREENZONE::TryDumpIncremental(bool lagFlag) if((int)currMovieData.records.size() <= currFrameCounter) currMovieData.insertEmpty(-1, 1 + currFrameCounter - (int)currMovieData.records.size()); - // if frame chanegd - log savestate + // update greenzone upper limit + if (greenZoneCount <= currFrameCounter) + greenZoneCount = currFrameCounter+1; + if ((int)savestates.size() < greenZoneCount) + savestates.resize(greenZoneCount); + if ((int)currMovieData.frames_flags.size() < greenZoneCount) + currMovieData.frames_flags.resize(greenZoneCount); + + // if frame changed - log savestate storeTasSavestate(currFrameCounter); // also log frame_flags if (currFrameCounter > 0) @@ -53,9 +62,8 @@ void GREENZONE::TryDumpIncremental(bool lagFlag) else currMovieData.frames_flags[currFrameCounter-1] &= ~LAG_FLAG_BIT; } - // update greenzone upper limit - if (greenZoneCount <= currFrameCounter) - greenZoneCount = currFrameCounter+1; + + ClearGreenzoneTail(); } @@ -109,8 +117,9 @@ void GREENZONE::clearGreenzone() { ClearSavestate(i); } - greenZoneCount = 1; - currMovieData.frames_flags.resize(1); + savestates.resize(0); + greenZoneCount = 0; + currMovieData.frames_flags.resize(0); // reset lua_colorings // reset monitorings @@ -226,7 +235,7 @@ void GREENZONE::InvalidateGreenZone(int after) if (TASEdit_restore_position) playback.restorePosition(); else - playback.JumpToFrame(greenZoneCount-1); + playback.jump(greenZoneCount-1); } } // redraw list even if greenzone didn't change diff --git a/src/drivers/win/taseditlib/playback.cpp b/src/drivers/win/taseditlib/playback.cpp index 8de835f0..702e76fb 100644 --- a/src/drivers/win/taseditlib/playback.cpp +++ b/src/drivers/win/taseditlib/playback.cpp @@ -5,10 +5,15 @@ #include "taseditproj.h" #include "../tasedit.h" +#ifdef _S9XLUA_H +extern void ForceExecuteLuaFrameFunctions(); +#endif + extern HWND hwndProgressbar, hwndList, hwndRewind, hwndForward; extern void FCEU_printf(char *format, ...); extern bool turbo; extern GREENZONE greenzone; +extern bool Tasedit_rewind_now; PLAYBACK::PLAYBACK() { @@ -59,9 +64,12 @@ void PLAYBACK::update() old_pauseframe = pauseframe; old_show_pauseframe = show_pauseframe; if (pauseframe) - show_pauseframe = (int)(clock() / PAUSEFRAME_BLINKING_PERIOD) & 1; - else - show_pauseframe = false; + { + if (emu_paused) + show_pauseframe = (int)(clock() / PAUSEFRAME_BLINKING_PERIOD_PAUSED) & 1; + else + show_pauseframe = (int)(clock() / PAUSEFRAME_BLINKING_PERIOD_SEEKING) & 1; + } else show_pauseframe = false; if (old_show_pauseframe != show_pauseframe) RedrawRow(pauseframe-1); //update the playback cursor @@ -79,7 +87,7 @@ void PLAYBACK::update() if(emu_paused) { old_rewind_button_state = rewind_button_state; - rewind_button_state = (Button_GetState(hwndRewind) & BST_PUSHED) != 0; + rewind_button_state = ((Button_GetState(hwndRewind) & BST_PUSHED) != 0 || Tasedit_rewind_now); if (rewind_button_state) { if (!old_rewind_button_state) @@ -93,7 +101,7 @@ void PLAYBACK::update() } old_forward_button_state = forward_button_state; forward_button_state = (Button_GetState(hwndForward) & BST_PUSHED) != 0; - if (forward_button_state) + if (forward_button_state && !rewind_button_state) { if (!old_forward_button_state) { @@ -156,16 +164,28 @@ void PLAYBACK::SeekingStop() void PLAYBACK::RewindFrame() { - if (currFrameCounter > 0) JumpToFrame(currFrameCounter-1); + if (currFrameCounter > 0) jump(currFrameCounter-1); turbo = false; FollowPlayback(); } void PLAYBACK::ForwardFrame() { - JumpToFrame(currFrameCounter+1); + jump(currFrameCounter+1); turbo = false; FollowPlayback(); } +void PLAYBACK::RewindFull() +{ + // rewind to the beginning of greenzone + jump(greenzone.FindBeginningOfGreenZone()); + FollowPlayback(); +} +void PLAYBACK::ForwardFull() +{ + // move to the end of greenzone + jump(greenzone.greenZoneCount-1); + FollowPlayback(); +} void PLAYBACK::StartFromZero() { @@ -174,6 +194,19 @@ void PLAYBACK::StartFromZero() greenzone.TryDumpIncremental(); } +void PLAYBACK::jump(int frame) +{ + if (JumpToFrame(frame)) + ForceExecuteLuaFrameFunctions(); +} +void PLAYBACK::restorePosition() +{ + if (pauseframe) + jump(pauseframe-1); + else + jump(currFrameCounter); +} + bool PLAYBACK::JumpToFrame(int index) { // Returns true if a jump to the frame is made, false if started seeking or if nothing's done @@ -211,14 +244,6 @@ bool PLAYBACK::JumpToFrame(int index) return false; } -void PLAYBACK::restorePosition() -{ - if (pauseframe) - JumpToFrame(pauseframe-1); - else - JumpToFrame(currFrameCounter); -} - int PLAYBACK::GetPauseFrame() { if (show_pauseframe) diff --git a/src/drivers/win/taseditlib/playback.h b/src/drivers/win/taseditlib/playback.h index 71f7e5d8..9bb697e7 100644 --- a/src/drivers/win/taseditlib/playback.h +++ b/src/drivers/win/taseditlib/playback.h @@ -1,6 +1,8 @@ //Specification file for Playback class -#define PAUSEFRAME_BLINKING_PERIOD 100 +#define PAUSEFRAME_BLINKING_PERIOD_SEEKING 100 +#define PAUSEFRAME_BLINKING_PERIOD_PAUSED 250 + #define HOLD_REPEAT_DELAY 250 // in milliseconds @@ -12,6 +14,9 @@ public: void reset(); void update(); + void jump(int frame); + void restorePosition(); + void updateProgressbar(); void SeekingStart(int finish_frame); @@ -22,9 +27,9 @@ public: void RewindFrame(); void ForwardFrame(); + void RewindFull(); + void ForwardFull(); - bool JumpToFrame(int index); - void restorePosition(); void StartFromZero(); @@ -34,6 +39,7 @@ public: int pauseframe; private: + bool JumpToFrame(int index); int lastCursor; // for currentCursor we use external variable currFrameCounter bool old_emu_paused, emu_paused; diff --git a/src/fceu.cpp b/src/fceu.cpp index 46a2f48f..8e18d635 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -721,7 +721,7 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski #ifdef WIN32 if(FCEUMOV_Mode(MOVIEMODE_TASEDIT)) - greenzone.TryDumpIncremental(lagFlag); + greenzone.TryDumpIncremental((bool)lagFlag); #endif } diff --git a/src/input.cpp b/src/input.cpp index 3b0a175d..cebf7cea 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -51,6 +51,8 @@ #include "drivers/win/memview.h" #include "drivers/win/window.h" #include "drivers/win/ntview.h" + +extern bool Tasedit_rewind_now; #endif // WIN32 //it is easier to declare these input drivers extern here than include a bunch of files @@ -645,6 +647,8 @@ static void MovieSubtitleToggle(void); static void UndoRedoSavestate(void); static void FCEUI_DoExit(void); static void ToggleFullscreen(void); +static void TaseditRewindOn(void); +static void TaseditRewindOff(void); struct EMUCMDTABLE FCEUI_CommandTable[]= { @@ -768,6 +772,7 @@ struct EMUCMDTABLE FCEUI_CommandTable[]= { EMUCMD_TOOL_RAMSEARCHGTE, EMUCMDTYPE_TOOL, RamSearchOpGTE, 0, 0, "Ram Search - Greater Than or Equal", 0}, { EMUCMD_TOOL_RAMSEARCHEQ, EMUCMDTYPE_TOOL, RamSearchOpEQ, 0, 0, "Ram Search - Equal", 0}, { EMUCMD_TOOL_RAMSEARCHNE, EMUCMDTYPE_TOOL, RamSearchOpNE, 0, 0, "Ram Search - Not Equal", 0}, + { EMUCMD_TASEDIT_REWIND, EMUCMDTYPE_TOOL, TaseditRewindOn, TaseditRewindOff, 0, "Rewind Frame (Tasedit-only)", EMUCMDFLAG_TASEDIT}, }; #define NUM_EMU_CMDS (sizeof(FCEUI_CommandTable)/sizeof(FCEUI_CommandTable[0])) @@ -1103,4 +1108,19 @@ static void ToggleFullscreen(void) SetVideoMode(oldmode); changerecursive=0; #endif -} \ No newline at end of file +} + +static void TaseditRewindOn(void) +{ +#ifdef WIN32 + Tasedit_rewind_now = true; +#endif +} +static void TaseditRewindOff(void) +{ +#ifdef WIN32 + Tasedit_rewind_now = false; +#endif +} + + diff --git a/src/input.h b/src/input.h index fba788c3..b32b7fdb 100644 --- a/src/input.h +++ b/src/input.h @@ -215,7 +215,7 @@ enum EMUCMD //Currently only windows (but sdl could easily add onto these) EMUCMD_OPENROM, EMUCMD_CLOSEROM, - EMUCMD_RELOADROM, + EMUCMD_RELOADROM, //----------------------------- EMUCMD_MISC_DISPLAY_MOVIESUBTITLES, EMUCMD_MISC_UNDOREDOSAVESTATE, @@ -228,9 +228,11 @@ enum EMUCMD EMUCMD_TOOL_RAMSEARCHGTE, EMUCMD_TOOL_RAMSEARCHEQ, EMUCMD_TOOL_RAMSEARCHNE, + EMUCMD_TOOL_OPENNTVIEW, //----------------------------- //keep adding these in order of newness or else the hotkey binding configs will get messed up... - EMUCMD_TOOL_OPENNTVIEW, + EMUCMD_TASEDIT_REWIND, + EMUCMD_MAX }; diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 7555f161..96c70348 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -1869,6 +1869,13 @@ void CallRegisteredLuaFunctions(LuaCallID calltype) } } +void ForceExecuteLuaFrameFunctions() +{ + FCEU_LuaFrameBoundary(); + CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION); + CallRegisteredLuaFunctions(LUACALL_AFTEREMULATION); +} + // Not for the signed versions though static int memory_readbytesigned(lua_State *L) { signed char c = (signed char) FCEU_CheatGetByte(luaL_checkinteger(L,1)); diff --git a/src/movie.h b/src/movie.h index ac673f58..ec800cfc 100644 --- a/src/movie.h +++ b/src/movie.h @@ -178,7 +178,6 @@ public: std::string romFilename; std::vector savestate; std::vector records; - //std::vector > savestates; std::vector frames_flags; std::vector comments; std::vector subtitles;