Running Lua Script on the main GUI thread
Switched running the LUA script from the emuThread to the main window / main GUI thread... Should have just done this from the start, this makes things much simpler to implement, and will make future planned GUI functions much easier to add.
This commit is contained in:
parent
a312d4d2e7
commit
c21d794482
|
@ -442,14 +442,8 @@ void EmuThread::run()
|
||||||
|
|
||||||
handleMessages();
|
handleMessages();
|
||||||
|
|
||||||
LuaConsoleDialog* dialog = emuInstance->getMainWindow()->getLuaDialog();
|
|
||||||
//Lua Script Stuff (-for now happens at the end of each frame regardless of emuStatus)
|
//Lua Script Stuff (-for now happens at the end of each frame regardless of emuStatus)
|
||||||
if (dialog!=nullptr)
|
emit signalLuaUpdate();
|
||||||
{
|
|
||||||
LuaBundle* lua = dialog->getLuaBundle();
|
|
||||||
lua->createLuaState();//Create LuaState if needed
|
|
||||||
lua->luaUpdate(); //"_Update()" gets called in current lua script
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file = Platform::OpenLocalFile("rtc.bin", Platform::FileMode::Write);
|
file = Platform::OpenLocalFile("rtc.bin", Platform::FileMode::Write);
|
||||||
|
|
|
@ -107,12 +107,6 @@ public:
|
||||||
void deinitContext();
|
void deinitContext();
|
||||||
void updateVideoSettings() { videoSettingsDirty = true; }
|
void updateVideoSettings() { videoSettingsDirty = true; }
|
||||||
|
|
||||||
void onLuaPrint(const QString&);
|
|
||||||
void onLuaClearConsole();
|
|
||||||
void onLuaLoadState(const QString&);
|
|
||||||
void onLuaSaveState(const QString&);
|
|
||||||
void onLuaLayoutChange();
|
|
||||||
|
|
||||||
int FrontBuffer = 0;
|
int FrontBuffer = 0;
|
||||||
QMutex FrontBufferLock;
|
QMutex FrontBufferLock;
|
||||||
|
|
||||||
|
@ -136,10 +130,7 @@ signals:
|
||||||
|
|
||||||
void syncVolumeLevel();
|
void syncVolumeLevel();
|
||||||
|
|
||||||
void signalLuaPrint(const QString&);
|
void signalLuaUpdate();
|
||||||
void signalLuaClearConsole();
|
|
||||||
void signalLuaSaveState(const QString&);
|
|
||||||
void signalLuaLoadState(const QString&);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleMessages();
|
void handleMessages();
|
||||||
|
|
|
@ -12,34 +12,6 @@
|
||||||
#include <NDS_Header.h>
|
#include <NDS_Header.h>
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
//EmuThread Signals
|
|
||||||
void EmuThread::onLuaPrint(const QString& string)
|
|
||||||
{
|
|
||||||
emit signalLuaPrint(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmuThread::onLuaClearConsole()
|
|
||||||
{
|
|
||||||
emit signalLuaClearConsole();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmuThread::onLuaLoadState(const QString& string)
|
|
||||||
{
|
|
||||||
emit signalLuaLoadState(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
void EmuThread::onLuaLayoutChange()
|
|
||||||
{
|
|
||||||
//TODO:
|
|
||||||
//emit screenLayoutChange();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void EmuThread::onLuaSaveState(const QString& string)
|
|
||||||
{
|
|
||||||
emit signalLuaSaveState(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
LuaBundle::LuaBundle(LuaConsoleDialog* dialog, EmuInstance* inst)
|
LuaBundle::LuaBundle(LuaConsoleDialog* dialog, EmuInstance* inst)
|
||||||
{
|
{
|
||||||
|
@ -74,8 +46,6 @@ LuaConsoleDialog::LuaConsoleDialog(QWidget* parent) : QDialog(parent)
|
||||||
connect(buttonOpenScript,&QPushButton::clicked,this,&LuaConsoleDialog::onOpenScript);
|
connect(buttonOpenScript,&QPushButton::clicked,this,&LuaConsoleDialog::onOpenScript);
|
||||||
connect(buttonStartStop,&QPushButton::clicked,this,&LuaConsoleDialog::onStop);
|
connect(buttonStartStop,&QPushButton::clicked,this,&LuaConsoleDialog::onStop);
|
||||||
connect(buttonPausePlay,&QPushButton::clicked,this,&LuaConsoleDialog::onPausePlay);
|
connect(buttonPausePlay,&QPushButton::clicked,this,&LuaConsoleDialog::onPausePlay);
|
||||||
connect(bundle->getEmuThread(),&EmuThread::signalLuaPrint,console,&LuaConsole::onGetText);
|
|
||||||
connect(bundle->getEmuThread(),&EmuThread::signalLuaClearConsole,console,&LuaConsole::onClear);
|
|
||||||
this->setWindowTitle("Lua Script");
|
this->setWindowTitle("Lua Script");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +77,21 @@ void LuaConsole::onGetText(const QString& string)
|
||||||
bar->setValue(bar->maximum());
|
bar->setValue(bar->maximum());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuaBundle::printText(QString string)
|
||||||
|
{
|
||||||
|
this->luaDialog->console->onGetText(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaConsoleDialog::onLuaSaveState(QString string)
|
||||||
|
{
|
||||||
|
emit signalLuaSaveState(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaConsoleDialog::onLuaLoadState(QString string)
|
||||||
|
{
|
||||||
|
emit signalLuaLoadState(string);
|
||||||
|
}
|
||||||
|
|
||||||
void LuaConsole::onClear()
|
void LuaConsole::onClear()
|
||||||
{
|
{
|
||||||
this->clear();
|
this->clear();
|
||||||
|
@ -160,7 +145,7 @@ void LuaBundle::createLuaState()
|
||||||
}
|
}
|
||||||
else //Error loading script
|
else //Error loading script
|
||||||
{
|
{
|
||||||
emuThread->onLuaPrint(lua_tostring(L,-1));
|
printText(lua_tostring(L,-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,20 +160,26 @@ void LuaConsoleDialog::onPausePlay()
|
||||||
bundle->flagPause = !bundle->flagPause;
|
bundle->flagPause = !bundle->flagPause;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuaConsoleDialog::onLuaUpdate()
|
||||||
|
{
|
||||||
|
bundle->createLuaState();
|
||||||
|
bundle->luaUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
//Gets Called once a frame
|
//Gets Called once a frame
|
||||||
void LuaBundle::luaUpdate()
|
void LuaBundle::luaUpdate()
|
||||||
{
|
{
|
||||||
if (!luaState || flagPause) return;
|
if (!luaState || flagPause) return;
|
||||||
if (lua_getglobal(luaState,"_Update")!=LUA_TFUNCTION)
|
if (lua_getglobal(luaState,"_Update")!=LUA_TFUNCTION)
|
||||||
{
|
{
|
||||||
emuThread->onLuaPrint("No \"_Update\" Function found, pausing script...");
|
printText("No \"_Update\" Function found, pausing script...");
|
||||||
flagPause = true;
|
flagPause = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (lua_pcall(luaState,0,0,0)!=0)
|
if (lua_pcall(luaState,0,0,0)!=0)
|
||||||
{
|
{
|
||||||
//Handel Errors
|
//Handel Errors
|
||||||
emuThread->onLuaPrint(lua_tostring(luaState,-1));
|
printText(lua_tostring(luaState,-1));
|
||||||
luaState = nullptr;
|
luaState = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,7 +237,7 @@ int lua_MelonPrint(lua_State* L)
|
||||||
{
|
{
|
||||||
LuaBundle* bundle = get_bundle(L);
|
LuaBundle* bundle = get_bundle(L);
|
||||||
const char* string = luaL_checkstring(L,1);
|
const char* string = luaL_checkstring(L,1);
|
||||||
bundle->getEmuThread()->onLuaPrint((QString)string);
|
bundle->printText((QString)string);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
AddLuaFunction(lua_MelonPrint,print);
|
AddLuaFunction(lua_MelonPrint,print);
|
||||||
|
@ -254,7 +245,7 @@ AddLuaFunction(lua_MelonPrint,print);
|
||||||
int lua_MelonClear(lua_State* L)
|
int lua_MelonClear(lua_State* L)
|
||||||
{
|
{
|
||||||
LuaBundle* bundle = get_bundle(L);
|
LuaBundle* bundle = get_bundle(L);
|
||||||
bundle->getEmuThread()->onLuaClearConsole();
|
bundle->getluaDialog()->console->clear();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
AddLuaFunction(lua_MelonClear,MelonClear);
|
AddLuaFunction(lua_MelonClear,MelonClear);
|
||||||
|
@ -378,7 +369,7 @@ int Lua_StateSave(lua_State* L)
|
||||||
{
|
{
|
||||||
LuaBundle* bundle = get_bundle(L);
|
LuaBundle* bundle = get_bundle(L);
|
||||||
const char* filename = luaL_checkstring(L,1);
|
const char* filename = luaL_checkstring(L,1);
|
||||||
bundle->getEmuThread()->onLuaSaveState((QString)filename);
|
bundle->getluaDialog()->onLuaSaveState((QString)filename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
AddLuaFunction(Lua_StateSave,StateSave);
|
AddLuaFunction(Lua_StateSave,StateSave);
|
||||||
|
@ -387,7 +378,8 @@ int Lua_StateLoad(lua_State* L)
|
||||||
{
|
{
|
||||||
LuaBundle* bundle = get_bundle(L);
|
LuaBundle* bundle = get_bundle(L);
|
||||||
const char* filename = luaL_checkstring(L,1);
|
const char* filename = luaL_checkstring(L,1);
|
||||||
bundle->getEmuThread()->onLuaLoadState((QString)filename);
|
|
||||||
|
bundle->getluaDialog()->onLuaLoadState((QString)filename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
AddLuaFunction(Lua_StateLoad,StateLoad);
|
AddLuaFunction(Lua_StateLoad,StateLoad);
|
||||||
|
|
|
@ -31,17 +31,22 @@ public:
|
||||||
QPushButton* buttonPausePlay;
|
QPushButton* buttonPausePlay;
|
||||||
QScrollBar* bar;
|
QScrollBar* bar;
|
||||||
bool flagClosed;
|
bool flagClosed;
|
||||||
|
void onLuaSaveState(QString);
|
||||||
|
void onLuaLoadState(QString);
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event) override;
|
void closeEvent(QCloseEvent *event) override;
|
||||||
LuaBundle* bundle;
|
LuaBundle* bundle;
|
||||||
signals:
|
signals:
|
||||||
void signalNewLua();
|
void signalNewLua();
|
||||||
void signalClosing();
|
void signalClosing();
|
||||||
|
void signalLuaSaveState(const QString&);
|
||||||
|
void signalLuaLoadState(const QString&);
|
||||||
public slots:
|
public slots:
|
||||||
//void onStartStop();
|
//void onStartStop();
|
||||||
void onOpenScript();
|
void onOpenScript();
|
||||||
void onStop();
|
void onStop();
|
||||||
void onPausePlay();
|
void onPausePlay();
|
||||||
|
void onLuaUpdate();
|
||||||
};
|
};
|
||||||
|
|
||||||
//Based on ScreenLayout::GetScreenTransforms
|
//Based on ScreenLayout::GetScreenTransforms
|
||||||
|
@ -95,6 +100,8 @@ public:
|
||||||
lua_State* getLuaState(){return luaState;};
|
lua_State* getLuaState(){return luaState;};
|
||||||
EmuThread* getEmuThread(){return emuThread;};
|
EmuThread* getEmuThread(){return emuThread;};
|
||||||
EmuInstance* getEmuInstance(){return emuInstance;};
|
EmuInstance* getEmuInstance(){return emuInstance;};
|
||||||
|
LuaConsoleDialog* getluaDialog(){return luaDialog;};
|
||||||
|
void printText(QString string);
|
||||||
void createLuaState();
|
void createLuaState();
|
||||||
void luaUpdate();
|
void luaUpdate();
|
||||||
bool flagPause = false;
|
bool flagPause = false;
|
||||||
|
|
|
@ -1689,8 +1689,9 @@ void MainWindow::onOpenLuaScript()
|
||||||
return;
|
return;
|
||||||
luaDialog = new LuaConsoleDialog(this);
|
luaDialog = new LuaConsoleDialog(this);
|
||||||
luaDialog->show();
|
luaDialog->show();
|
||||||
connect(emuThread,&EmuThread::signalLuaSaveState,this,&MainWindow::onLuaSaveState);
|
connect(emuThread,&EmuThread::signalLuaUpdate,luaDialog,&LuaConsoleDialog::onLuaUpdate);
|
||||||
connect(emuThread,&EmuThread::signalLuaLoadState,this,&MainWindow::onLuaLoadState);
|
connect(luaDialog,&LuaConsoleDialog::signalLuaSaveState,this,&MainWindow::onLuaSaveState);
|
||||||
|
connect(luaDialog,&LuaConsoleDialog::signalLuaLoadState,this,&MainWindow::onLuaLoadState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onEnableCheats(bool checked)
|
void MainWindow::onEnableCheats(bool checked)
|
||||||
|
|
Loading…
Reference in New Issue