Qt: Allow passing multiple games on command line for multiplayer (closes #3061)

This commit is contained in:
Vicki Pfau 2025-01-10 02:46:58 -08:00
parent 77e50f7aec
commit f58f9746d7
6 changed files with 34 additions and 2 deletions

View File

@ -47,6 +47,7 @@ Misc:
- Qt: Pass logging context through to video proxy thread (fixes mgba.io/i/3095)
- Qt: Show maker code and game version in ROM info
- Qt: Show a dummy shader settings tab if shaders aren't supported
- Qt: Allow passing multiple games on command line for multiplayer (closes mgba.io/i/3061)
- Res: Port NSO-gba-colors shader (closes mgba.io/i/2834)
- Scripting: Add `callbacks:oneshot` for single-call callbacks
- Updater: Fix rewriting folders and files on Windows (fixes mgba.io/i/3384)

View File

@ -196,6 +196,14 @@ ConfigController::ConfigController(QObject* parent)
m_subparsers[1].extraOptions = nullptr;
m_subparsers[1].longOptions = s_frontendOptions;
m_subparsers[1].opts = this;
m_subparsers[1].handleExtraArg = [](struct mSubParser* parser, const char* arg) {
ConfigController* self = static_cast<ConfigController*>(parser->opts);
if (self->m_fnames.count() >= MAX_GBAS) {
return false;
}
self->m_fnames.append(QString::fromUtf8(arg));
return true;
};
}
ConfigController::~ConfigController() {

View File

@ -102,6 +102,7 @@ public:
const mArguments* args() const { return &m_args; }
const mGraphicsOpts* graphicsOpts() const { return &m_graphicsOpts; }
QStringList fileNames() const { return m_fnames; }
void usage(const char* arg0) const;
static const QString& configDir();
@ -129,6 +130,7 @@ private:
mArguments m_args{};
mGraphicsOpts m_graphicsOpts{};
std::array<mSubParser, 2> m_subparsers;
QStringList m_fnames;
bool m_parsed = false;
QHash<QString, QVariant> m_argvOptions;

View File

@ -397,6 +397,26 @@ void GBAApp::finishJob(qint64 jobId) {
m_workerJobCallbacks.remove(jobId);
}
void GBAApp::initMultiplayer() {
QStringList fnames = m_configController->fileNames();
if (fnames.count() < 2) {
return;
}
Window* w = m_windows[0];
for (const auto& fname : fnames) {
if (!w) {
w = newWindow();
}
if (!w) {
break;
}
CoreController* core = m_manager.loadGame(fname);
w->setController(core, fname);
w = nullptr;
}
}
GBAApp::WorkerJob::WorkerJob(qint64 id, std::function<void ()>&& job, GBAApp* owner)
: m_id(id)
, m_job(std::move(job))

View File

@ -82,6 +82,8 @@ public:
ApplicationUpdater* updater() { return &m_updater; }
QString invokeOnExit() { return m_invokeOnExit; }
void initMultiplayer();
public slots:
void restartForUpdate();
Window* newWindow();

View File

@ -131,10 +131,9 @@ int main(int argc, char* argv[]) {
}
Window* w = application.newWindow();
w->loadConfig();
w->argumentsPassed();
w->show();
application.initMultiplayer();
int ret = application.exec();
if (ret != 0) {