Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore GRPC #90

Merged
merged 7 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _ui(new Ui::MainW
this->_recentFiles = new RecentFiles(this, this->_ui->menuRecent, this->_ui->actionClearRecentMenu);

_ui->mdiArea->setBackground(QImage(":/banner.png"));
connect(_ui->mdiArea, &QMdiArea::subWindowActivated, this, &MainWindow::MDIWindowChanged);
connect(_ui->menuWindow, &QMenu::aboutToShow, this, &MainWindow::updateWindowMenu);

auto settingsButton = static_cast<QToolButton *>(_ui->mainToolBar->widgetForAction(_ui->actionSettings));
settingsButton->setPopupMode(QToolButton::ToolButtonPopupMode::MenuButtonPopup);
settingsButton->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon);
_ui->actionSettings->setMenu(_ui->menuChangeGameSettings);

#ifdef RGM_SERVER_ENABLED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're linking in all the code regardless of whether you intend to use it, this could as well be a runtime check.

Also, we're leaking that pluginServer ref. It should probably be a unique_ptr owned by this class (can be left null when disabled).

Copy link
Contributor Author

@RobertBColton RobertBColton Mar 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting making it a dll? Yeah that's how Qt Creator has its own plugin interface, I just wasn't ready to set it up yet.

And no, we're not, Qt has its own ownership policy. The server plugin reference is owned by the main window. This is because the server plugin inherits from my generic RGM plugin abstraction which itself is based on QObject. All RGM plugins are informed of the main window during construction in the current implementation.

explicit RGMPlugin(MainWindow &mainWindow);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm just suggesting being consistent about whether we're eliminating code at compile time or branching over it at runtime. My complaint above is related.

I am checking the define RGM_SERVER_ENABLED in MainWindow.cpp which calls this constructor.

You are building an entire unused class into RGM in this case. I suggest either making it a runtime check (e.g, a flag), or removing the class from the codegen.

Copy link
Contributor Author

@RobertBColton RobertBColton Mar 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which class is the one you are saying is unused? Are you saying RGMPlugin is unused or ServerPlugin is unused? The former is clearly true, but the latter is not always true. I am in fact filtering out the ServerPlugin class entirely in both the pro qmake and the CMakeLists.
https://github.com/enigma-dev/RadialGM/pull/90/files#diff-af3b638bc2a3e6c650974192a53c7291R162-R166
https://github.com/enigma-dev/RadialGM/pull/90/files#diff-bad885b9516edcb9eac2d0c8c57a7ebdR33-R40

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if you remove the #if from just MainWindow, it will generate link errors because the Qt project file excludes the class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, assuming you haven't uncommented rgm_enable_grpc_server in the pro or CMakeLists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit awkward, but okay. Proceed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly me though I forgot to wrap the include in the main window.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok though, as I said later we'll move plugins to dlls.

RGMPlugin *pluginServer = new ServerPlugin(*this);
auto outputTextBrowser = this->_ui->outputTextBrowser;
connect(pluginServer, &RGMPlugin::LogOutput, outputTextBrowser, &QTextBrowser::append);
Expand All @@ -145,8 +147,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _ui(new Ui::MainW
connect(_ui->actionRun, &QAction::triggered, pluginServer, &RGMPlugin::Run);
connect(_ui->actionDebug, &QAction::triggered, pluginServer, &RGMPlugin::Debug);
connect(_ui->actionCreateExecutable, &QAction::triggered, pluginServer, &RGMPlugin::CreateExecutable);

connect(_ui->mdiArea, &QMdiArea::subWindowActivated, this, &MainWindow::MDIWindowChanged);
#endif

openNewProject();
}
Expand Down
25 changes: 11 additions & 14 deletions Plugins/ServerPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ void CompilerClient::UpdateLoop() {
}

ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) {
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't seem to be checking the new macros you created. This code's just always uncommented. Are you just relying on it not being called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am checking the define RGM_SERVER_ENABLED in MainWindow.cpp which calls this constructor. The plugin interface I designed was meant to be pluggable into RGM, so fundies kind of went commenting it out in the wrong place.


FIXME: gRPC currently causes infinite hang on linux and segfault on MinGW
disabling until fixed. Uncomment all methods below when fixed.

// create a new child process for us to launch an emake server
process = new QProcess(this);

Expand All @@ -255,14 +250,15 @@ ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) {
const QDir dir(path);
QDir::Filters filters = QDir::Filter::Executable | QDir::Filter::Files;
// we use a wildcard because we want it to find emake.exe on Windows
auto entryList = dir.entryInfoList(QStringList("emake*"), filters, QDir::SortFlag::NoSort);
auto entryList = dir.entryInfoList(QStringList({"emake","emake.exe"}), filters, QDir::SortFlag::NoSort);
if (!entryList.empty()) {
emakeFileInfo = entryList.first();
break;
}
}

