Skip to content

Commit aaa519d

Browse files
committed
Added initial framework for movie JS API. Still TODO implement rest of movie functions.
1 parent af9b53b commit aaa519d

File tree

2 files changed

+116
-4
lines changed

2 files changed

+116
-4
lines changed

src/drivers/Qt/QtScriptManager.cpp

+84-2
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,78 @@ void PpuScriptObject::writeByte(int address, int value)
872872
}
873873
}
874874
//----------------------------------------------------
875+
//---- Movie Script Object
876+
//----------------------------------------------------
877+
//----------------------------------------------------
878+
MovieScriptObject::MovieScriptObject(QObject* parent)
879+
: QObject(parent)
880+
{
881+
script = qobject_cast<QtScriptInstance*>(parent);
882+
engine = script->getEngine();
883+
}
884+
//----------------------------------------------------
885+
MovieScriptObject::~MovieScriptObject()
886+
{
887+
}
888+
//----------------------------------------------------
889+
bool MovieScriptObject::active()
890+
{
891+
bool movieActive = (FCEUMOV_IsRecording() || FCEUMOV_IsPlaying());
892+
return movieActive;
893+
}
894+
//----------------------------------------------------
895+
bool MovieScriptObject::isPlaying()
896+
{
897+
bool playing = FCEUMOV_IsPlaying();
898+
return playing;
899+
}
900+
//----------------------------------------------------
901+
bool MovieScriptObject::isRecording()
902+
{
903+
bool recording = FCEUMOV_IsRecording();
904+
return recording;
905+
}
906+
//----------------------------------------------------
907+
bool MovieScriptObject::isPowerOn()
908+
{
909+
bool flag = false;
910+
if (FCEUMOV_IsRecording() || FCEUMOV_IsPlaying())
911+
{
912+
flag = FCEUMOV_FromPoweron();
913+
}
914+
return flag;
915+
}
916+
//----------------------------------------------------
917+
bool MovieScriptObject::isFromSaveState()
918+
{
919+
bool flag = false;
920+
if (FCEUMOV_IsRecording() || FCEUMOV_IsPlaying())
921+
{
922+
flag = !FCEUMOV_FromPoweron();
923+
}
924+
return flag;
925+
}
926+
//----------------------------------------------------
927+
bool MovieScriptObject::record(const QString& filename, int saveType, const QString author)
928+
{
929+
if (filename.isEmpty())
930+
{
931+
script->throwError(QJSValue::GenericError, "movie.record(): Filename required");
932+
return false;
933+
}
934+
935+
// No need to use the full functionality of the enum
936+
EMOVIE_FLAG flags;
937+
if (saveType == FROM_SAVESTATE) flags = MOVIE_FLAG_NONE; // from savestate
938+
else if (saveType == FROM_SAVERAM ) flags = MOVIE_FLAG_FROM_SAVERAM;
939+
else flags = MOVIE_FLAG_FROM_POWERON;
940+
941+
// Save it!
942+
FCEUI_SaveMovie( filename.toLocal8Bit().data(), flags, author.toStdWString());
943+
944+
return true;
945+
}
946+
//----------------------------------------------------
875947
//---- Input Script Object
876948
//----------------------------------------------------
877949
//----------------------------------------------------
@@ -1437,6 +1509,11 @@ void QtScriptInstance::shutdownEngine()
14371509
delete input;
14381510
input = nullptr;
14391511
}
1512+
if (movie != nullptr)
1513+
{
1514+
delete movie;
1515+
movie = nullptr;
1516+
}
14401517

