From 95a301dbb273936d5497cbd580010b29911531a7 Mon Sep 17 00:00:00 2001 From: ansstuff Date: Thu, 13 Sep 2012 16:11:03 +0000 Subject: [PATCH] * "Tools->TAS Editor" gives focus to Taseditor when it's already open; fixed the setfocus behavior for other tools as well * Taseditor: AdjustDown operation now works faster (not rewinding anymore) * Taseditor: AdjustLag always combines with current History item, not creating its own item in the History Log --- src/drivers/win/cdlogger.cpp | 13 +- src/drivers/win/cheat.cpp | 22 +- src/drivers/win/debugger.cpp | 10 +- src/drivers/win/log.cpp | 3 +- src/drivers/win/memview.cpp | 7 +- src/drivers/win/memwatch.cpp | 3 +- src/drivers/win/ntview.cpp | 13 +- src/drivers/win/ppuview.cpp | 14 +- src/drivers/win/res.rc | 4 +- src/drivers/win/taseditor.cpp | 50 ++-- src/drivers/win/taseditor/greenzone.cpp | 20 +- src/drivers/win/taseditor/history.cpp | 307 ++++++++++-------------- src/drivers/win/taseditor/history.h | 2 +- src/drivers/win/taseditor/splicer.cpp | 29 ++- src/drivers/win/texthook.cpp | 7 +- src/drivers/win/tracer.cpp | 13 +- src/drivers/win/window.cpp | 13 +- src/fceu.cpp | 1 - src/input.cpp | 2 +- 19 files changed, 277 insertions(+), 256 deletions(-) diff --git a/src/drivers/win/cdlogger.cpp b/src/drivers/win/cdlogger.cpp index 25529bdd..63ef6c22 100644 --- a/src/drivers/win/cdlogger.cpp +++ b/src/drivers/win/cdlogger.cpp @@ -289,7 +289,8 @@ void SaveCDLogFile(){ //todo make this button work before you've saved as return; } -void DoCDLogger(){ +void DoCDLogger() +{ if (!GameInfo) { FCEUD_PrintError("You must have a game loaded before you can use the Code Data Logger."); return; @@ -299,10 +300,14 @@ void DoCDLogger(){ // return; //} - if(!hCDLogger){ + if(!hCDLogger) + { CreateDialog(fceu_hInstance,"CDLOGGER",NULL,CDLoggerCallB); - } else { - SetWindowPos(hCDLogger,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + } else + { + //SetWindowPos(hCDLogger,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + ShowWindow(hCDLogger, SW_SHOWNORMAL); + SetForegroundWindow(hCDLogger); } } diff --git a/src/drivers/win/cheat.cpp b/src/drivers/win/cheat.cpp index 9ce884b9..f91c5d9e 100644 --- a/src/drivers/win/cheat.cpp +++ b/src/drivers/win/cheat.cpp @@ -633,14 +633,17 @@ void ConfigCheats(HWND hParent) { // return; //} - if (!CheatWindow) { + if (!CheatWindow) + { selcheat=-1; CheatWindow=1; if (CheatStyle) pwindow = hCheat = CreateDialog(fceu_hInstance,"CHEATCONSOLE",NULL,CheatConsoleCallB); else DialogBox(fceu_hInstance,"CHEATCONSOLE",hParent,CheatConsoleCallB); + } else + { + ShowWindow(hCheat, SW_SHOWNORMAL); + SetForegroundWindow(hCheat); } - else - SetFocus(hCheat); } void UpdateCheatList() @@ -908,9 +911,16 @@ void SetGGConvFocus(int address,int compare){ return; } -void DoGGConv(){ - if(hGGConv)return; - hGGConv = CreateDialog(fceu_hInstance,"GGCONV",NULL,GGConvCallB); +void DoGGConv() +{ + if (hGGConv) + { + ShowWindow(hGGConv, SW_SHOWNORMAL); + SetForegroundWindow(hGGConv); + } else + { + hGGConv = CreateDialog(fceu_hInstance,"GGCONV",NULL,GGConvCallB); + } return; } diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 3e868746..02a10327 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1870,15 +1870,19 @@ void updateGameDependentMenusDebugger(unsigned int enable) { //EnableWindow(GetDlgItem(hDebug,DEBUGLOADDEB),(enable ? 0 : 1)); } -void DoDebug(uint8 halt) { - if (!debugger_open) { +void DoDebug(uint8 halt) +{ + if (!debugger_open) + { hDebug = CreateDialog(fceu_hInstance,"DEBUGGER",NULL,DebuggerCallB); if(DbgSizeX != -1 && DbgSizeY != -1) SetWindowPos(hDebug,0,0,0,DbgSizeX,DbgSizeY,SWP_NOMOVE|SWP_NOZORDER|SWP_NOOWNERZORDER); } if (hDebug) { - SetWindowPos(hDebug,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + //SetWindowPos(hDebug,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + ShowWindow(hDebug, SW_SHOWNORMAL); + SetForegroundWindow(hDebug); updateGameDependentMenusDebugger(GameInfo != 0); diff --git a/src/drivers/win/log.cpp b/src/drivers/win/log.cpp index 36067fae..eaefb375 100644 --- a/src/drivers/win/log.cpp +++ b/src/drivers/win/log.cpp @@ -125,7 +125,8 @@ void MakeLogWindow(void) RedoText(); // XXX jeblanchard Why didn't this work in WM_INITDIALOG? } else { - SetFocus(logwin); + ShowWindow(logwin, SW_SHOWNORMAL); + SetForegroundWindow(logwin); } } diff --git a/src/drivers/win/memview.cpp b/src/drivers/win/memview.cpp index 16a7e869..7947d850 100644 --- a/src/drivers/win/memview.cpp +++ b/src/drivers/win/memview.cpp @@ -1684,7 +1684,8 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa -void DoMemView() { +void DoMemView() +{ WNDCLASSEX wndclass ; //static RECT al; @@ -1724,7 +1725,9 @@ void DoMemView() { UpdateCaption(); } else { - SetWindowPos(hMemView, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + //SetWindowPos(hMemView, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + ShowWindow(hMemView, SW_SHOWNORMAL); + SetForegroundWindow(hMemView); UpdateCaption(); } diff --git a/src/drivers/win/memwatch.cpp b/src/drivers/win/memwatch.cpp index 96ec61a4..bc4e36fb 100644 --- a/src/drivers/win/memwatch.cpp +++ b/src/drivers/win/memwatch.cpp @@ -968,7 +968,8 @@ void CreateMemWatch() if(hwndMemWatch) //If already open, give focus { - SetFocus(hwndMemWatch); + ShowWindow(hwndMemWatch, SW_SHOWNORMAL); + SetForegroundWindow(hwndMemWatch); return; } diff --git a/src/drivers/win/ntview.cpp b/src/drivers/win/ntview.cpp index f286e779..13c13402 100644 --- a/src/drivers/win/ntview.cpp +++ b/src/drivers/win/ntview.cpp @@ -536,7 +536,8 @@ BOOL CALLBACK NTViewCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) return FALSE; } -void DoNTView() { +void DoNTView() +{ if (!GameInfo) { FCEUD_PrintError("You must have a game loaded before you can use the Name Table Viewer."); return; @@ -546,12 +547,16 @@ void DoNTView() { return; } - if (!hNTView) { + if (!hNTView) + { hNTView = CreateDialog(fceu_hInstance,"NTVIEW",NULL,NTViewCallB); new(cache) NTCache[4]; //reinitialize NTCache } - if (hNTView) { - SetWindowPos(hNTView,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + if (hNTView) + { + //SetWindowPos(hNTView,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + ShowWindow(hNTView, SW_SHOWNORMAL); + SetForegroundWindow(hNTView); FCEUD_UpdateNTView(-1,true); NTViewDoBlit(1); } diff --git a/src/drivers/win/ppuview.cpp b/src/drivers/win/ppuview.cpp index 3b096ec6..16b91093 100644 --- a/src/drivers/win/ppuview.cpp +++ b/src/drivers/win/ppuview.cpp @@ -348,7 +348,8 @@ BOOL CALLBACK PPUViewCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam return FALSE; } -void DoPPUView() { +void DoPPUView() +{ if(!GameInfo) { FCEUD_PrintError("You must have a game loaded before you can use the PPU Viewer."); return; @@ -359,9 +360,12 @@ void DoPPUView() { } if(!hPPUView) hPPUView = CreateDialog(fceu_hInstance,"PPUVIEW",NULL,PPUViewCallB); - if(hPPUView) { - SetWindowPos(hPPUView,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); - FCEUD_UpdatePPUView(-1,1); - PPUViewDoBlit(); + if(hPPUView) + { + //SetWindowPos(hPPUView,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + ShowWindow(hPPUView, SW_SHOWNORMAL); + SetForegroundWindow(hPPUView); + FCEUD_UpdatePPUView(-1,1); + PPUViewDoBlit(); } } diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 6e2ea276..a8d7a310 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -165,7 +165,7 @@ BEGIN MENUITEM "RAM Search...", ID_RAM_SEARCH MENUITEM "RAM Watch...", ID_RAM_WATCH MENUITEM "&Memory Watch...", MENU_MEMORY_WATCH - MENUITEM "&TAS Editor...", MENU_TASEDITOR, INACTIVE + MENUITEM "&TAS Editor...", MENU_TASEDITOR MENUITEM "Convert &FCM...", MENU_CONVERT_MOVIE MENUITEM SEPARATOR POPUP "Autofire &Pattern" @@ -1216,7 +1216,7 @@ BEGIN END NTVIEW DIALOGEX 44, 38, 355, 402 -STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Name Table Viewer" FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN diff --git a/src/drivers/win/taseditor.cpp b/src/drivers/win/taseditor.cpp index e4ae3d28..e640c8b5 100644 --- a/src/drivers/win/taseditor.cpp +++ b/src/drivers/win/taseditor.cpp @@ -68,10 +68,16 @@ extern void UpdateCheckedMenuItems(); extern void TaseditorAutoFunction(); extern void TaseditorManualFunction(); +// returns true if Taseditor is engaged at the end of the function bool EnterTasEditor() { - if (!FCEU_IsValidUI(FCEUI_TASEDITOR)) return false; - if (!taseditor_window.hwndTasEditor) + if (taseditor_window.hwndTasEditor) + { + // TAS Editor is already engaged, just set focus to its window + ShowWindow(taseditor_window.hwndTasEditor, SW_SHOWNORMAL); + SetForegroundWindow(taseditor_window.hwndTasEditor); + return true; + } else if (FCEU_IsValidUI(FCEUI_TASEDITOR)) { // start TAS Editor // create window @@ -144,8 +150,16 @@ bool EnterTasEditor() FCEU_DispMessage("TAS Editor engaged", 0); taseditor_window.RedrawTaseditor(); return true; - } else return false; - } else return true; + } else + { + // couldn't init window + return false; + } + } else + { + // right now TAS Editor launch is not allowed by emulator + return true; + } } bool ExitTasEditor() @@ -185,20 +199,9 @@ bool ExitTasEditor() // everyframe function void UpdateTasEditor() { - if (!taseditor_window.hwndTasEditor) - { - // TAS Editor is not engaged... but we still should run Lua auto function - TaseditorAutoFunction(); - if (emulator_must_run_taseditor) - { - char fullname[512]; - strcpy(fullname, curMovieFilename); - if (EnterTasEditor()) - LoadProject(fullname); - emulator_must_run_taseditor = false; - } - } else + if (taseditor_window.hwndTasEditor) { + // TAS Editor is engaged // update all modules that need to be updated every frame // the order is somewhat important, e.g. Greenzone must update before Bookmark Set, Piano Roll must update before Selection taseditor_window.update(); @@ -214,7 +217,6 @@ void UpdateTasEditor() splicer.update(); history.update(); project.update(); - // run Lua functions if needed if (taseditor_config.enable_auto_function) TaseditorAutoFunction(); @@ -223,6 +225,18 @@ void UpdateTasEditor() TaseditorManualFunction(); must_call_manual_lua_function = false; } + } else + { + // TAS Editor is not engaged + TaseditorAutoFunction(); // but we still should run Lua auto function + if (emulator_must_run_taseditor) + { + char fullname[512]; + strcpy(fullname, curMovieFilename); + if (EnterTasEditor()) + LoadProject(fullname); + emulator_must_run_taseditor = false; + } } } diff --git a/src/drivers/win/taseditor/greenzone.cpp b/src/drivers/win/taseditor/greenzone.cpp index 11e86fcb..8d30441f 100644 --- a/src/drivers/win/taseditor/greenzone.cpp +++ b/src/drivers/win/taseditor/greenzone.cpp @@ -58,7 +58,7 @@ void GREENZONE::reset() void GREENZONE::update() { // keep collecting savestates, this function should be called at the end of every frame - if (greenZoneCount <= currFrameCounter || (int)savestates.size() <= currFrameCounter || !savestates[currFrameCounter].size() || laglog.GetSize() <= currFrameCounter) + if (greenZoneCount <= currFrameCounter || (int)savestates.size() <= currFrameCounter || !savestates[currFrameCounter].size() || laglog.GetSize() < currFrameCounter) CollectCurrentState(); // run cleaning from time to time @@ -85,33 +85,17 @@ void GREENZONE::CollectCurrentState() { // lagFlag indicates that lag was in previous frame int old_lagFlag = laglog.GetLagInfoAtFrame(currFrameCounter - 1); - // Auto-adjust Input due to lag + // Auto-adjust Input according to lag if (taseditor_config.adjust_input_due_to_lag) { if (old_lagFlag && !lagFlag) { // there's no more lag on previous frame - shift Input up splicer.AdjustUp(currFrameCounter - 1); - // since AdjustUp didn't restore Playback cursor, we must rewind here - bool emu_was_paused = (FCEUI_EmulationPaused() != 0); - int saved_pause_frame = playback.GetPauseFrame(); - playback.jump(currFrameCounter - 1); // rewind - if (saved_pause_frame >= 0) - playback.SeekingStart(saved_pause_frame); - if (emu_was_paused) - playback.PauseEmulation(); } else if (!old_lagFlag && lagFlag) { // there's new lag on previous frame - shift Input down splicer.AdjustDown(currFrameCounter - 1); - // since AdjustDown didn't restore Playback cursor, we must rewind here - bool emu_was_paused = (FCEUI_EmulationPaused() != 0); - int saved_pause_frame = playback.GetPauseFrame(); - playback.jump(currFrameCounter - 1); // rewind - if (saved_pause_frame >= 0) - playback.SeekingStart(saved_pause_frame); - if (emu_was_paused) - playback.PauseEmulation(); } else { // old_lagFlag == lagFlag diff --git a/src/drivers/win/taseditor/history.cpp b/src/drivers/win/taseditor/history.cpp index e8d2b495..b5bc4598 100644 --- a/src/drivers/win/taseditor/history.cpp +++ b/src/drivers/win/taseditor/history.cpp @@ -102,8 +102,7 @@ char modCaptions[MODTYPES_TOTAL][20] = {" Initialization", " LUA Marker Set", " LUA Marker Remove", " LUA Marker Rename", - " LUA Change", - " AdjustLag" }; + " LUA Change" }; char LuaCaptionPrefix[6] = " LUA "; char joypadCaptions[4][5] = {"(1P)", "(2P)", "(3P)", "(4P)"}; @@ -415,29 +414,14 @@ int HISTORY::JumpInTime(int new_pos) void HISTORY::undo() { - int step = -1; - if (taseditor_config.adjust_input_due_to_lag) - { - // if we're undoing an AdjustLag operation then undo two operations - if (GetCurrentSnapshot().mod_type == MODTYPE_ADJUST_LAG) - step = -2; - } - int result = JumpInTime(history_cursor_pos + step); + int result = JumpInTime(history_cursor_pos - 1); if (result >= 0) greenzone.InvalidateAndCheck(result); return; } void HISTORY::redo() { - int step = 1; - if (taseditor_config.adjust_input_due_to_lag) - { - // if we're redoing an operation followed by AdjustLag then redo two operations - if (history_cursor_pos + 2 <= history_total_items) - if (snapshots[(history_start_pos + history_cursor_pos + 2) % history_size].mod_type == MODTYPE_ADJUST_LAG) - step = 2; - } - int result = JumpInTime(history_cursor_pos + step); + int result = JumpInTime(history_cursor_pos + 1); if (result >= 0) greenzone.InvalidateAndCheck(result); return; @@ -525,7 +509,6 @@ int HISTORY::RegisterChanges(int mod_type, int start, int end, int size, const c case MODTYPE_CLONE: case MODTYPE_DELETE: case MODTYPE_PATTERN: - case MODTYPE_ADJUST_LAG: { // for these changes user prefers to see frame of attempted change (Selection cursor position), not frame of actual differences snap.keyframe = start; @@ -533,43 +516,44 @@ int HISTORY::RegisterChanges(int mod_type, int start, int end, int size, const c } } // set start_frame, end_frame, consecutive_tag - if (snap.mod_type == MODTYPE_ADJUST_LAG) + // normal operations + snap.start_frame = start; + if (mod_type == MODTYPE_INSERTNUM) { - // special operation: AdjustLag - snap.start_frame = snap.end_frame = start; - snap.consecutive_tag = size; // -1 for Adjust Up, +1 for Adjust Down - // combine Adjustment with previous snapshot if needed - bool combine = false; - if (snapshots[real_pos].mod_type == MODTYPE_ADJUST_LAG) - combine = true; - if (combine) - { - if (snap.keyframe > snapshots[real_pos].keyframe) - snap.keyframe = snapshots[real_pos].keyframe; - if (snap.start_frame > snapshots[real_pos].start_frame) - snap.start_frame = snapshots[real_pos].start_frame; - if (snap.end_frame < snapshots[real_pos].end_frame) - snap.end_frame = snapshots[real_pos].end_frame; - snap.consecutive_tag += snapshots[real_pos].consecutive_tag; - } - // set hotchanges - if (taseditor_config.enable_hot_changes) - { - if (size < 0) - // it was Adjust Up - snap.inputlog.inheritHotChanges_DeleteNum(&snapshots[real_pos].inputlog, start, 1, !combine); - else - // it was Adjust Down - snap.inputlog.inheritHotChanges_InsertNum(&snapshots[real_pos].inputlog, start, 1, !combine); - } - // add "consecutive size" to description - strcat(snap.description, " ["); - if (snap.consecutive_tag > 0) - strcat(snap.description, "+"); - _itoa(snap.consecutive_tag, framenum, 10); + snap.end_frame = start + size - 1; + _itoa(size, framenum, 10); strcat(snap.description, framenum); - strcat(snap.description, "] "); + } else + { + snap.end_frame = end; + } + int first_input_changes = first_changes; + // for lag-affecting operations only: Greenzone should be invalidated after the frame of Lag changes if this frame is less than the frame of Input changes + if (first_changes > start && end == -1) + { + // check if LagLogs of these snapshots differ before the "first_changes" frame + for (int i = start; i < first_changes; ++i) + { + if (snap.laglog.GetLagInfoAtFrame(i) != snapshots[real_pos].laglog.GetLagInfoAtFrame(i)) + { + // Greenzone should be invalidated from the frame + first_changes = i; + break; + } + } + } + snap.consecutive_tag = consecutive_tag; + if (consecutive_tag && taseditor_config.combine_consecutive && snapshots[real_pos].mod_type == snap.mod_type && snapshots[real_pos].consecutive_tag == snap.consecutive_tag) + { + // combine Drawing with previous snapshot + if (snap.keyframe > snapshots[real_pos].keyframe) + snap.keyframe = snapshots[real_pos].keyframe; + if (snap.start_frame > snapshots[real_pos].start_frame) + snap.start_frame = snapshots[real_pos].start_frame; + if (snap.end_frame < snapshots[real_pos].end_frame) + snap.end_frame = snapshots[real_pos].end_frame; // add upper and lower frame to description + strcat(snap.description, " "); _itoa(snap.start_frame, framenum, 10); strcat(snap.description, framenum); if (snap.end_frame > snap.start_frame) @@ -584,143 +568,118 @@ int HISTORY::RegisterChanges(int mod_type, int start, int end, int size, const c strcat(snap.description, " "); strncat(snap.description, comment, SNAPSHOT_DESC_MAX_LENGTH - strlen(snap.description) - 1); } - if (combine) + // set hotchanges + if (taseditor_config.enable_hot_changes) { - // replace current snapshot with this cloned snapshot and truncate history here - snapshots[real_pos] = snap; - history_total_items = history_cursor_pos+1; - UpdateHistoryList(); - RedrawHistoryList(); - } else - { - AddItemToHistory(snap); + snap.inputlog.copyHotChanges(&snapshots[real_pos].inputlog); + snap.inputlog.fillHotChanges(snapshots[real_pos].inputlog, first_input_changes, end); } + // replace current snapshot with this cloned snapshot and truncate history here + snapshots[real_pos] = snap; + history_total_items = history_cursor_pos+1; + UpdateHistoryList(); + RedrawHistoryList(); } else { - // normal operations - snap.start_frame = start; - if (mod_type == MODTYPE_INSERTNUM) + // don't combine + // add upper and lower frame to description + strcat(snap.description, " "); + _itoa(snap.start_frame, framenum, 10); + strcat(snap.description, framenum); + if (snap.end_frame > snap.start_frame) { - snap.end_frame = start + size - 1; - _itoa(size, framenum, 10); + strcat(snap.description, "-"); + _itoa(snap.end_frame, framenum, 10); strcat(snap.description, framenum); - } else - { - snap.end_frame = end; } - int first_input_changes = first_changes; - // for lag-affecting operations only: Greenzone should be invalidated after the frame of Lag changes if this frame is less than the frame of Input changes - if (first_changes > start && end == -1) + // add comment if there is one specified + if (comment) { - // check if LagLogs of these snapshots differ before the "first_changes" frame - for (int i = start; i < first_changes; ++i) + strcat(snap.description, " "); + strncat(snap.description, comment, SNAPSHOT_DESC_MAX_LENGTH - strlen(snap.description) - 1); + } + // set hotchanges + if (taseditor_config.enable_hot_changes) + { + // inherit previous hotchanges and set new changes + switch (mod_type) { - if (snap.laglog.GetLagInfoAtFrame(i) != snapshots[real_pos].laglog.GetLagInfoAtFrame(i)) - { - // Greenzone should be invalidated from the frame - first_changes = i; + case MODTYPE_DELETE: + snap.inputlog.inheritHotChanges_DeleteSelection(&snapshots[real_pos].inputlog, frameset); + break; + case MODTYPE_INSERT: + case MODTYPE_CLONE: + snap.inputlog.inheritHotChanges_InsertSelection(&snapshots[real_pos].inputlog, frameset); + break; + case MODTYPE_INSERTNUM: + snap.inputlog.inheritHotChanges_InsertNum(&snapshots[real_pos].inputlog, start, size, true); + break; + case MODTYPE_SET: + case MODTYPE_UNSET: + case MODTYPE_CLEAR: + case MODTYPE_CUT: + case MODTYPE_PASTE: + case MODTYPE_PATTERN: + snap.inputlog.inheritHotChanges(&snapshots[real_pos].inputlog); + snap.inputlog.fillHotChanges(snapshots[real_pos].inputlog, first_input_changes, end); + break; + case MODTYPE_PASTEINSERT: + snap.inputlog.inheritHotChanges_PasteInsert(&snapshots[real_pos].inputlog, frameset); + break; + case MODTYPE_TRUNCATE: + snap.inputlog.copyHotChanges(&snapshots[real_pos].inputlog); + // do not add new hotchanges and do not fade old hotchanges, because there was nothing added break; - } } } - snap.consecutive_tag = consecutive_tag; - if (consecutive_tag && taseditor_config.combine_consecutive && snapshots[real_pos].mod_type == snap.mod_type && snapshots[real_pos].consecutive_tag == snap.consecutive_tag) - { - // combine Drawing with previous snapshot - if (snap.keyframe > snapshots[real_pos].keyframe) - snap.keyframe = snapshots[real_pos].keyframe; - if (snap.start_frame > snapshots[real_pos].start_frame) - snap.start_frame = snapshots[real_pos].start_frame; - if (snap.end_frame < snapshots[real_pos].end_frame) - snap.end_frame = snapshots[real_pos].end_frame; - // add upper and lower frame to description - strcat(snap.description, " "); - _itoa(snap.start_frame, framenum, 10); - strcat(snap.description, framenum); - if (snap.end_frame > snap.start_frame) - { - strcat(snap.description, "-"); - _itoa(snap.end_frame, framenum, 10); - strcat(snap.description, framenum); - } - // add comment if there is one specified - if (comment) - { - strcat(snap.description, " "); - strncat(snap.description, comment, SNAPSHOT_DESC_MAX_LENGTH - strlen(snap.description) - 1); - } - // set hotchanges - if (taseditor_config.enable_hot_changes) - { - snap.inputlog.copyHotChanges(&snapshots[real_pos].inputlog); - snap.inputlog.fillHotChanges(snapshots[real_pos].inputlog, first_input_changes, end); - } - // replace current snapshot with this cloned snapshot and truncate history here - snapshots[real_pos] = snap; - history_total_items = history_cursor_pos+1; - UpdateHistoryList(); - RedrawHistoryList(); - } else - { - // don't combine - // add upper and lower frame to description - strcat(snap.description, " "); - _itoa(snap.start_frame, framenum, 10); - strcat(snap.description, framenum); - if (snap.end_frame > snap.start_frame) - { - strcat(snap.description, "-"); - _itoa(snap.end_frame, framenum, 10); - strcat(snap.description, framenum); - } - // add comment if there is one specified - if (comment) - { - strcat(snap.description, " "); - strncat(snap.description, comment, SNAPSHOT_DESC_MAX_LENGTH - strlen(snap.description) - 1); - } - // set hotchanges - if (taseditor_config.enable_hot_changes) - { - // inherit previous hotchanges and set new changes - switch (mod_type) - { - case MODTYPE_DELETE: - snap.inputlog.inheritHotChanges_DeleteSelection(&snapshots[real_pos].inputlog, frameset); - break; - case MODTYPE_INSERT: - case MODTYPE_CLONE: - snap.inputlog.inheritHotChanges_InsertSelection(&snapshots[real_pos].inputlog, frameset); - break; - case MODTYPE_INSERTNUM: - snap.inputlog.inheritHotChanges_InsertNum(&snapshots[real_pos].inputlog, start, size, true); - break; - case MODTYPE_SET: - case MODTYPE_UNSET: - case MODTYPE_CLEAR: - case MODTYPE_CUT: - case MODTYPE_PASTE: - case MODTYPE_PATTERN: - snap.inputlog.inheritHotChanges(&snapshots[real_pos].inputlog); - snap.inputlog.fillHotChanges(snapshots[real_pos].inputlog, first_input_changes, end); - break; - case MODTYPE_PASTEINSERT: - snap.inputlog.inheritHotChanges_PasteInsert(&snapshots[real_pos].inputlog, frameset); - break; - case MODTYPE_TRUNCATE: - snap.inputlog.copyHotChanges(&snapshots[real_pos].inputlog); - // do not add new hotchanges and do not fade old hotchanges, because there was nothing added - break; - } - } - AddItemToHistory(snap); - } + AddItemToHistory(snap); } branches.ChangesMadeSinceBranch(); project.SetProjectChanged(); } return first_changes; } +void HISTORY::RegisterAdjustLag(int start, int size) +{ + // create new shanshot + SNAPSHOT snap; + snap.init(currMovieData, taseditor_config.enable_hot_changes); + // check if there are Input differences from latest snapshot + int real_pos = (history_start_pos + history_cursor_pos) % history_size; + SNAPSHOT& current_snap = snapshots[real_pos]; + int first_changes = snap.inputlog.findFirstChange(current_snap.inputlog, start, -1); + if (first_changes >= 0) + { + // differences found - combine Adjustment with current snapshot + // copy all properties of current snapshot + snap.keyframe = current_snap.keyframe; + snap.start_frame = current_snap.start_frame; + snap.end_frame = current_snap.end_frame; + snap.consecutive_tag = current_snap.consecutive_tag; + // make sure that consecutive Recordings work even when there's AdjustUp inbetween + //if (current_snap.mod_type == MODTYPE_RECORD && size < 0 && current_snap.consecutive_tag == first_changes) + // snap.consecutive_tag--; + snap.rec_joypad_diff_bits = current_snap.rec_joypad_diff_bits; + snap.mod_type = current_snap.mod_type; + strcpy(snap.description, current_snap.description); + // set hotchanges + if (taseditor_config.enable_hot_changes) + { + if (size < 0) + // it was Adjust Up + snap.inputlog.inheritHotChanges_DeleteNum(&snapshots[real_pos].inputlog, start, 1, false); + else + // it was Adjust Down + snap.inputlog.inheritHotChanges_InsertNum(&snapshots[real_pos].inputlog, start, 1, false); + } + // replace current snapshot with this cloned snapshot and don't truncate history + snapshots[real_pos] = snap; + UpdateHistoryList(); + RedrawHistoryList(); + branches.ChangesMadeSinceBranch(); + project.SetProjectChanged(); + } +} void HISTORY::RegisterMarkersChange(int mod_type, int start, int end, const char* comment) { // create new shanshot @@ -1293,8 +1252,6 @@ int HISTORY::GetCategoryOfOperation(int mod_type) return CATEGORY_MARKERS_CHANGE; case MODTYPE_LUA_CHANGE: return CATEGORY_INPUT_MARKERS_CHANGE; - case MODTYPE_ADJUST_LAG: - return CATEGORY_INPUT_MARKERS_CHANGE; } // if undefined diff --git a/src/drivers/win/taseditor/history.h b/src/drivers/win/taseditor/history.h index b36d0dea..50488cd2 100644 --- a/src/drivers/win/taseditor/history.h +++ b/src/drivers/win/taseditor/history.h @@ -66,7 +66,6 @@ enum MOD_TYPES MODTYPE_LUA_MARKER_REMOVE, MODTYPE_LUA_MARKER_RENAME, MODTYPE_LUA_CHANGE, - MODTYPE_ADJUST_LAG, MODTYPES_TOTAL }; @@ -107,6 +106,7 @@ public: void redo(); int RegisterChanges(int mod_type, int start = 0, int end =-1, int size = 0, const char* comment = NULL, int consecutive_tag = 0, SelectionFrames* frameset = NULL); + void RegisterAdjustLag(int start, int size); void RegisterMarkersChange(int mod_type, int start = 0, int end =-1, const char* comment = 0); void RegisterBookmarkSet(int slot, BOOKMARK& backup_copy, int old_current_branch); diff --git a/src/drivers/win/taseditor/splicer.cpp b/src/drivers/win/taseditor/splicer.cpp index 15e469d0..65c9742a 100644 --- a/src/drivers/win/taseditor/splicer.cpp +++ b/src/drivers/win/taseditor/splicer.cpp @@ -694,9 +694,17 @@ void SPLICER::AdjustUp(int at) playback.StartFromZero(); // reduce Piano Roll piano_roll.UpdateItemCount(); - // check and register changes - history.RegisterChanges(MODTYPE_ADJUST_LAG, at, -1, -1); + // register changes + history.RegisterAdjustLag(at, -1); greenzone.Invalidate(at); + // rewind, because maybe next frame also needs lag removal + bool emu_was_paused = (FCEUI_EmulationPaused() != 0); + int saved_pause_frame = playback.GetPauseFrame(); + playback.jump(currFrameCounter - 1); + if (saved_pause_frame >= 0) + playback.SeekingStart(saved_pause_frame); + if (emu_was_paused) + playback.PauseEmulation(); if (markers_changed) selection.must_find_current_marker = playback.must_find_current_marker = true; } @@ -713,9 +721,22 @@ void SPLICER::AdjustDown(int at) if (markers_manager.insertEmpty(at, 1)) markers_changed = true; } - // check and register changes - history.RegisterChanges(MODTYPE_ADJUST_LAG, at, -1, 1); + // register changes + history.RegisterAdjustLag(at, +1); + greenzone.Invalidate(at + 1); + /* + // this would be needed if "changes of Input in lag frames" were affecting game Output + // but since they don't affect it, we can keep current frame savestate in the Greenzone, and only truncate the Greenzone starting from next frame greenzone.Invalidate(at); + // rewind + bool emu_was_paused = (FCEUI_EmulationPaused() != 0); + int saved_pause_frame = playback.GetPauseFrame(); + playback.jump(currFrameCounter - 1); + if (saved_pause_frame >= 0) + playback.SeekingStart(saved_pause_frame); + if (emu_was_paused) + playback.PauseEmulation(); + */ if (markers_changed) selection.must_find_current_marker = playback.must_find_current_marker = true; } diff --git a/src/drivers/win/texthook.cpp b/src/drivers/win/texthook.cpp index 36eb7cd3..98f64a3e 100644 --- a/src/drivers/win/texthook.cpp +++ b/src/drivers/win/texthook.cpp @@ -1607,8 +1607,11 @@ void DoTextHooker() CheckDlgButton( hTextHooker, 342, BST_CHECKED ); CheckDlgButton( hTextHooker, 343, BST_CHECKED ); - if (hTextHooker) { - SetWindowPos(hTextHooker,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + if (hTextHooker) + { + //SetWindowPos(hTextHooker,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + ShowWindow(hTextHooker, SW_SHOWNORMAL); + SetForegroundWindow(hTextHooker); UpdateTextHooker(); TextHookerDoBlit(); } diff --git a/src/drivers/win/tracer.cpp b/src/drivers/win/tracer.cpp index 8a584b47..891482ec 100644 --- a/src/drivers/win/tracer.cpp +++ b/src/drivers/win/tracer.cpp @@ -648,7 +648,8 @@ void ShowLogDirDialog(void){ return; } -void DoTracer(){ +void DoTracer() +{ if (!GameInfo) { FCEUD_PrintError("You must have a game loaded before you can use the Trace Logger."); @@ -659,10 +660,14 @@ void DoTracer(){ // return; //} - if(!hTracer){ + if(!hTracer) + { CreateDialog(fceu_hInstance,"TRACER",NULL,TracerCallB); //hTracer gets set in WM_INITDIALOG - } else { - SetWindowPos(hTracer,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + } else + { + //SetWindowPos(hTracer,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); + ShowWindow(hTracer, SW_SHOWNORMAL); + SetForegroundWindow(hTracer); } } diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 61b36d12..935d639d 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -1687,11 +1687,14 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) //Lua submenu case ID_FILE_OPENLUAWINDOW: - if(!LuaConsoleHWnd) + if (!LuaConsoleHWnd) + { LuaConsoleHWnd = CreateDialog(fceu_hInstance, MAKEINTRESOURCE(IDD_LUA), hWnd, (DLGPROC) DlgLuaScriptDialog); - else + } else + { ShowWindow(LuaConsoleHWnd, SW_SHOWNORMAL); SetForegroundWindow(LuaConsoleHWnd); + } break; case FCEUX_CONTEXT_CLOSELUAWINDOWS: case ID_FILE_CLOSELUAWINDOWS: @@ -1921,9 +1924,11 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) if(!RamSearchHWnd) { OpenRamSearch(); - } - else + } else + { + ShowWindow(RamSearchHWnd, SW_SHOWNORMAL); SetForegroundWindow(RamSearchHWnd); + } break; case ID_RAM_WATCH: diff --git a/src/fceu.cpp b/src/fceu.cpp index 5518dd90..a69dd826 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -1050,7 +1050,6 @@ bool FCEU_IsValidUI(EFCEUI ui) case FCEUI_TASEDITOR: if(!GameInfo) return false; - if(FCEUMOV_Mode(MOVIEMODE_TASEDITOR)) return false; // can't run two TAS Editors break; case FCEUI_RESET: diff --git a/src/input.cpp b/src/input.cpp index 83636fef..a0694788 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -761,7 +761,7 @@ struct EMUCMDTABLE FCEUI_CommandTable[]= { EMUCMD_MISC_DISPLAY_BG_TOGGLE, EMUCMDTYPE_MISC, BackgroundDisplayToggle, 0, 0, "Toggle Background Display", EMUCMDFLAG_TASEDITOR }, { EMUCMD_MISC_DISPLAY_OBJ_TOGGLE, EMUCMDTYPE_MISC, ObjectDisplayToggle, 0, 0, "Toggle Object Display", EMUCMDFLAG_TASEDITOR }, { EMUCMD_MISC_DISPLAY_LAGCOUNTER_TOGGLE,EMUCMDTYPE_MISC, LagCounterToggle, 0, 0, "Lag Counter Toggle", EMUCMDFLAG_TASEDITOR }, - { EMUCMD_MISC_OPENTASEDITOR, EMUCMDTYPE_TOOL, LaunchTasEditor, 0, 0, "Open TAS Editor", 0}, + { EMUCMD_MISC_OPENTASEDITOR, EMUCMDTYPE_TOOL, LaunchTasEditor, 0, 0, "Open TAS Editor", EMUCMDFLAG_TASEDITOR }, { EMUCMD_TOOL_OPENMEMORYWATCH, EMUCMDTYPE_TOOL, LaunchMemoryWatch,0, 0, "Open Memory Watch", EMUCMDFLAG_TASEDITOR }, { EMUCMD_TOOL_OPENCHEATS, EMUCMDTYPE_TOOL, LaunchCheats, 0, 0, "Open Cheats", EMUCMDFLAG_TASEDITOR }, { EMUCMD_TOOL_OPENDEBUGGER, EMUCMDTYPE_TOOL, LaunchDebugger, 0, 0, "Open Debugger", EMUCMDFLAG_TASEDITOR },