Qt JS engine in work.

This commit is contained in:
harry 2024-01-15 05:34:13 -05:00
parent ecda95ed70
commit e51a748a05
4 changed files with 50 additions and 6 deletions

View File

@ -4597,9 +4597,9 @@ void consoleWin_t::emuFrameFinish(void)
//printf("EMU Frame Finish\n");
#ifdef __FCEU_QSCRIPT_ENABLE__
QtScriptManager::getInstance()->frameFinishedUpdate();
#endif
//#ifdef __FCEU_QSCRIPT_ENABLE__
// QtScriptManager::getInstance()->frameFinishedUpdate();
//#endif
transferVideoBuffer();
}

View File

@ -240,6 +240,8 @@ int QtScriptInstance::configEngine()
engine->globalObject().setProperty("gui", guiObject);
QtScriptManager::getInstance()->removeFrameFinishedConnection(this);
onFrameFinishCallback = QJSValue();
onScriptStopCallback = QJSValue();
@ -277,6 +279,10 @@ int QtScriptInstance::loadScriptFile( QString filepath )
onFrameFinishCallback = engine->globalObject().property("onFrameFinish");
onScriptStopCallback = engine->globalObject().property("onScriptStop");
if (onFrameFinishCallback.isCallable())
{
QtScriptManager::getInstance()->addFrameFinishedConnection(this);
}
return 0;
}
//----------------------------------------------------
@ -513,12 +519,45 @@ void QtScriptManager::removeScriptInstance(QtScriptInstance* script)
it++;
}
}
removeFrameFinishedConnection(script);
}
//----------------------------------------------------
void QtScriptManager::addFrameFinishedConnection(QtScriptInstance* script)
{
if (frameFinishConnectList.size() == 0)
{
connect(consoleWindow->emulatorThread, SIGNAL(frameFinished(void)), this, SLOT(frameFinishedUpdate(void)), Qt::BlockingQueuedConnection);
}
frameFinishConnectList.push_back(script);
}
//----------------------------------------------------
void QtScriptManager::removeFrameFinishedConnection(QtScriptInstance* script)
{
auto it = frameFinishConnectList.begin();
while (it != frameFinishConnectList.end())
{
if (*it == script)
{
it = frameFinishConnectList.erase(it);
}
else
{
it++;
}
}
if (frameFinishConnectList.size() == 0)
{
consoleWindow->emulatorThread->disconnect( SIGNAL(frameFinished(void)), this, SLOT(frameFinishedUpdate(void)));
}
}
//----------------------------------------------------
void QtScriptManager::frameFinishedUpdate()
{
FCEU_WRAPPER_LOCK();
for (auto script : scriptList)
for (auto script : frameFinishConnectList)
{
script->onFrameFinish();
}

View File

@ -113,12 +113,17 @@ public:
void addScriptInstance(QtScriptInstance* script);
void removeScriptInstance(QtScriptInstance* script);
void addFrameFinishedConnection(QtScriptInstance* script);
void removeFrameFinishedConnection(QtScriptInstance* script);
private:
static QtScriptManager* _instance;
QList<QtScriptInstance*> scriptList;
QList<QtScriptInstance*> frameFinishConnectList;
FCEU::timeStampRecord lastFrameUpdate;
int frameFinishedConnectCount = 0;
public slots:
void frameFinishedUpdate();
};

View File

@ -1481,12 +1481,12 @@ int fceuWrapperUpdate( void )
hexEditorUpdateMemoryValues();
fceuWrapperUnLock();
if ( consoleWindow )
{
consoleWindow->emulatorThread->signalFrameFinished();
}
fceuWrapperUnLock();
emulatorHasMutex = 0;
#ifdef __FCEU_PROFILER_ENABLE__