Skip to content

Commit 4b85285

Browse files
committed
Added code to save/load state recorder config parameters for Qt gui.
1 parent bb76573 commit 4b85285

File tree

4 files changed

+90
-9
lines changed

4 files changed

+90
-9
lines changed

src/drivers/Qt/StateRecorderConf.cpp

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ StateRecorderDialog_t::StateRecorderDialog_t(QWidget *parent)
4444
QGroupBox *frame, *frame1;
4545
QGridLayout *grid, *memStatsGrid;
4646
QSettings settings;
47+
int opt;
4748

4849
setWindowTitle("State Recorder Config");
4950

@@ -61,13 +62,22 @@ StateRecorderDialog_t::StateRecorderDialog_t(QWidget *parent)
6162

6263
snapSeconds->setMinimum(0);
6364
snapSeconds->setMaximum(60);
64-
snapSeconds->setValue(3);
6565
snapMinutes->setMinimum(0);
6666
snapMinutes->setMaximum(60);
67-
snapMinutes->setValue(0);
6867
historyDuration->setMinimum(1);
6968
historyDuration->setMaximum(180);
70-
historyDuration->setValue(15);
69+
70+
opt = 15;
71+
g_config->getOption("SDL.StateRecorderHistoryDurationMin", &opt );
72+
historyDuration->setValue(opt);
73+
74+
opt = 0;
75+
g_config->getOption("SDL.StateRecorderTimeBetweenSnapsMin", &opt);
76+
snapMinutes->setValue(opt);
77+
78+
opt = 3;
79+
g_config->getOption("SDL.StateRecorderTimeBetweenSnapsSec", &opt);
80+
snapSeconds->setValue(opt);
7181

7282
connect( snapSeconds, SIGNAL(valueChanged(int)), this, SLOT(spinBoxValueChanged(int)) );
7383
connect( snapMinutes, SIGNAL(valueChanged(int)), this, SLOT(spinBoxValueChanged(int)) );
@@ -84,10 +94,34 @@ StateRecorderDialog_t::StateRecorderDialog_t(QWidget *parent)
8494
grid->addWidget( recorderEnable, 0, 0 );
8595
grid->addWidget( frame , 1, 0 );
8696

97+
frame = new QGroupBox(tr("Compression Level:"));
98+
hbox = new QHBoxLayout();
99+
100+
cmprLvlCbox = new QComboBox();
101+
cmprLvlCbox->addItem( tr("0 - None"), 0 );
102+
cmprLvlCbox->addItem( tr("1"), 1 );
103+
cmprLvlCbox->addItem( tr("2"), 2 );
104+
cmprLvlCbox->addItem( tr("3"), 3 );
105+
cmprLvlCbox->addItem( tr("4"), 4 );
106+
cmprLvlCbox->addItem( tr("5"), 5 );
107+
cmprLvlCbox->addItem( tr("6"), 6 );
108+
cmprLvlCbox->addItem( tr("7"), 7 );
109+
cmprLvlCbox->addItem( tr("8"), 8 );
110+
cmprLvlCbox->addItem( tr("9 - Max"), 9 );
111+
112+
opt = 0;
113+
g_config->getOption("SDL.StateRecorderCompressionLevel", &opt);
114+
cmprLvlCbox->setCurrentIndex(opt);
115+
116+
hbox->addWidget(cmprLvlCbox);
117+
118+
frame->setLayout(hbox);
119+
grid->addWidget( frame, 1, 1 );
120+
87121
frame1 = new QGroupBox(tr("Time Between Snapshots:"));
88122
hbox1 = new QHBoxLayout();
89123
frame1->setLayout(hbox1);
90-
grid->addWidget( frame1, 2, 0 );
124+
grid->addWidget( frame1, 2, 0, 1, 2 );
91125

92126
frame = new QGroupBox();
93127
hbox = new QHBoxLayout();
@@ -118,7 +152,7 @@ StateRecorderDialog_t::StateRecorderDialog_t(QWidget *parent)
118152
snapMemSizeLbl->setReadOnly(true);
119153
totalMemUsageLbl->setReadOnly(true);
120154