// use the closest matching emake file we found and launch it in a child process
qDebug() << emakeFileInfo.fileName();
process->setWorkingDirectory(emakeFileInfo.absolutePath());
QString program = emakeFileInfo.fileName();
QStringList arguments;
Expand All @@ -287,27 +283,28 @@ ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) {
// without us needing any threading or blocking the main thread
QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, compilerClient, &CompilerClient::UpdateLoop);
timer->start();
// timer delay larger than one so we don't hog the CPU core
timer->start(1);

// update initial keyword set and systems
compilerClient->GetResources();
compilerClient->GetSystems();
*/

}

ServerPlugin::~ServerPlugin() { /*process->close();*/ }
ServerPlugin::~ServerPlugin() { process->close(); }

void ServerPlugin::Run() { /*compilerClient->CompileBuffer(mainWindow.Game(), CompileRequest::RUN);*/ };
void ServerPlugin::Run() { compilerClient->CompileBuffer(mainWindow.Game(), CompileRequest::RUN); };

void ServerPlugin::Debug() { /*compilerClient->CompileBuffer(mainWindow.Game(), CompileRequest::DEBUG);*/ };
void ServerPlugin::Debug() { compilerClient->CompileBuffer(mainWindow.Game(), CompileRequest::DEBUG); };

void ServerPlugin::CreateExecutable() {
/*const QString& fileName =
const QString& fileName =
QFileDialog::getSaveFileName(&mainWindow, tr("Create Executable"), "", tr("Executable (*.exe);;All Files (*)"));
if (!fileName.isEmpty())
compilerClient->CompileBuffer(mainWindow.Game(), CompileRequest::COMPILE, fileName.toStdString());*/
compilerClient->CompileBuffer(mainWindow.Game(), CompileRequest::COMPILE, fileName.toStdString());
};

void ServerPlugin::SetCurrentConfig(const resources::Settings& settings) {
/*compilerClient->SetCurrentConfig(settings);*/
compilerClient->SetCurrentConfig(settings);
};
13 changes: 10 additions & 3 deletions RadialGM.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ VERSION = 0.0.0.0
QMAKE_TARGET_COMPANY = ENIGMA Dev Team
QMAKE_TARGET_PRODUCT = RadialGM IDE
QMAKE_TARGET_DESCRIPTION = ENIGMA Development Environment
QMAKE_TARGET_COPYRIGHT = "Copyright \\251 2007-2018 ENIGMA Dev Team"
QMAKE_TARGET_COPYRIGHT = "Copyright \\251 2007-2020 ENIGMA Dev Team"

# Uncomment if you want QPlainTextEdit used in place of QScintilla
CONFIG += rgm_disable_syntaxhighlight
Expand All @@ -30,6 +30,15 @@ rgm_disable_syntaxhighlight {
CONFIG += qscintilla2
}

# Comment out if you do not want the GRPC plugin
#CONFIG += rgm_enable_grpc_server

rgm_enable_grpc_server {
DEFINES += RGM_SERVER_ENABLED
SOURCES += Plugins/ServerPlugin.cpp
HEADERS += Plugins/ServerPlugin.h
}

# we do this even in release mode for "Editor Diagnostics"
DEFINES += QT_MESSAGELOGCONTEXT

Expand Down Expand Up @@ -92,7 +101,6 @@ SOURCES += \
Models/ImmediateMapper.cpp \
Components/Utility.cpp \
Plugins/RGMPlugin.cpp \
Plugins/ServerPlugin.cpp \
Components/RecentFiles.cpp \
Editors/CodeEditor.cpp \
Editors/ScriptEditor.cpp \
Expand Down Expand Up @@ -137,7 +145,6 @@ HEADERS += \
Models/ImmediateMapper.h \
Components/Utility.h \
Plugins/RGMPlugin.h \
Plugins/ServerPlugin.h \
Components/RecentFiles.h \
Widgets/SpriteSubimageListView.h \
Widgets/SpriteView.h \
Expand Down