Added initial framework for movie JS API. Still TODO implement rest of movie functions.
This commit is contained in:
parent
af9b53ba75
commit
aaa519d29c
|
@ -872,6 +872,78 @@ void PpuScriptObject::writeByte(int address, int value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
//---- Movie Script Object
|
||||||
|
//----------------------------------------------------
|
||||||
|
//----------------------------------------------------
|
||||||
|
MovieScriptObject::MovieScriptObject(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
script = qobject_cast<QtScriptInstance*>(parent);
|
||||||
|
engine = script->getEngine();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
MovieScriptObject::~MovieScriptObject()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
bool MovieScriptObject::active()
|
||||||
|
{
|
||||||
|
bool movieActive = (FCEUMOV_IsRecording() || FCEUMOV_IsPlaying());
|
||||||
|
return movieActive;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
bool MovieScriptObject::isPlaying()
|
||||||
|
{
|
||||||
|
bool playing = FCEUMOV_IsPlaying();
|
||||||
|
return playing;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
bool MovieScriptObject::isRecording()
|
||||||
|
{
|
||||||
|
bool recording = FCEUMOV_IsRecording();
|
||||||
|
return recording;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
bool MovieScriptObject::isPowerOn()
|
||||||
|
{
|
||||||
|
bool flag = false;
|
||||||
|
if (FCEUMOV_IsRecording() || FCEUMOV_IsPlaying())
|
||||||
|
{
|
||||||
|
flag = FCEUMOV_FromPoweron();
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
bool MovieScriptObject::isFromSaveState()
|
||||||
|
{
|
||||||
|
bool flag = false;
|
||||||
|
if (FCEUMOV_IsRecording() || FCEUMOV_IsPlaying())
|
||||||
|
{
|
||||||
|
flag = !FCEUMOV_FromPoweron();
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
bool MovieScriptObject::record(const QString& filename, int saveType, const QString author)
|
||||||
|
{
|
||||||
|
if (filename.isEmpty())
|
||||||
|
{
|
||||||
|
script->throwError(QJSValue::GenericError, "movie.record(): Filename required");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No need to use the full functionality of the enum
|
||||||
|
EMOVIE_FLAG flags;
|
||||||
|
if (saveType == FROM_SAVESTATE) flags = MOVIE_FLAG_NONE; // from savestate
|
||||||
|
else if (saveType == FROM_SAVERAM ) flags = MOVIE_FLAG_FROM_SAVERAM;
|
||||||
|
else flags = MOVIE_FLAG_FROM_POWERON;
|
||||||
|
|
||||||
|
// Save it!
|
||||||
|
FCEUI_SaveMovie( filename.toLocal8Bit().data(), flags, author.toStdWString());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
//---- Input Script Object
|
//---- Input Script Object
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
@ -1437,6 +1509,11 @@ void QtScriptInstance::shutdownEngine()
|
||||||
delete input;
|
delete input;
|
||||||
input = nullptr;
|
input = nullptr;
|
||||||
}
|
}
|
||||||
|
if (movie != nullptr)
|
||||||
|
{
|
||||||
|
delete movie;
|
||||||
|
movie = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (ui_rootWidget != nullptr)
|
if (ui_rootWidget != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -1464,6 +1541,7 @@ int QtScriptInstance::initEngine()
|
||||||
ppu = new JS::PpuScriptObject(this);
|
ppu = new JS::PpuScriptObject(this);
|
||||||
mem = new JS::MemoryScriptObject(this);
|
mem = new JS::MemoryScriptObject(this);
|
||||||
input = new JS::InputScriptObject(this);
|
input = new JS::InputScriptObject(this);
|
||||||
|
movie = new JS::MovieScriptObject(this);
|
||||||
|
|
||||||
emu->setDialog(dialog);
|
emu->setDialog(dialog);
|
||||||
rom->setDialog(dialog);
|
rom->setDialog(dialog);
|
||||||
|
@ -1500,6 +1578,11 @@ int QtScriptInstance::initEngine()
|
||||||
|
|
||||||
engine->globalObject().setProperty("input", inputObject);
|
engine->globalObject().setProperty("input", inputObject);
|
||||||
|
|
||||||
|
// movie
|
||||||
|
QJSValue movieObject = engine->newQObject(movie);
|
||||||
|
|
||||||
|
engine->globalObject().setProperty("movie", movieObject);
|
||||||
|
|
||||||
// gui
|
// gui
|
||||||
QJSValue guiObject = engine->newQObject(this);
|
QJSValue guiObject = engine->newQObject(this);
|
||||||
|
|
||||||
|
@ -1668,8 +1751,7 @@ bool QtScriptInstance::onGuiThread()
|
||||||
int QtScriptInstance::throwError(QJSValue::ErrorType errorType, const QString &message)
|
int QtScriptInstance::throwError(QJSValue::ErrorType errorType, const QString &message)
|
||||||
{
|
{
|
||||||
running = false;
|
running = false;
|
||||||
print(message);
|
engine->throwError(errorType, message);
|
||||||
engine->setInterrupted(true);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
|
|
@ -103,6 +103,8 @@ public slots:
|
||||||
Q_INVOKABLE void setBlue(int b){ color.setBlue(b); }
|
Q_INVOKABLE void setBlue(int b){ color.setBlue(b); }
|
||||||
Q_INVOKABLE int getPalette(){ return _palette; }
|
Q_INVOKABLE int getPalette(){ return _palette; }
|
||||||
Q_INVOKABLE void setPalette(int p){ _palette = p; }
|
Q_INVOKABLE void setPalette(int p){ _palette = p; }
|
||||||
|
Q_INVOKABLE int toRGB8(){ return color.value(); }
|
||||||
|
Q_INVOKABLE QString name(){ return color.name(QColor::HexRgb); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class JoypadScriptObject: public QObject
|
class JoypadScriptObject: public QObject
|
||||||
|
@ -472,6 +474,35 @@ public slots:
|
||||||
Q_INVOKABLE void writeByte(int address, int value);
|
Q_INVOKABLE void writeByte(int address, int value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MovieScriptObject: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MovieScriptObject(QObject* parent = nullptr);
|
||||||
|
~MovieScriptObject();
|
||||||
|
|
||||||
|
void setEngine(FCEU::JSEngine* _engine){ engine = _engine; }
|
||||||
|
|
||||||
|
enum SaveType
|
||||||
|
{
|
||||||
|
FROM_POWERON = 0,
|
||||||
|
FROM_SAVESTATE,
|
||||||
|
FROM_SAVERAM,
|
||||||
|
};
|
||||||
|
Q_ENUM(SaveType);
|
||||||
|
private:
|
||||||
|
FCEU::JSEngine* engine = nullptr;
|
||||||
|
QtScriptInstance* script = nullptr;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
Q_INVOKABLE bool active();
|
||||||
|
Q_INVOKABLE bool isPlaying();
|
||||||
|
Q_INVOKABLE bool isRecording();
|
||||||
|
Q_INVOKABLE bool isPowerOn();
|
||||||
|
Q_INVOKABLE bool isFromSaveState();
|
||||||
|
Q_INVOKABLE bool record(const QString& filename, int saveType = FROM_POWERON, const QString author = QString());
|
||||||
|
};
|
||||||
|
|
||||||
class InputScriptObject: public QObject
|
class InputScriptObject: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -480,11 +511,9 @@ public:
|
||||||
~InputScriptObject();
|
~InputScriptObject();
|
||||||
|
|
||||||
void setEngine(FCEU::JSEngine* _engine){ engine = _engine; }
|
void setEngine(FCEU::JSEngine* _engine){ engine = _engine; }
|
||||||
void setDialog(QScriptDialog_t* _dialog){ dialog = _dialog; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FCEU::JSEngine* engine = nullptr;
|
FCEU::JSEngine* engine = nullptr;
|
||||||
QScriptDialog_t* dialog = nullptr;
|
|
||||||
QtScriptInstance* script = nullptr;
|
QtScriptInstance* script = nullptr;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -563,6 +592,7 @@ private:
|
||||||
JS::PpuScriptObject* ppu = nullptr;
|
JS::PpuScriptObject* ppu = nullptr;
|
||||||
JS::MemoryScriptObject* mem = nullptr;
|
JS::MemoryScriptObject* mem = nullptr;
|
||||||
JS::InputScriptObject* input = nullptr;
|
JS::InputScriptObject* input = nullptr;
|
||||||
|
JS::MovieScriptObject* movie = nullptr;
|
||||||
QWidget* ui_rootWidget = nullptr;
|
QWidget* ui_rootWidget = nullptr;
|
||||||
QJSValue *onFrameBeginCallback = nullptr;
|
QJSValue *onFrameBeginCallback = nullptr;
|
||||||
QJSValue *onFrameFinishCallback = nullptr;
|
QJSValue *onFrameFinishCallback = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue