From c7bfb684ae27d3455a9ec861a96969e811892d34 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Fri, 26 Nov 2021 05:45:16 -0500 Subject: [PATCH] Added TAS input pattern selection Qt GUI code. Fixed a few clock timing calculations in Qt TAS editor. --- src/drivers/Qt/TasEditor/TasEditorWindow.cpp | 48 +++++++++++++++++++- src/drivers/Qt/TasEditor/TasEditorWindow.h | 1 + src/drivers/Qt/TasEditor/greenzone.h | 3 +- src/drivers/Qt/TasEditor/history.h | 5 +- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/drivers/Qt/TasEditor/TasEditorWindow.cpp b/src/drivers/Qt/TasEditor/TasEditorWindow.cpp index 17a5b45e..9db888f6 100644 --- a/src/drivers/Qt/TasEditor/TasEditorWindow.cpp +++ b/src/drivers/Qt/TasEditor/TasEditorWindow.cpp @@ -329,8 +329,9 @@ void TasEditorWindow::closeWindow(void) QMenuBar *TasEditorWindow::buildMenuBar(void) { QMenu *fileMenu, *editMenu, *viewMenu, - *confMenu, *luaMenu, *helpMenu; - //QActionGroup *actGroup; + *confMenu, *luaMenu, *helpMenu, + *patternMenu; + QActionGroup *actGroup; QAction *act; int useNativeMenuBar=0; @@ -861,6 +862,27 @@ QMenuBar *TasEditorWindow::buildMenuBar(void) luaMenu->addAction(act); + // Pattern + patternMenu = menuBar->addMenu(tr("&Pattern")); + + actGroup = new QActionGroup(this); + + for (size_t i=0; i Names + act = new QAction(tr(patternsNames[i].c_str()), this); + act->setCheckable(true); + //act->setShortcut(QKeySequence(tr("Ctrl+N"))); + act->setStatusTip(tr(patternsNames[i].c_str())); + //act->setIcon( style()->standardIcon( QStyle::SP_FileDialogStart ) ); + connect(act, &QAction::triggered, [this, i] { setCurrentPattern(i); } ); + + actGroup->addAction(act); + patternMenu->addAction(act); + + act->setChecked( taseditorConfig.currentPattern == i ); + } + // Help helpMenu = menuBar->addMenu(tr("&Help")); @@ -2074,6 +2096,20 @@ void TasEditorWindow::openOnlineDocs(void) return; } //---------------------------------------------------------------------------- +void TasEditorWindow::setCurrentPattern(int idx) +{ + if ( idx < 0 ) + { + return; + } + if ( (size_t)idx >= patternsNames.size() ) + { + return; + } + //printf("Set Pattern: %i\n", idx); + taseditorConfig.currentPattern = idx; +} +//---------------------------------------------------------------------------- void TasEditorWindow::recordingChanged(int state) { FCEUI_MovieToggleReadOnly(); @@ -2705,7 +2741,9 @@ void TasEditorWindow::setInputUsingPattern(int start, int end, int joy, int butt } if (start < 0) start = end; if (end >= currMovieData.getNumRecords()) + { return; + } int pattern_offset = 0, current_pattern = taseditorConfig.currentPattern; bool changes_made = false; @@ -2715,7 +2753,9 @@ void TasEditorWindow::setInputUsingPattern(int start, int end, int joy, int butt { // skip lag frames if (taseditorConfig.autofirePatternSkipsLag && greenzone.lagLog.getLagInfoAtFrame(i) == LAGGED_YES) + { continue; + } value = (patterns[current_pattern][pattern_offset] != 0); if (currMovieData.records[i].checkBit(joy, button) != value) { @@ -2724,10 +2764,14 @@ void TasEditorWindow::setInputUsingPattern(int start, int end, int joy, int butt } pattern_offset++; if (pattern_offset >= (int)patterns[current_pattern].size()) + { pattern_offset -= patterns[current_pattern].size(); + } } if (changes_made) + { greenzone.invalidateAndUpdatePlayback(history.registerChanges(MODTYPE_PATTERN, start, end, 0, patternsNames[current_pattern].c_str(), consecutivenessTag)); + } } // following functions use current Selection to determine range of frames diff --git a/src/drivers/Qt/TasEditor/TasEditorWindow.h b/src/drivers/Qt/TasEditor/TasEditorWindow.h index 8b1a0131..1c1e3f23 100644 --- a/src/drivers/Qt/TasEditor/TasEditorWindow.h +++ b/src/drivers/Qt/TasEditor/TasEditorWindow.h @@ -371,6 +371,7 @@ class TasEditorWindow : public QDialog void openProjectSaveOptions(void); void setGreenzoneCapacity(void); void setMaxUndoCapacity(void); + void setCurrentPattern(int); void tabViewChanged(int); friend class RECORDER; diff --git a/src/drivers/Qt/TasEditor/greenzone.h b/src/drivers/Qt/TasEditor/greenzone.h index 27ed73f9..db6cd5b9 100644 --- a/src/drivers/Qt/TasEditor/greenzone.h +++ b/src/drivers/Qt/TasEditor/greenzone.h @@ -7,7 +7,8 @@ #define GREENZONE_ID_LEN 10 -#define TIME_BETWEEN_CLEANINGS 10000 // in milliseconds +#define TIME_BETWEEN_CLEANINGS (10000 * (CLOCKS_PER_SEC / 1000)) // in milliseconds + // Greenzone cleaning masks #define EVERY16TH 0xFFFFFFF0 #define EVERY8TH 0xFFFFFFF8 diff --git a/src/drivers/Qt/TasEditor/history.h b/src/drivers/Qt/TasEditor/history.h index 7e19552b..2a0a40a5 100644 --- a/src/drivers/Qt/TasEditor/history.h +++ b/src/drivers/Qt/TasEditor/history.h @@ -1,16 +1,17 @@ // Specification file for History class #pragma once #include +#include #include #include "fceu.h" #include "Qt/TasEditor/bookmark.h" #include "Qt/TasEditor/snapshot.h" -#define UNDO_HINT_TIME 200 // in milliseconds +#define UNDO_HINT_TIME (200 * (CLOCKS_PER_SEC / 1000)) // in milliseconds #define SAVING_HISTORY_PROGRESSBAR_UPDATE_RATE 10 -#define TIME_BETWEEN_AUTOCOMPRESSIONS 500 // in milliseconds +#define TIME_BETWEEN_AUTOCOMPRESSIONS (500 * (CLOCKS_PER_SEC / 1000)) // in milliseconds #define HISTORY_LIST_WIDTH 500