From d2a886ebb15178df548d80dc222ba2fdd1ca9732 Mon Sep 17 00:00:00 2001 From: ansstuff Date: Mon, 19 Sep 2011 18:13:31 +0000 Subject: [PATCH] * Tasedit: accelerator table * Tasedit: new menu item "Config" * Tasedit: Config->"Set greenzone capacity", auto-clearing old savestates * Tasedit: pauseframe is shown by flashing color --- src/drivers/win/Win32InputBox.cpp | 6 +- src/drivers/win/config.cpp | 2 + src/drivers/win/res.rc | 27 ++-- src/drivers/win/res/te_arrow.bmp | Bin 220 -> 1174 bytes src/drivers/win/resource.h | 5 +- src/drivers/win/tasedit.cpp | 170 ++++++++++++--------- src/drivers/win/tasedit.h | 8 +- src/drivers/win/taseditlib/taseditproj.cpp | 5 +- src/drivers/win/window.cpp | 1 - src/fceu.cpp | 1 + src/movie.cpp | 105 ++++++++----- src/movie.h | 6 +- 12 files changed, 204 insertions(+), 132 deletions(-) diff --git a/src/drivers/win/Win32InputBox.cpp b/src/drivers/win/Win32InputBox.cpp index ad10be13..b9ab4fb6 100644 --- a/src/drivers/win/Win32InputBox.cpp +++ b/src/drivers/win/Win32InputBox.cpp @@ -13,6 +13,9 @@ History - Lessened the complexity of the class, made it less generic (since its purpose is to be simple) - Updated the dialog template and made OK button as default button +18-Sept-2011 +- AnS: added szResult initializing to GetInteger + */ typedef struct _MSDN_DLGTEMPLATEEX @@ -228,7 +231,8 @@ INT_PTR CWin32InputBox::GetInteger( { WIN32INPUTBOX_PARAM param; - char szResult[20] = {'0'}; + char szResult[20]; + itoa(result,szResult,10); param.szTitle = szTitle; param.szPrompt = szPrompt; param.szResult = szResult; diff --git a/src/drivers/win/config.cpp b/src/drivers/win/config.cpp index 22f6f3d7..923bbd0d 100644 --- a/src/drivers/win/config.cpp +++ b/src/drivers/win/config.cpp @@ -71,6 +71,7 @@ extern bool TASEdit_follow_playback; extern bool TASEdit_show_lag_frames; extern bool TASEdit_show_tweak_count; extern bool TASEdit_restore_position; +extern int TASEdit_greenzone_capacity; //window positions and sizes: extern int ChtPosX,ChtPosY; @@ -290,6 +291,7 @@ static CFGSTRUCT fceuconfig[] = { AC(TASEdit_show_lag_frames), AC(TASEdit_show_tweak_count), AC(TASEdit_restore_position), + AC(TASEdit_greenzone_capacity), AC(lagCounterDisplay), AC(oldInputDisplay), AC(movieSubtitles), diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 471f90b3..3c6c3881 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -233,21 +233,23 @@ BEGIN MENUITEM "Cu&t\tCtrl+X", ID_TASEDIT_CUT MENUITEM "&Copy\tCtrl+C", ID_TASEDIT_COPY MENUITEM "&Paste\tCtrl+V", ID_TASEDIT_PASTE - MENUITEM "Paste to &New\tCtrl+Shift+V", ID_TASEDIT_PASTETONEW, INACTIVE MENUITEM "&Delete\tCtrl+Delete", ID_TASEDIT_DELETE MENUITEM SEPARATOR MENUITEM "&Add Marker", ID_EDIT_ADDMARKER, INACTIVE MENUITEM "&Remove Marker", ID_EDIT_REMOVEMARKER, INACTIVE MENUITEM SEPARATOR MENUITEM "&Truncate\tCtrl+T", ID_EDIT_TRUNCATE - MENUITEM "&Branch\tCtrl+B", ID_EDIT_BRANCH, INACTIVE END POPUP "&View" BEGIN MENUITEM "Highlight &lag frames", ID_VIEW_SHOW_LAG_FRAMES MENUITEM "Show T&weak count", ID_VIEW_SHOW_TWEAK_COUNT MENUITEM SEPARATOR - MENUITEM "&Follow playback", ID_VIEW_FOLLOW_PLAYBACK + MENUITEM "&Follow playback\tCtrl+F", ID_VIEW_FOLLOW_PLAYBACK + END + POPUP "Config" + BEGIN + MENUITEM "Set greenzone capacity", ID_CONFIG_SETGREENZONECAPACITY END POPUP "&Help" BEGIN @@ -339,13 +341,10 @@ BEGIN MENUITEM "Insert number of Frames", ID_CONTEXT_SELECTED_INSERTFRAMES2 MENUITEM "Delete Frame(s)", ID_CONTEXT_SELECTED_DELETEFRAMES MENUITEM SEPARATOR - MENUITEM "Paste to New", ID_CONTEXT_SELECTED_PASTETONEW, INACTIVE - MENUITEM SEPARATOR MENUITEM "Add Marker", ID_CONTEXT_SELECTED_ADDMARKER, INACTIVE MENUITEM "Remove Marker", ID_CONTEXT_SELECTED_REMOVEMARKER, INACTIVE MENUITEM SEPARATOR MENUITEM "Truncate", ID_CONTEXT_SELECTED_TRUNCATE - MENUITEM "Branch", ID_CONTEXT_SELECTED_BRANCH, INACTIVE END END @@ -1341,7 +1340,7 @@ CAPTION "TAS Editor" MENU TASEDITMENU FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - CONTROL "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,5,324,370 + CONTROL "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | LVS_NOSORTHEADER | WS_BORDER,7,5,324,370 PUSHBUTTON "<<",TASEDIT_REWIND_FULL,341,14,22,14 PUSHBUTTON "<",TASEDIT_REWIND,363,14,22,14 PUSHBUTTON "||",TASEDIT_PLAYSTOP,385,14,22,14 @@ -1349,7 +1348,7 @@ BEGIN PUSHBUTTON ">>",TASEDIT_FOWARD_FULL,429,14,22,14 GROUPBOX "Playback control",IDC_STATIC,337,5,118,41,BS_CENTER,WS_EX_RIGHT GROUPBOX "Project Input Logs",IDC_STATIC,337,246,118,129,BS_CENTER,WS_EX_RIGHT - CONTROL "",IDC_LIST2,"SysListView32",LVS_LIST | LVS_ALIGNLEFT | LVS_OWNERDATA | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,342,257,109,114 + CONTROL "",IDC_LIST2,"SysListView32",LVS_LIST | LVS_ALIGNLEFT | LVS_OWNERDATA | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,342,257,109,114,WS_EX_LEFTSCROLLBAR LTEXT "Tweak Count",IDC_TWEAKCOUNT,344,113,84,8 GROUPBOX "Recording input",IDC_STATIC,337,47,118,62,BS_CENTER,WS_EX_RIGHT CONTROL " Auto-restore last position",CHECK_AUTORESTORE_PLAYBACK, @@ -1989,16 +1988,14 @@ END IDR_ACCELERATOR1 ACCELERATORS BEGIN - "B", ACCEL_CTRL_B, VIRTKEY, CONTROL, NOINVERT VK_DELETE, ACCEL_CTRL_DELETE, VIRTKEY, CONTROL, NOINVERT - "E", ACCEL_CTRL_E, VIRTKEY, CONTROL, NOINVERT - "N", ACCEL_CTRL_N, VIRTKEY, CONTROL, NOINVERT - "O", ACCEL_CTRL_O, VIRTKEY, CONTROL, NOINVERT "S", ACCEL_CTRL_S, VIRTKEY, CONTROL, NOINVERT - "S", ACCEL_CTRL_SHIFT_S, VIRTKEY, SHIFT, CONTROL, NOINVERT - "V", ACCEL_CTRL_SHIFT_V, VIRTKEY, SHIFT, CONTROL, NOINVERT "T", ACCEL_CTRL_T, VIRTKEY, CONTROL, NOINVERT - "W", ACCEL_CTRL_W, VIRTKEY, CONTROL, NOINVERT + "C", ACCEL_CTRL_C, VIRTKEY, CONTROL, NOINVERT + "V", ACCEL_CTRL_V, VIRTKEY, CONTROL, NOINVERT + "X", ACCEL_CTRL_X, VIRTKEY, CONTROL, NOINVERT + "F", ACCEL_CTRL_F, VIRTKEY, CONTROL, NOINVERT + "P", ACCEL_CTRL_P, VIRTKEY, CONTROL, NOINVERT END IDR_RWACCELERATOR ACCELERATORS diff --git a/src/drivers/win/res/te_arrow.bmp b/src/drivers/win/res/te_arrow.bmp index 2d2578897377a62f74d8450ed0af7aa56796edf3..9ccc5a4e104f7c5803df5e5a525c61fde1a29cfb 100644 GIT binary patch literal 1174 zcmY+?A+H)i5Ww*vp$P(mL7`CPRZh|bi$~&7qxl9!H%QWCJauR^A7CV*35q=X5S65e z>3{aoHod*y?lRon&duIz{;ezR_{{i`Sr2`5+Dv50{O{3WRwVzNj9Dj>I-SaFHk0{$ zE{nxNmdmA>nXFbTS+Cc!*=%IH-HN-*Znu;DelLf^p{*Seayp&la=FO$dX?MlCinYY z9*+k(rYJcW9D&NOf-EZrM<7ubDp*<^fkfS`Fpz=-67@iZ!9gmLs6`Y8N1*COv^Ar5 z1X_k9V{il#m7K!h2qY?Dg~1U>)JrG~jzFSbOkr>Y5-h;#)|%4?5>)_&!4XJQQ523q zqKc$2I0A_(oWkG;B&wJSgCmgOL9HT0TMPO`61(4E21g)Ko3Ai90*U${6b45iQ6GuI;7HJs3o$qX3I1qb z2vuqoA=(-jlMA~AM^sk(nco#jn8=9`F>T6_3Pj98<(u3OaK4? literal 220 zcmZ?ry~6+jRX|Duh&h0m2Z$NLECz-oAX|tVf(3zW5dIH>2M#d&{|}_ez(6D5fRPcx eWP~z+G*|>ggBV~M$Uvc?;vk(6RUjI~Lk0k)Eiq&O diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index 88ccf63f..d0e94b1b 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -817,6 +817,9 @@ #define ID_CONTEXT_SELECTED_INSERTFRAME 40423 #define ID_SELECTED_INSERTFRAMES40424 40424 #define ID_CONTEXT_SELECTED_INSERTFRAMES2 40425 +#define ACCEL_CTRL_F 40429 +#define ACCEL_CTRL_P 40430 +#define ID_CONFIG_SETGREENZONECAPACITY 40432 #define IDC_DEBUGGER_ICONTRAY 55535 #define MW_ValueLabel2 65423 #define MW_ValueLabel1 65426 @@ -826,7 +829,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 160 -#define _APS_NEXT_COMMAND_VALUE 40426 +#define _APS_NEXT_COMMAND_VALUE 40433 #define _APS_NEXT_CONTROL_VALUE 1262 #define _APS_NEXT_SYMED_VALUE 101 #endif diff --git a/src/drivers/win/tasedit.cpp b/src/drivers/win/tasedit.cpp index 089879e7..0fad0f9f 100644 --- a/src/drivers/win/tasedit.cpp +++ b/src/drivers/win/tasedit.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "common.h" #include "tasedit.h" @@ -22,6 +23,10 @@ using namespace std; //http://forums.devx.com/archive/index.php/t-37234.html int old_movie_readonly = -1; +int lastCursor; +int old_pauseframe; +bool old_show_pauseframe; +bool show_pauseframe; // vars saved in cfg file int TasEdit_wndx, TasEdit_wndy; @@ -29,6 +34,7 @@ bool TASEdit_follow_playback = true; bool TASEdit_show_lag_frames = true; bool TASEdit_show_tweak_count = false; bool TASEdit_restore_position = false; +int TASEdit_greenzone_capacity = GREENZONE_DEFAULT_CAPACITY; string tasedithelp = "{16CDE0C4-02B0-4A60-A88D-076319909A4D}"; //Name of TASEdit Help page char buttonNames[NUM_JOYPAD_BUTTONS][2] = {"A", "B", "S", "T", "U", "D", "L", "R"}; @@ -36,7 +42,6 @@ char buttonNames[NUM_JOYPAD_BUTTONS][2] = {"A", "B", "S", "T", "U", "D", "L", "R HWND hwndTasEdit = 0; static HMENU hmenu, hrmenu; -static int lastCursor; static HWND hwndList, hwndHeader, hwndTweakCount; static RECT rectTweakCount; static WNDPROC hwndHeader_oldWndproc, hwndList_oldWndProc; @@ -114,7 +119,7 @@ static LONG CustomDraw(NMLVCUSTOMDRAW* msg) if(cell_x == COLUMN_FRAMENUM || cell_x == COLUMN_FRAMENUM2) { // frame number - if (cell_y == currFrameCounter) + if (cell_y == currFrameCounter || (cell_y == pauseframe-1 && show_pauseframe)) { // current frame msg->clrTextBk = CUR_FRAMENUM_COLOR; @@ -133,7 +138,7 @@ static LONG CustomDraw(NMLVCUSTOMDRAW* msg) } else if((cell_x - COLUMN_JOYPAD1_A) / NUM_JOYPAD_BUTTONS == 0 || (cell_x - COLUMN_JOYPAD1_A) / NUM_JOYPAD_BUTTONS == 2) { // pad 1 or 3 - if (cell_y == currFrameCounter) + if (cell_y == currFrameCounter || (cell_y == pauseframe-1 && show_pauseframe)) { // current frame msg->clrTextBk = CUR_INPUT_COLOR1; @@ -152,7 +157,7 @@ static LONG CustomDraw(NMLVCUSTOMDRAW* msg) } else if((cell_x - COLUMN_JOYPAD1_A) / NUM_JOYPAD_BUTTONS == 1 || (cell_x - COLUMN_JOYPAD1_A) / NUM_JOYPAD_BUTTONS == 3) { // pad 2 or 4 - if (cell_y == currFrameCounter) + if (cell_y == currFrameCounter || (cell_y == pauseframe-1 && show_pauseframe)) { // current frame msg->clrTextBk = CUR_INPUT_COLOR2; @@ -176,13 +181,6 @@ static LONG CustomDraw(NMLVCUSTOMDRAW* msg) } } -void ExitTasEdit() -{ - movieMode = MOVIEMODE_INACTIVE; - FCEU_DispMessage("Tasedit disengaged",0); - CreateCleanMovie(); -} - // called from the rest of the emulator when things happen and the tasedit should change to reflect it void UpdateTasEdit() { @@ -209,11 +207,22 @@ void UpdateTasEdit() { FollowPlayback(); //update the old and new rows - ListView_RedrawItems(hwndList,lastCursor,lastCursor); - ListView_RedrawItems(hwndList,currFrameCounter,currFrameCounter); + RedrawRow(lastCursor); + RedrawRow(currFrameCounter); UpdateWindow(hwndList); lastCursor = currFrameCounter; } + + // update flashing pauseframe + if (old_pauseframe != pauseframe && old_pauseframe > 0) RedrawRow(old_pauseframe-1); + old_pauseframe = pauseframe; + old_show_pauseframe = show_pauseframe; + if (pauseframe > 0) + show_pauseframe = (int)(clock() / PAUSEFRAME_BLINKING_PERIOD) & 1; + else + show_pauseframe = false; + if (old_show_pauseframe != show_pauseframe) RedrawRow(pauseframe-1); + // update window caption if ((!old_movie_readonly) == movie_readonly) { @@ -228,13 +237,18 @@ void UpdateTasEdit() } } +void RedrawTasedit() +{ + InvalidateRect(hwndTasEdit,0,FALSE); +} void RedrawList() { InvalidateRect(hwndList,0,FALSE); } -void RedrawTasedit() +void RedrawRow(int index) { - InvalidateRect(hwndTasEdit,0,FALSE); + if (ListView_IsItemVisible(hwndList, index)) + ListView_RedrawItems(hwndList,index,index); } void RedrawTweakCount() { @@ -302,7 +316,10 @@ void InvalidateGreenZone(int after) { if (TASEdit_restore_position) { - JumpToFrame(currFrameCounter); + if (pauseframe-1 > currFrameCounter) + JumpToFrame(pauseframe-1); + else + JumpToFrame(currFrameCounter); turbo = true; } else { @@ -314,13 +331,9 @@ void InvalidateGreenZone(int after) RedrawList(); } -/* A function that tries jumping to a given frame. If unsuccessful, it than tries to jump to - a previously good frame and fastforward to it. - - Returns true if a jump to the frame is made, false if nothing done. - */ bool JumpToFrame(int index) { + // Returns true if a jump to the frame is made, false if nothing's done. if (index<0) return false; if (index >= currMovieData.greenZoneCount) @@ -340,6 +353,13 @@ bool JumpToFrame(int index) if (currMovieData.loadTasSavestate(index)) { currFrameCounter = index; + // if playback was seeking, pause emulation right here + if (pauseframe > 0) + { + if (!FCEUI_EmulationPaused()) FCEUI_ToggleEmulationPause(); + pauseframe = -1; + } + turbo = false; return true; } //Search for an earlier frame with savestate @@ -373,11 +393,11 @@ void DoubleClick(LPNMITEMACTIVATE info) //if the icon or frame columns were double clicked: if(info->iSubItem == COLUMN_ARROW) { - // set bookmark (of current bookmark slot) here } else if(info->iSubItem == COLUMN_FRAMENUM || info->iSubItem == COLUMN_FRAMENUM2) { JumpToFrame(index); + ClearSelection(); } else if(info->iSubItem >= COLUMN_JOYPAD1_A && info->iSubItem <= COLUMN_JOYPAD4_R) { @@ -398,7 +418,6 @@ void DoubleClick(LPNMITEMACTIVATE info) { //update one row currMovieData.records[index].toggleBit(joy,bit); - //ListView_RedrawItems(hwndList,index,index); } InvalidateGreenZone(index); } @@ -412,7 +431,6 @@ static void ClearSelection() ListView_SetItemState(hwndList,-1,0, LVIS_SELECTED); selectionFrames.clear(); - lastCursor=-1; } //insert frames at the currently selected positions. @@ -681,31 +699,19 @@ static bool Paste() return result; } -//pastes the current clipboard selection into a new inputlog -static void PastetoNew() -{ -} - //removes the current selection (does not put in clipboard) static void Delete() { DeleteFrames(); } -//Adds a marker to left column at selected frame (if multiple frames selected, it is placed at end of selection) void AddMarker() { } - -//Removes marker from selected frame (if multiple frames selected, all markers in selection removed? void RemoveMarker() { } -//Makes new branch (timeline), takes current frame and creates new input log of all frames before it, new input log will be in focus -void Branch() -{ -} // --------------------------------------------------------------------------------- //The subclass wndproc for the listview header @@ -723,7 +729,7 @@ static LRESULT APIENTRY HeaderWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lP info.pt.x = GET_X_LPARAM(lParam); info.pt.y = GET_Y_LPARAM(lParam); SendMessage(hWnd,HDM_HITTEST,0,(LPARAM)&info); - if(info.iItem != -1) + if(info.iItem >= COLUMN_JOYPAD1_A && info.iItem <= COLUMN_JOYPAD4_R) ColumnSet(info.iItem); } } @@ -769,9 +775,9 @@ static void InitDialog() hwndList_oldWndProc = (WNDPROC)SetWindowLong(hwndList,GWL_WNDPROC,(LONG)ListWndProc); //setup all images for the listview - HIMAGELIST himglist = ImageList_Create(8,12,ILC_COLOR32 | ILC_MASK,1,1); + HIMAGELIST himglist = ImageList_Create(8,12,ILC_COLOR8 | ILC_MASK,1,1); HBITMAP bmp = LoadBitmap(fceu_hInstance,MAKEINTRESOURCE(IDB_TE_ARROW)); - ImageList_AddMasked(himglist, bmp, RGB(255,0,255)); + ImageList_AddMasked(himglist, bmp, 0xFF00FF); DeleteObject(bmp); ListView_SetImageList(hwndList,himglist,LVSIL_SMALL); //doesnt work well?? @@ -782,10 +788,11 @@ static void InitDialog() int colidx=0; // arrow column lvc.mask = LVCF_WIDTH; - lvc.cx = 14; + lvc.cx = 12; ListView_InsertColumn(hwndList, colidx++, &lvc); // frame number column - lvc.mask = LVCF_WIDTH | LVCF_TEXT; + lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_FMT; + lvc.fmt = LVCFMT_CENTER; lvc.cx = 92; lvc.pszText = "Frame#"; ListView_InsertColumn(hwndList, colidx++, &lvc); @@ -809,7 +816,8 @@ static void InitDialog() void AddFourscoreColumns() { LVCOLUMN lvc; - lvc.mask = LVCF_WIDTH | LVCF_TEXT; + lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_FMT; + lvc.fmt = LVCFMT_CENTER; lvc.cx = 21; int colidx = COLUMN_JOYPAD3_A; for (int joy = 0; joy < 2; ++joy) @@ -918,7 +926,9 @@ static void OpenProject() RemoveFourscoreColumns(); else if (!last_fourscore && currMovieData.fourscore) AddFourscoreColumns(); + if (!FCEUI_EmulationPaused()) FCEUI_ToggleEmulationPause(); FollowPlayback(); + RedrawTasedit(); } } @@ -1146,12 +1156,10 @@ BOOL CALLBACK WndprocTasEdit(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar case WM_COMMAND: switch(LOWORD(wParam)) { - case ACCEL_CTRL_N: case ID_FILE_NEWPROJECT: NewProject(); break; - case ACCEL_CTRL_O: case ID_FILE_OPENPROJECT: OpenProject(); break; @@ -1161,7 +1169,6 @@ BOOL CALLBACK WndprocTasEdit(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar SaveProject(); break; - case ACCEL_CTRL_SHIFT_S: case ID_FILE_SAVEPROJECTAS: SaveProjectAs(); break; @@ -1198,12 +1205,6 @@ BOOL CALLBACK WndprocTasEdit(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar Paste(); break; - case ACCEL_CTRL_SHIFT_V: //Takes selected frames and creates new inputlog files - case ID_TASEDIT_PASTETONEW: - case ID_CONTEXT_SELECTED_PASTETONEW: - PastetoNew(); - break; - case ACCEL_CTRL_DELETE: case ID_TASEDIT_DELETE: Delete(); @@ -1225,11 +1226,6 @@ BOOL CALLBACK WndprocTasEdit(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar case ID_CONTEXT_STRAY_TRUNCATE: Truncate(); break; - case ACCEL_CTRL_B: - case ID_EDIT_BRANCH: - case ID_CONTEXT_SELECTED_BRANCH: - Branch(); - break; case ID_HELP_TASEDITHELP: OpenHelpWindow(tasedithelp); @@ -1239,20 +1235,23 @@ BOOL CALLBACK WndprocTasEdit(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar case MENU_CONTEXT_STRAY_INSERTFRAMES: case ID_CONTEXT_SELECTED_INSERTFRAMES2: { - int frames; + int frames = 1; if(CWin32InputBox::GetInteger("Insert Frames", "How many frames?", frames, hwndDlg) == IDOK) { - if (selectionFrames.size()) + if (frames > 0) { - // insert at selection - int index = *selectionFrames.begin(); - currMovieData.insertEmpty(index,frames); - InvalidateGreenZone(index); - } else - { - // insert at playback cursor - currMovieData.insertEmpty(currFrameCounter,frames); - InvalidateGreenZone(currFrameCounter); + if (selectionFrames.size()) + { + // insert at selection + int index = *selectionFrames.begin(); + currMovieData.insertEmpty(index,frames); + InvalidateGreenZone(index); + } else + { + // insert at playback cursor + currMovieData.insertEmpty(currFrameCounter,frames); + InvalidateGreenZone(currFrameCounter); + } } } } @@ -1296,11 +1295,16 @@ BOOL CALLBACK WndprocTasEdit(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar JumpToFrame(currMovieData.greenZoneCount-1); FollowPlayback(); break; + case ACCEL_CTRL_F: case ID_VIEW_FOLLOW_PLAYBACK: //switch "Follow playback" flag TASEdit_follow_playback ^= 1; CheckMenuItem(hmenu, ID_VIEW_FOLLOW_PLAYBACK, TASEdit_follow_playback?MF_CHECKED : MF_UNCHECKED); - FollowPlayback(); + // if switched off then jump to selection + if (TASEdit_follow_playback) + FollowPlayback(); + else if (selectionFrames.size()) + ListView_EnsureVisible(hwndList,(int)*selectionFrames.begin(),FALSE); break; case ID_VIEW_SHOW_LAG_FRAMES: //switch "Highlight lag frames" flag @@ -1314,10 +1318,29 @@ BOOL CALLBACK WndprocTasEdit(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar CheckMenuItem(hmenu, ID_VIEW_SHOW_TWEAK_COUNT, TASEdit_show_tweak_count?MF_CHECKED : MF_UNCHECKED); RedrawTweakCount(); break; + case ACCEL_CTRL_P: case CHECK_AUTORESTORE_PLAYBACK: + //switch "Auto-restore last playback position" flag TASEdit_restore_position ^= 1; CheckDlgButton(hwndTasEdit,CHECK_AUTORESTORE_PLAYBACK,TASEdit_restore_position?BST_CHECKED:BST_UNCHECKED); break; + case ID_CONFIG_SETGREENZONECAPACITY: + //open input dialog + int new_capacity = TASEdit_greenzone_capacity; + if(CWin32InputBox::GetInteger("Greenzone capacity", "Keep savestates for how many frames?", new_capacity, hwndDlg) == IDOK) + { + if (new_capacity < GREENZONE_MIN_CAPACITY) + new_capacity = GREENZONE_MIN_CAPACITY; + else if (new_capacity > GREENZONE_MAX_CAPACITY) + new_capacity = GREENZONE_MAX_CAPACITY; + if (new_capacity < TASEdit_greenzone_capacity) + { + TASEdit_greenzone_capacity = new_capacity; + currMovieData.ClearGreenzoneTail(); + RedrawList(); + } else TASEdit_greenzone_capacity = new_capacity; + } + break; } break; @@ -1343,7 +1366,9 @@ void EnterTasEdit() { if(!FCEU_IsValidUI(FCEUI_TASEDIT)) return; - lastCursor = -1; + // init variables + lastCursor = old_pauseframe = -1; + old_show_pauseframe = show_pauseframe = false; // either start new project or use current movie if (movieMode == MOVIEMODE_INACTIVE) @@ -1381,3 +1406,10 @@ void EnterTasEdit() SetWindowPos(hwndTasEdit,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); } } +void ExitTasEdit() +{ + movieMode = MOVIEMODE_INACTIVE; + FCEU_DispMessage("Tasedit disengaged",0); + currMovieData.clearGreenzone(); + CreateCleanMovie(); +} diff --git a/src/drivers/win/tasedit.h b/src/drivers/win/tasedit.h index 067407ca..96c75b21 100644 --- a/src/drivers/win/tasedit.h +++ b/src/drivers/win/tasedit.h @@ -3,6 +3,10 @@ #define FRAMES_TOO_FAR 60 #define NUM_JOYPADS 4 #define NUM_JOYPAD_BUTTONS 8 +#define GREENZONE_DEFAULT_CAPACITY 50000 +#define GREENZONE_MIN_CAPACITY 1 +#define GREENZONE_MAX_CAPACITY 200000 // maybe even more +#define PAUSEFRAME_BLINKING_PERIOD 100 // listview column names #define COLUMN_ARROW 0 #define COLUMN_FRAMENUM 1 @@ -62,8 +66,10 @@ void InvalidateGreenZone(int after); bool JumpToFrame(int index); int FindBeginningOfGreenZone(int starting_index); void FollowPlayback(); +void ClearSelection(); void AddFourscoreColumns(); void RemoveFourscoreColumns(); -void RedrawList(); void RedrawTasedit(); +void RedrawList(); +void RedrawRow(int index); void RedrawTweakCount(); \ No newline at end of file diff --git a/src/drivers/win/taseditlib/taseditproj.cpp b/src/drivers/win/taseditlib/taseditproj.cpp index 4b1da021..accc54bc 100644 --- a/src/drivers/win/taseditlib/taseditproj.cpp +++ b/src/drivers/win/taseditlib/taseditproj.cpp @@ -63,7 +63,7 @@ bool TASEDIT_PROJECT::SaveProject() currMovieData.dump(ofs, true); ofs->fputc('\0'); // TODO: Add main branch name. - currMovieData.dumpGreenzone(ofs, true); + currMovieData.dumpGreenzone(ofs); delete ofs; @@ -86,8 +86,7 @@ bool TASEDIT_PROJECT::LoadProject(std::string PFN) char branchname; branchname = ifs.fgetc(); // TODO: Add main branch name. - currMovieData.clearGreenzone(); - if (!currMovieData.loadGreenzone(&ifs, true)) + if (!currMovieData.loadGreenzone(&ifs)) { // there was some error while loading greenzone - reset playback to frame 0 poweron(true); diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index a35509aa..dfeb88ab 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -1902,7 +1902,6 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) // DoByteMonitor(); // break; // Removing this tool since it is redundant to both - case ACCEL_CTRL_E: case MENU_TASEDIT: EnterTasEdit(); break; diff --git a/src/fceu.cpp b/src/fceu.cpp index afa38b6e..e482f35a 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -1039,6 +1039,7 @@ bool FCEU_IsValidUI(EFCEUI ui) case FCEUI_TASEDIT: if(!GameInfo) return false; + if(FCEUMOV_Mode(MOVIEMODE_TASEDIT)) return false; break; case FCEUI_RESET: diff --git a/src/movie.cpp b/src/movie.cpp index b5d86023..db51c697 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -48,6 +48,7 @@ using namespace std; extern char FileBase[]; extern bool AutoSS; //Declared in fceu.cpp, keeps track if a auto-savestate has been made +extern int TASEdit_greenzone_capacity; std::vector subtitleFrames; //Frame numbers for subtitle messages std::vector subtitleMessages; //Messages of subtitles @@ -141,9 +142,28 @@ void MovieData::TryDumpIncremental() // update greenzone upper limit if (currMovieData.greenZoneCount <= currFrameCounter) currMovieData.greenZoneCount = currFrameCounter+1; + + ClearGreenzoneTail(); } } +void MovieData::ClearGreenzoneTail() +{ + int tail_frame = currMovieData.greenZoneCount-1 - TASEdit_greenzone_capacity; + if (tail_frame >= currFrameCounter) tail_frame = currFrameCounter - 1; + for (;tail_frame >= 0; tail_frame--) + { + if (currMovieData.savestates[tail_frame].empty()) break; + ClearSavestate(tail_frame); + RedrawRow(tail_frame); + } +} +void MovieData::ClearSavestate(int index) +{ + std::vector tmp; + currMovieData.savestates[index].swap(tmp); +} + MovieRecord::MovieRecord() { joysticks.data[0] = 0; @@ -510,9 +530,9 @@ int MovieData::dump(EMUFILE *os, bool binary) void MovieData::clearGreenzone() { int size = currMovieData.savestates.size(); - for (int i = 1; i < size; ++i) + for (int i = 0; i < size; ++i) { - currMovieData.savestates[i].clear(); + ClearSavestate(i); } greenZoneCount = 1; currMovieData.frames_flags.resize(1); @@ -521,72 +541,79 @@ void MovieData::clearGreenzone() } -int MovieData::dumpGreenzone(EMUFILE *os, bool binary) +int MovieData::dumpGreenzone(EMUFILE *os) { - // save savestates int start = os->ftell(); int frame, size; write32le(greenZoneCount, os); + write32le(currFrameCounter, os); + // write savestates for (frame = 0; frame < greenZoneCount; ++frame) { if (savestates[frame].empty()) continue; write32le(frame, os); - size = savestates[frame].size(); - write32le(size, os); - // write savestate - os->fwrite(&savestates[frame][0], size); // write frames_flags os->fwrite(&frames_flags[frame], 1); // write lua_colorings // write monitorings - + // write savestate + size = savestates[frame].size(); + write32le(size, os); + os->fwrite(&savestates[frame][0], size); } // write -1 as eof for greenzone write32le(-1, os); - // finally write playback cursor position - write32le(currFrameCounter, os); int end = os->ftell(); return end-start; } -bool MovieData::loadGreenzone(EMUFILE *is, bool binary) +bool MovieData::loadGreenzone(EMUFILE *is) { clearGreenzone(); int frame = 0, prev_frame = 0, size = 0; if (read32le((uint32 *)&size, is)) { greenZoneCount = size; - frames_flags.resize(size); - savestates.resize(size); - while(1) + savestates.resize(greenZoneCount); + frames_flags.resize(greenZoneCount); + savestates.resize(greenZoneCount); + int greenzone_tail_frame = greenZoneCount-1 - TASEdit_greenzone_capacity; + if (read32le((uint32 *)&frame, is)) { - if (!read32le((uint32 *)&frame, is)) break; - if (frame == -1) break; - if (!read32le((uint32 *)&size, is)) break; - - if ((int)savestates.size() <= frame) savestates.resize(frame+1); - // load savestate - savestates[frame].resize(size); - if ((int)is->fread((char*)&savestates[frame][0],size) < size) break; - // load frames_flags - if ((int)is->fread(&frames_flags[frame],1) != 1) break; - // load lua_colorings - // load monitorings - - prev_frame = frame; - } - greenZoneCount = prev_frame+1; // cut greenZoneCount to last good frame - if (frame == -1) - { - // everything went fine - load savestate at cursor position - if (read32le((uint32 *)&currFrameCounter, is) && currMovieData.loadTasSavestate(currFrameCounter)) + currFrameCounter = frame; + while(1) { - return true; + if (!read32le((uint32 *)&frame, is)) break; + if (frame == -1) break; + // read frames_flags + if ((int)is->fread(&frames_flags[frame],1) != 1) break; + // read lua_colorings + // read monitorings + // read savestate + if (!read32le((uint32 *)&size, is)) break; + if (frame > greenzone_tail_frame || frame == currFrameCounter) + { + // load savestate + savestates[frame].resize(size); + if ((int)is->fread((char*)&savestates[frame][0],size) < size) break; + prev_frame = frame; // successfully read one greenzone frame info + } else + { + // skip loading this savestate + if (is->fseek(size,SEEK_CUR) != 0) break; + } + } + greenZoneCount = prev_frame+1; // cut greenZoneCount to last good frame + if (frame == -1) + { + // everything went fine - load savestate at cursor position + if (currMovieData.loadTasSavestate(currFrameCounter)) + return true; + } else + { + // there was some error while reading greenzone } - } else - { - // there was some error while reading greenzone } } return false; diff --git a/src/movie.h b/src/movie.h index cde623b0..8836a4df 100644 --- a/src/movie.h +++ b/src/movie.h @@ -233,8 +233,8 @@ public: void installValue(std::string& key, std::string& val); int dump(EMUFILE* os, bool binary); void clearGreenzone(); - int dumpGreenzone(EMUFILE *os, bool binary); - bool loadGreenzone(EMUFILE *is, bool binary); + int dumpGreenzone(EMUFILE *os); + bool loadGreenzone(EMUFILE *is); void clearRecordRange(int start, int len); void insertEmpty(int at, int frames); @@ -245,6 +245,8 @@ public: bool loadTasSavestate(int frame); void storeTasSavestate(int frame, int compression_level); void TryDumpIncremental(); + void ClearGreenzoneTail(); + void ClearSavestate(int index); private: void installInt(std::string& val, int& var)