121-
grid->addWidget(frame, 1, 2, 2, 2);
155+
grid->addWidget(frame, 1, 3, 2, 2);
122156
frame->setLayout(memStatsGrid);
123157
memStatsGrid->addWidget( new QLabel( tr("Number of\nSnapshots:") ), 0, 0 );
124158
memStatsGrid->addWidget( numSnapsLbl, 0, 1 );
@@ -178,16 +212,38 @@ void StateRecorderDialog_t::closeWindow(void)
178212
//----------------------------------------------------------------------------
179213
void StateRecorderDialog_t::applyChanges(void)
180214
{
215+
StateRecorderConfigData config;
216+
217+
config.historyDurationMinutes = static_cast<float>( historyDuration->value() );
218+
config.timeBetweenSnapsMinutes = static_cast<float>( snapMinutes->value() ) +
219+
( static_cast<float>( snapSeconds->value() ) / 60.0f );
220+
config.compressionLevel = cmprLvlCbox->currentData().toInt();
221+
222+
FCEU_WRAPPER_LOCK();
223+
FCEU_StateRecorderSetEnabled( recorderEnable->isChecked() );
224+
FCEU_StateRecorderSetConfigData( config );
225+
if (FCEU_StateRecorderRunning())
226+
{
227+
// TODO restart with new settings
228+
}
229+
FCEU_WRAPPER_UNLOCK();
181230

231+
g_config->setOption("SDL.StateRecorderHistoryDurationMin", historyDuration->value() );
232+
g_config->setOption("SDL.StateRecorderTimeBetweenSnapsMin", snapMinutes->value() );
233+
g_config->setOption("SDL.StateRecorderTimeBetweenSnapsSec", snapSeconds->value() );
234+
g_config->setOption("SDL.StateRecorderEnable", recorderEnable->isChecked() );
235+
g_config->save();
182236
}
183237
//----------------------------------------------------------------------------
184238
void StateRecorderDialog_t::enableChanged(int val)
185239
{
186240
bool ena = val ? true : false;
187241

242+
FCEU_WRAPPER_LOCK();
188243
FCEU_StateRecorderSetEnabled( ena );
244+
FCEU_WRAPPER_UNLOCK();
189245

190-
g_config->setOption("SDL.StateRecorderEnable", ena);
246+
g_config->setOption("SDL.StateRecorderEnable", ena );
191247
g_config->save();
192248
}
193249
//----------------------------------------------------------------------------
@@ -218,12 +274,16 @@ void StateRecorderDialog_t::recalcMemoryUsage(void)
218274

219275
if (GameInfo)
220276
{
277+
FCEU_WRAPPER_LOCK();
278+
221279
EMUFILE_MEMORY em;
222280
int compressionLevel = 0;
223281

224282
FCEUSS_SaveMS( &em, compressionLevel );
225283

226284
fsnapSize = static_cast<float>( em.size() ) / 1024.0f;
285+
286+
FCEU_WRAPPER_UNLOCK();
227287
}
228288

229289
if (fsnapSize >= oneKiloByte)

src/drivers/Qt/StateRecorderConf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class StateRecorderDialog_t : public QDialog
3737
QLineEdit *totalMemUsageLbl;
3838
QPushButton *applyButton;
3939
QPushButton *closeButton;
40+
QComboBox *cmprLvlCbox;
4041

4142
void recalcMemoryUsage(void);
4243

src/drivers/Qt/config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ InitConfig()
758758
config->addOption("SDL.StateRecorderHistoryDurationMin", 15);
759759
config->addOption("SDL.StateRecorderTimeBetweenSnapsMin", 0);
760760
config->addOption("SDL.StateRecorderTimeBetweenSnapsSec", 3);
761+
config->addOption("SDL.StateRecorderCompressionLevel", 0);
761762

762763
//TODO implement this
763764
config->addOption("periodicsaves", "SDL.PeriodicSaves", 0);

src/drivers/Qt/fceuWrapper.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,30 @@ int fceuWrapperInit( int argc, char *argv[] )
974974
setHotKeys();
975975

976976
// Initialize the State Recorder
977-
bool srEnable = false;
978-
g_config->getOption("SDL.StateRecorderEnable", &srEnable);
977+
{
978+
bool srEnable = false;
979+
int srHistDurMin = 15;
980+
int srTimeBtwSnapsMin = 0;
981+
int srTimeBtwSnapsSec = 3;
982+
int srCompressionLevel = 0;
983+
g_config->getOption("SDL.StateRecorderEnable", &srEnable);
984+
g_config->getOption("SDL.StateRecorderHistoryDurationMin", &srHistDurMin);
985+
g_config->getOption("SDL.StateRecorderTimeBetweenSnapsMin", &srTimeBtwSnapsMin);
986+
g_config->getOption("SDL.StateRecorderTimeBetweenSnapsSec", &srTimeBtwSnapsSec);
987+
g_config->getOption("SDL.StateRecorderCompressionLevel", &srCompressionLevel);
988+
989+
StateRecorderConfigData srConfig;
979990

980-
FCEU_StateRecorderSetEnabled( srEnable );
991+
srConfig.historyDurationMinutes = srHistDurMin;
992+
srConfig.timeBetweenSnapsMinutes = static_cast<float>( srTimeBtwSnapsMin ) +
993+
( static_cast<float>( srTimeBtwSnapsSec ) / 60.0f );
994+
srConfig.compressionLevel = srCompressionLevel;
995+
996+
FCEU_StateRecorderSetEnabled( srEnable );
997+
FCEU_StateRecorderSetConfigData( srConfig );
998+
}
981999

1000+
// Rom Load
9821001
if (romIndex >= 0)
9831002
{
9841003
QFileInfo fi( argv[romIndex] );

0 commit comments

Comments
 (0)