14411518
if (ui_rootWidget != nullptr)
14421519
{
@@ -1464,6 +1541,7 @@ int QtScriptInstance::initEngine()
14641541
ppu = new JS::PpuScriptObject(this);
14651542
mem = new JS::MemoryScriptObject(this);
14661543
input = new JS::InputScriptObject(this);
1544+
movie = new JS::MovieScriptObject(this);
14671545

14681546
emu->setDialog(dialog);
14691547
rom->setDialog(dialog);
@@ -1500,6 +1578,11 @@ int QtScriptInstance::initEngine()
15001578

15011579
engine->globalObject().setProperty("input", inputObject);
15021580

1581+
// movie
1582+
QJSValue movieObject = engine->newQObject(movie);
1583+
1584+
engine->globalObject().setProperty("movie", movieObject);
1585+
15031586
// gui
15041587
QJSValue guiObject = engine->newQObject(this);
15051588

@@ -1668,8 +1751,7 @@ bool QtScriptInstance::onGuiThread()
16681751
int QtScriptInstance::throwError(QJSValue::ErrorType errorType, const QString &message)
16691752
{
16701753
running = false;
1671-
print(message);
1672-
engine->setInterrupted(true);
1754+
engine->throwError(errorType, message);
16731755
return 0;
16741756
}
16751757
//----------------------------------------------------

src/drivers/Qt/QtScriptManager.h

+32-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public slots:
103103
Q_INVOKABLE void setBlue(int b){ color.setBlue(b); }
104104
Q_INVOKABLE int getPalette(){ return _palette; }
105105
Q_INVOKABLE void setPalette(int p){ _palette = p; }
106+
Q_INVOKABLE int toRGB8(){ return color.value(); }
107+
Q_INVOKABLE QString name(){ return color.name(QColor::HexRgb); }
106108
};
107109

108110
class JoypadScriptObject: public QObject
@@ -472,6 +474,35 @@ public slots:
472474
Q_INVOKABLE void writeByte(int address, int value);
473475
};
474476

477+
class MovieScriptObject: public QObject
478+
{
479+
Q_OBJECT
480+
public:
481+
MovieScriptObject(QObject* parent = nullptr);
482+
~MovieScriptObject();
483+
484+
void setEngine(FCEU::JSEngine* _engine){ engine = _engine; }
485+
486+
enum SaveType
487+
{
488+
FROM_POWERON = 0,
489+
FROM_SAVESTATE,
490+
FROM_SAVERAM,
491+
};
492+
Q_ENUM(SaveType);
493+
private:
494+
FCEU::JSEngine* engine = nullptr;
495+
QtScriptInstance* script = nullptr;
496+
497+
public slots:
498+
Q_INVOKABLE bool active();
499+
Q_INVOKABLE bool isPlaying();
500+
Q_INVOKABLE bool isRecording();
501+
Q_INVOKABLE bool isPowerOn();
502+
Q_INVOKABLE bool isFromSaveState();
503+
Q_INVOKABLE bool record(const QString& filename, int saveType = FROM_POWERON, const QString author = QString());
504+
};
505+
475506
class InputScriptObject: public QObject
476507
{
477508
Q_OBJECT
@@ -480,11 +511,9 @@ class InputScriptObject: public QObject
480511
~InputScriptObject();
481512

482513
void setEngine(FCEU::JSEngine* _engine){ engine = _engine; }
483-
void setDialog(QScriptDialog_t* _dialog){ dialog = _dialog; }
484514

485515
private:
486516
FCEU::JSEngine* engine = nullptr;
487-
QScriptDialog_t* dialog = nullptr;
488517
QtScriptInstance* script = nullptr;
489518

490519
public slots:
@@ -563,6 +592,7 @@ class QtScriptInstance : public QObject
563592
JS::PpuScriptObject* ppu = nullptr;
564593
JS::MemoryScriptObject* mem = nullptr;
565594
JS::InputScriptObject* input = nullptr;
595+
JS::MovieScriptObject* movie = nullptr;
566596
QWidget* ui_rootWidget = nullptr;
567597
QJSValue *onFrameBeginCallback = nullptr;
568598
QJSValue *onFrameFinishCallback = nullptr;

0 commit comments

Comments
 (0)