State recorder config setup in work.
This commit is contained in:
parent
f87d746350
commit
bb76573112
|
@ -28,6 +28,7 @@
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "Qt/fceuWrapper.h"
|
||||||
#include "Qt/StateRecorderConf.h"
|
#include "Qt/StateRecorderConf.h"
|
||||||
|
|
||||||
#include "../../fceu.h"
|
#include "../../fceu.h"
|
||||||
|
@ -54,6 +55,10 @@ StateRecorderDialog_t::StateRecorderDialog_t(QWidget *parent)
|
||||||
snapSeconds = new QSpinBox();
|
snapSeconds = new QSpinBox();
|
||||||
historyDuration = new QSpinBox();
|
historyDuration = new QSpinBox();
|
||||||
|
|
||||||
|
recorderEnable->setChecked( FCEU_StateRecorderIsEnabled() );
|
||||||
|
|
||||||
|
connect( recorderEnable, SIGNAL(stateChanged(int)), this, SLOT(enableChanged(int)) );
|
||||||
|
|
||||||
snapSeconds->setMinimum(0);
|
snapSeconds->setMinimum(0);
|
||||||
snapSeconds->setMaximum(60);
|
snapSeconds->setMaximum(60);
|
||||||
snapSeconds->setValue(3);
|
snapSeconds->setValue(3);
|
||||||
|
@ -64,6 +69,10 @@ StateRecorderDialog_t::StateRecorderDialog_t(QWidget *parent)
|
||||||
historyDuration->setMaximum(180);
|
historyDuration->setMaximum(180);
|
||||||
historyDuration->setValue(15);
|
historyDuration->setValue(15);
|
||||||
|
|
||||||
|
connect( snapSeconds, SIGNAL(valueChanged(int)), this, SLOT(spinBoxValueChanged(int)) );
|
||||||
|
connect( snapMinutes, SIGNAL(valueChanged(int)), this, SLOT(spinBoxValueChanged(int)) );
|
||||||
|
connect( historyDuration, SIGNAL(valueChanged(int)), this, SLOT(spinBoxValueChanged(int)) );
|
||||||
|
|
||||||
frame = new QGroupBox(tr("Retain History For:"));
|
frame = new QGroupBox(tr("Retain History For:"));
|
||||||
hbox = new QHBoxLayout();
|
hbox = new QHBoxLayout();
|
||||||
|
|
||||||
|
@ -131,6 +140,9 @@ StateRecorderDialog_t::StateRecorderDialog_t(QWidget *parent)
|
||||||
closeButton->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) );
|
closeButton->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) );
|
||||||
applyButton->setIcon( style()->standardIcon( QStyle::SP_DialogApplyButton ) );
|
applyButton->setIcon( style()->standardIcon( QStyle::SP_DialogApplyButton ) );
|
||||||
|
|
||||||
|
connect(closeButton, SIGNAL(clicked(void)), this, SLOT(closeWindow(void)));
|
||||||
|
connect(applyButton, SIGNAL(clicked(void)), this, SLOT(applyChanges(void)));
|
||||||
|
|
||||||
hbox->addWidget(applyButton, 1);
|
hbox->addWidget(applyButton, 1);
|
||||||
hbox->addStretch(8);
|
hbox->addStretch(8);
|
||||||
hbox->addWidget(closeButton, 1);
|
hbox->addWidget(closeButton, 1);
|
||||||
|
@ -164,6 +176,26 @@ void StateRecorderDialog_t::closeWindow(void)
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
void StateRecorderDialog_t::applyChanges(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void StateRecorderDialog_t::enableChanged(int val)
|
||||||
|
{
|
||||||
|
bool ena = val ? true : false;
|
||||||
|
|
||||||
|
FCEU_StateRecorderSetEnabled( ena );
|
||||||
|
|
||||||
|
g_config->setOption("SDL.StateRecorderEnable", ena);
|
||||||
|
g_config->save();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void StateRecorderDialog_t::spinBoxValueChanged(int newValue)
|
||||||
|
{
|
||||||
|
recalcMemoryUsage();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
void StateRecorderDialog_t::recalcMemoryUsage(void)
|
void StateRecorderDialog_t::recalcMemoryUsage(void)
|
||||||
{
|
{
|
||||||
char stmp[64];
|
char stmp[64];
|
||||||
|
|
|
@ -43,5 +43,7 @@ protected:
|
||||||
public slots:
|
public slots:
|
||||||
void closeWindow(void);
|
void closeWindow(void);
|
||||||
private slots:
|
private slots:
|
||||||
|
void applyChanges(void);
|
||||||
|
void spinBoxValueChanged(int newValue);
|
||||||
|
void enableChanged(int);
|
||||||
};
|
};
|
||||||
|
|
|
@ -754,6 +754,11 @@ InitConfig()
|
||||||
config->addOption("loadstate", "SDL.AutoLoadState", INVALID_STATE);
|
config->addOption("loadstate", "SDL.AutoLoadState", INVALID_STATE);
|
||||||
config->addOption("savestate", "SDL.AutoSaveState", INVALID_STATE);
|
config->addOption("savestate", "SDL.AutoSaveState", INVALID_STATE);
|
||||||
|
|
||||||
|
config->addOption("SDL.StateRecorderEnable", false);
|
||||||
|
config->addOption("SDL.StateRecorderHistoryDurationMin", 15);
|
||||||
|
config->addOption("SDL.StateRecorderTimeBetweenSnapsMin", 0);
|
||||||
|
config->addOption("SDL.StateRecorderTimeBetweenSnapsSec", 3);
|
||||||
|
|
||||||
//TODO implement this
|
//TODO implement this
|
||||||
config->addOption("periodicsaves", "SDL.PeriodicSaves", 0);
|
config->addOption("periodicsaves", "SDL.PeriodicSaves", 0);
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
#include "../../fceu.h"
|
#include "../../fceu.h"
|
||||||
#include "../../cheat.h"
|
#include "../../cheat.h"
|
||||||
#include "../../movie.h"
|
#include "../../movie.h"
|
||||||
|
#include "../../state.h"
|
||||||
#include "../../version.h"
|
#include "../../version.h"
|
||||||
|
|
||||||
#ifdef _S9XLUA_H
|
#ifdef _S9XLUA_H
|
||||||
|
@ -972,6 +973,12 @@ int fceuWrapperInit( int argc, char *argv[] )
|
||||||
// load the hotkeys from the config life
|
// load the hotkeys from the config life
|
||||||
setHotKeys();
|
setHotKeys();
|
||||||
|
|
||||||
|
// Initialize the State Recorder
|
||||||
|
bool srEnable = false;
|
||||||
|
g_config->getOption("SDL.StateRecorderEnable", &srEnable);
|
||||||
|
|
||||||
|
FCEU_StateRecorderSetEnabled( srEnable );
|
||||||
|
|
||||||
if (romIndex >= 0)
|
if (romIndex >= 0)
|
||||||
{
|
{
|
||||||
QFileInfo fi( argv[romIndex] );
|
QFileInfo fi( argv[romIndex] );
|
||||||
|
|
|
@ -1185,23 +1185,23 @@ void RedoLoadState()
|
||||||
//----------- Save State History ----------------
|
//----------- Save State History ----------------
|
||||||
//-----------------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------------
|
||||||
//-----------------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
static StateRecorderConfigData stateRecorderConfig;
|
||||||
|
|
||||||
class StateRecorder
|
class StateRecorder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StateRecorder(void)
|
StateRecorder(void)
|
||||||
{
|
{
|
||||||
size_t ringBufSize = 60;
|
loadConfig( stateRecorderConfig );
|
||||||
|
|
||||||
for (size_t i=0; i<ringBufSize; i++)
|
for (int i=0; i<ringBufSize; i++)
|
||||||
{
|
{
|
||||||
EMUFILE_MEMORY *em = new EMUFILE_MEMORY( 0x10000 );
|
EMUFILE_MEMORY *em = new EMUFILE_MEMORY( 0x1000 );
|
||||||
|
|
||||||
ringBuf.push_back(em);
|
ringBuf.push_back(em);
|
||||||
}
|
}
|
||||||
ringStart = ringHead = ringTail = 0;
|
ringStart = ringHead = ringTail = 0;
|
||||||
frameCounter = 0;
|
frameCounter = 0;
|
||||||
framesPerSnap = 3 * 60;
|
|
||||||
compressionLevel = Z_NO_COMPRESSION;
|
|
||||||
lastState = ringHead;
|
lastState = ringHead;
|
||||||
loadIndexReset = false;
|
loadIndexReset = false;
|
||||||
lastLoadFrame = 0;
|
lastLoadFrame = 0;
|
||||||
|
@ -1216,6 +1216,35 @@ class StateRecorder
|
||||||
ringBuf.clear();
|
ringBuf.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loadConfig( StateRecorderConfigData &config )
|
||||||
|
{
|
||||||
|
if (config.timeBetweenSnapsMinutes < 0.0)
|
||||||
|
{
|
||||||
|
config.timeBetweenSnapsMinutes = 3.0f / 60.0f;
|
||||||
|
}
|
||||||
|
if (config.timeBetweenSnapsMinutes > config.historyDurationMinutes)
|
||||||
|
{
|
||||||
|
config.historyDurationMinutes = config.timeBetweenSnapsMinutes;
|
||||||
|
}
|
||||||
|
const double fhistMin = config.historyDurationMinutes;
|
||||||
|
const double fsnapMin = config.timeBetweenSnapsMinutes;
|
||||||
|
const double fnumSnaps = fhistMin / fsnapMin;
|
||||||
|
|
||||||
|
ringBufSize = static_cast<int>( fnumSnaps + 0.5f );
|
||||||
|
|
||||||
|
int32_t fps = FCEUI_GetDesiredFPS(); // Do >> 24 to get in Hz
|
||||||
|
|
||||||
|
double hz = ( ((double)fps) / 16777216.0 );
|
||||||
|
|
||||||
|
double framesPerSnapf = hz * fsnapMin * 60.0;
|
||||||
|
|
||||||
|
framesPerSnap = static_cast<unsigned int>( framesPerSnapf + 0.50 );
|
||||||
|
|
||||||
|
printf("ringBufSize:%i framesPerSnap:%i\n", ringBufSize, framesPerSnap );
|
||||||
|
|
||||||
|
compressionLevel = stateRecorderConfig.compressionLevel;
|
||||||
|
}
|
||||||
|
|
||||||
void update(void)
|
void update(void)
|
||||||
{
|
{
|
||||||
bool isPaused = FCEUI_EmulationPaused() ? true : false;
|
bool isPaused = FCEUI_EmulationPaused() ? true : false;
|
||||||
|
@ -1224,8 +1253,6 @@ class StateRecorder
|
||||||
|
|
||||||
if (!isPaused && loadIndexReset)
|
if (!isPaused && loadIndexReset)
|
||||||
{
|
{
|
||||||
int ringBufSize = static_cast<int>( ringBuf.size() );
|
|
||||||
|
|
||||||
ringHead = (lastState + 1) % ringBufSize;
|
ringHead = (lastState + 1) % ringBufSize;
|
||||||
|
|
||||||
frameCounter = curFrame;
|
frameCounter = curFrame;
|
||||||
|
@ -1239,8 +1266,6 @@ class StateRecorder
|
||||||
|
|
||||||
if ( (frameCounter % framesPerSnap) == 0 )
|
if ( (frameCounter % framesPerSnap) == 0 )
|
||||||
{
|
{
|
||||||
int ringBufSize = static_cast<int>( ringBuf.size() );
|
|
||||||
|
|
||||||
EMUFILE_MEMORY *em = ringBuf[ ringHead ];
|
EMUFILE_MEMORY *em = ringBuf[ ringHead ];
|
||||||
|
|
||||||
em->set_len(0);
|
em->set_len(0);
|
||||||
|
@ -1263,8 +1288,6 @@ class StateRecorder
|
||||||
|
|
||||||
int loadStateRelativeToEnd( int numSnapsFromLatest )
|
int loadStateRelativeToEnd( int numSnapsFromLatest )
|
||||||
{
|
{
|
||||||
int ringBufSize = static_cast<int>( ringBuf.size() );
|
|
||||||
|
|
||||||
if (numSnapsFromLatest < 0)
|
if (numSnapsFromLatest < 0)
|
||||||
{
|
{
|
||||||
numSnapsFromLatest = 0;
|
numSnapsFromLatest = 0;
|
||||||
|
@ -1280,8 +1303,6 @@ class StateRecorder
|
||||||
|
|
||||||
int loadStateByIndex( int snapIdx )
|
int loadStateByIndex( int snapIdx )
|
||||||
{
|
{
|
||||||
int ringBufSize = static_cast<int>( ringBuf.size() );
|
|
||||||
|
|
||||||
if (snapIdx < 0)
|
if (snapIdx < 0)
|
||||||
{
|
{
|
||||||
snapIdx = snapIdx + ringBufSize;
|
snapIdx = snapIdx + ringBufSize;
|
||||||
|
@ -1339,6 +1360,7 @@ class StateRecorder
|
||||||
int ringHead;
|
int ringHead;
|
||||||
int ringTail;
|
int ringTail;
|
||||||
int ringStart;
|
int ringStart;
|
||||||
|
int ringBufSize;
|
||||||
int compressionLevel;
|
int compressionLevel;
|
||||||
unsigned int frameCounter;
|
unsigned int frameCounter;
|
||||||
unsigned int framesPerSnap;
|
unsigned int framesPerSnap;
|
||||||
|
@ -1383,6 +1405,11 @@ bool FCEU_StateRecorderIsEnabled(void)
|
||||||
return StateRecorder::enabled;
|
return StateRecorder::enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FCEU_StateRecorderSetEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
StateRecorder::enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
bool FCEU_StateRecorderRunning(void)
|
bool FCEU_StateRecorderRunning(void)
|
||||||
{
|
{
|
||||||
return stateRecorder != nullptr;
|
return stateRecorder != nullptr;
|
||||||
|
@ -1401,3 +1428,13 @@ int FCEU_StateRecorderGetStateIndex(void)
|
||||||
{
|
{
|
||||||
return StateRecorder::lastState;
|
return StateRecorder::lastState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const StateRecorderConfigData& FCEU_StateRecorderGetConfigData(void)
|
||||||
|
{
|
||||||
|
return stateRecorderConfig;
|
||||||
|
}
|
||||||
|
int FCEU_StateRecorderSetConfigData(const StateRecorderConfigData &newConfig)
|
||||||
|
{
|
||||||
|
stateRecorderConfig = newConfig;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
17
src/state.h
17
src/state.h
|
@ -79,10 +79,27 @@ bool CheckBackupSaveStateExist(); //Checks if backupsavestate exists
|
||||||
|
|
||||||
extern bool compressSavestates; //Whether or not to compress non-movie savestates (by default, yes)
|
extern bool compressSavestates; //Whether or not to compress non-movie savestates (by default, yes)
|
||||||
|
|
||||||
|
struct StateRecorderConfigData
|
||||||
|
{
|
||||||
|
float historyDurationMinutes;
|
||||||
|
float timeBetweenSnapsMinutes;
|
||||||
|
int compressionLevel;
|
||||||
|
|
||||||
|
StateRecorderConfigData(void)
|
||||||
|
{
|
||||||
|
historyDurationMinutes = 15.0f;
|
||||||
|
timeBetweenSnapsMinutes = 3.0f / 60.0f;
|
||||||
|
compressionLevel = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
int FCEU_StateRecorderStart(void);
|
int FCEU_StateRecorderStart(void);
|
||||||
int FCEU_StateRecorderStop(void);
|
int FCEU_StateRecorderStop(void);
|
||||||
int FCEU_StateRecorderUpdate(void);
|
int FCEU_StateRecorderUpdate(void);
|
||||||
bool FCEU_StateRecorderRunning(void);
|
bool FCEU_StateRecorderRunning(void);
|
||||||
bool FCEU_StateRecorderIsEnabled(void);
|
bool FCEU_StateRecorderIsEnabled(void);
|
||||||
|
void FCEU_StateRecorderSetEnabled(bool enabled);
|
||||||
int FCEU_StateRecorderGetStateIndex(void);
|
int FCEU_StateRecorderGetStateIndex(void);
|
||||||
int FCEU_StateRecorderLoadState(int snapIndex);
|
int FCEU_StateRecorderLoadState(int snapIndex);
|
||||||
|
int FCEU_StateRecorderSetConfigData(const StateRecorderConfigData &newConfig);
|
||||||
|
const StateRecorderConfigData& FCEU_StateRecorderGetConfigData(void);
|
||||||
|
|
Loading…
Reference in New Issue