From 751a0bb3b2804eab8948e7a4b4ec21f2c86868a2 Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Mon, 25 Oct 2021 16:31:27 -0700 Subject: [PATCH 01/22] Consolidated (almost) all parameters in "main.cpp". --- interface/src/main.cpp | 105 ++++++++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 34 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 4e338a629b1..178e9c8cfc6 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -66,60 +66,80 @@ int main(int argc, const char* argv[]) { setupHifiApplication(BuildInfo::INTERFACE_NAME); - QStringList arguments; + /*QStringList arguments; for (int i = 0; i < argc; ++i) { arguments << argv[i]; - } + }*/ + + // grep -E 'getCmdOption|QCommandLineOption|cmdOptionExists' 'interface/src/Application.cpp' QCommandLineParser parser; parser.setApplicationDescription("Vircadia"); - QCommandLineOption versionOption = parser.addVersionOption(); QCommandLineOption helpOption = parser.addHelpOption(); + QCommandLineOption versionOption = parser.addVersionOption(); - QCommandLineOption urlOption("url", "", "value"); - QCommandLineOption noLauncherOption("no-launcher", "Do not execute the launcher"); - QCommandLineOption noUpdaterOption("no-updater", "Do not show auto-updater"); - QCommandLineOption checkMinSpecOption("checkMinSpec", "Check if machine meets minimum specifications"); - QCommandLineOption runServerOption("runServer", "Whether to run the server"); - QCommandLineOption serverContentPathOption("serverContentPath", "Where to find server content ", "serverContentPath"); - QCommandLineOption allowMultipleInstancesOption("allowMultipleInstances", "Allow multiple instances to run"); - QCommandLineOption overrideAppLocalDataPathOption("cache", "set test cache ", "dir"); + QCommandLineOption urlOption("url", "Start at specified URL location.", "value"); + QCommandLineOption protocolVersionOption("protocolVersion", "Displays the protocol version."); + QCommandLineOption noUpdaterOption("no-updater", "Do not show auto-updater."); + QCommandLineOption checkMinSpecOption("checkMinSpec", "Check if machine meets minimum specifications."); + QCommandLineOption runServerOption("runServer", "Whether to run the server."); + QCommandLineOption listenPortOption("listenPort", "Port to listen on."); + QCommandLineOption serverContentPathOption("serverContentPath", "Where to find server content .", "serverContentPath"); // This data type will not be familiar to users. + QCommandLineOption overrideAppLocalDataPathOption("cache", "set test cache .", "dir"); + //QCommandLineOption scriptsOption("scripts", "Set path for defaultScripts.", "dir"); // Use this once SCRIPTS_SWITCH is removed. + QCommandLineOption allowMultipleInstancesOption("allowMultipleInstances", "Allow multiple instances to run."); + QCommandLineOption displaysOption("display", "Preferred display.", "displays"); + QCommandLineOption disableDisplaysOption("disable-displays", "Displays to disable."); + QCommandLineOption disableInputsOption("disable-inputs", "Inputs to disable."); + QCommandLineOption suppressSettingsResetOption("suppress-settings-reset", "Suppress the prompt to reset interface settings."); + QCommandLineOption oculusStoreOption("oculus-store", "Let the Oculus plugin know if interface was run from the Oculus Store."); + QCommandLineOption standaloneOption("standalone", "Emulate a standalone device."); + QCommandLineOption disableWatchdogOption("disableWatchdog", "Disable the watchdog thread. The interface will crash on deadlocks."); + QCommandLineOption systemCursorOption("system-cursor", "Needs clarification!"); + QCommandLineOption concurrentDownloadsOption("concurrent-downloads", "Maximum concurrent resource downloads. Default is 16, except for Android where it is 4."); + QCommandLineOption avatarURLOption("avatarURL", "Override the avatar U.R.L."); + QCommandLineOption replaceAvatarURLOption("replace-avatar-url", "Replaces the avatar U.R.L. When used with --avatarURL, this takes precedence."); + QCommandLineOption setBookmarkOption("setBookmark", "Set bookmark as key=value pair. Including the '=' symbol in either string is unsupported.", "string"); + QCommandLineOption forceCrashReportingOption("forceCrashReporting", "Force crash reporting to initialize."); + // The documented "--disable-lod" does not seem to exist. + // Below are undocumented. + QCommandLineOption noLauncherOption("no-launcher", "Do not execute the launcher."); QCommandLineOption overrideScriptsPathOption(SCRIPTS_SWITCH, "set scripts ", "path"); - QCommandLineOption responseTokensOption("tokens", "set response tokens ", "json"); - QCommandLineOption displayNameOption("displayName", "set user display name ", "string"); - QCommandLineOption setBookmarkOption("setBookmark", "set bookmark key=value pair", "string"); - QCommandLineOption defaultScriptOverrideOption("defaultScriptsOverride", "override defaultsScripts.js", "string"); - QCommandLineOption forceCrashReportingOption("forceCrashReporting", "Force crash reporting to initialize"); + QCommandLineOption responseTokensOption("tokens", "set response tokens .", "json"); + QCommandLineOption displayNameOption("displayName", "set user display name .", "string"); + QCommandLineOption defaultScriptOverrideOption("defaultScriptsOverride", "override defaultsScripts.js.", "string"); + // "--qmljsdebugger", which appears in output from "--help-all". parser.addOption(urlOption); - parser.addOption(noLauncherOption); + parser.addOption(protocolVersionOption); parser.addOption(noUpdaterOption); parser.addOption(checkMinSpecOption); parser.addOption(runServerOption); + parser.addOption(listenPortOption); parser.addOption(serverContentPathOption); parser.addOption(overrideAppLocalDataPathOption); - parser.addOption(overrideScriptsPathOption); + //parser.addOption(scriptsOption); // Use this once SCRIPTS_SWITCH is removed. parser.addOption(allowMultipleInstancesOption); + parser.addOption(displaysOption); + parser.addOption(disableDisplaysOption); + parser.addOption(disableInputsOption); + parser.addOption(suppressSettingsResetOption); + parser.addOption(oculusStoreOption); + parser.addOption(standaloneOption); + parser.addOption(disableWatchdogOption); + parser.addOption(systemCursorOption); + parser.addOption(concurrentDownloadsOption); + parser.addOption(avatarURLOption); + parser.addOption(replaceAvatarURLOption); + parser.addOption(setBookmarkOption); + parser.addOption(forceCrashReportingOption); + parser.addOption(noLauncherOption); + parser.addOption(overrideScriptsPathOption); // Remove this along with SCRIPTS_SWITCH. parser.addOption(responseTokensOption); parser.addOption(displayNameOption); - parser.addOption(setBookmarkOption); parser.addOption(defaultScriptOverrideOption); - parser.addOption(forceCrashReportingOption); - - if (!parser.parse(arguments)) { - std::cout << parser.errorText().toStdString() << std::endl; // Avoid Qt log spam - } - - if (parser.isSet(versionOption)) { - parser.showVersion(); - Q_UNREACHABLE(); - } - if (parser.isSet(helpOption)) { - QCoreApplication mockApp(argc, const_cast(argv)); // required for call to showHelp() - parser.showHelp(); - Q_UNREACHABLE(); - } + QStringList arguments; QString applicationPath; // A temporary application instance is needed to get the location of the running executable // Tests using high_resolution_clock show that this takes about 30-50 microseconds (on my machine, YMMV) @@ -127,6 +147,10 @@ int main(int argc, const char* argv[]) { // cross-platform implementation. { QCoreApplication tempApp(argc, const_cast(argv)); + + parser.process(QCoreApplication::arguments()); // Must be run after QCoreApplication is initalised. + arguments = parser.positionalArguments(); // Must be run after parser processes arguments. + #ifdef Q_OS_OSX if (QFileInfo::exists(QCoreApplication::applicationDirPath() + "/../../../config.json")) { applicationPath = QCoreApplication::applicationDirPath() + "/../../../"; @@ -137,6 +161,18 @@ int main(int argc, const char* argv[]) { applicationPath = QCoreApplication::applicationDirPath(); #endif } + + // Act on arguments for early termination. + if (parser.isSet(versionOption)) { + parser.showVersion(); + Q_UNREACHABLE(); + } + if (parser.isSet(helpOption)) { + QCoreApplication mockApp(argc, const_cast(argv)); // required for call to showHelp() + parser.showHelp(); + Q_UNREACHABLE(); + } + static const QString APPLICATION_CONFIG_FILENAME = "config.json"; QDir applicationDir(applicationPath); QString configFileName = applicationDir.filePath(APPLICATION_CONFIG_FILENAME); @@ -330,6 +366,7 @@ int main(int argc, const char* argv[]) { // Oculus initialization MUST PRECEDE OpenGL context creation. // The nature of the Application constructor means this has to be either here, // or in the main window ctor, before GL startup. + //Application::initPlugins(arguments); Application::initPlugins(arguments); #ifdef Q_OS_WIN From 8f338208b472ca69fdc338ecc907a799a50c4f05 Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Mon, 25 Oct 2021 17:33:22 -0700 Subject: [PATCH 02/22] Made lines shorter. --- interface/src/main.cpp | 150 +++++++++++++++++++++++++++++++++-------- 1 file changed, 122 insertions(+), 28 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 178e9c8cfc6..7dc7712f00d 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -78,36 +78,130 @@ int main(int argc, const char* argv[]) { QCommandLineOption helpOption = parser.addHelpOption(); QCommandLineOption versionOption = parser.addVersionOption(); - QCommandLineOption urlOption("url", "Start at specified URL location.", "value"); - QCommandLineOption protocolVersionOption("protocolVersion", "Displays the protocol version."); - QCommandLineOption noUpdaterOption("no-updater", "Do not show auto-updater."); - QCommandLineOption checkMinSpecOption("checkMinSpec", "Check if machine meets minimum specifications."); - QCommandLineOption runServerOption("runServer", "Whether to run the server."); - QCommandLineOption listenPortOption("listenPort", "Port to listen on."); - QCommandLineOption serverContentPathOption("serverContentPath", "Where to find server content .", "serverContentPath"); // This data type will not be familiar to users. - QCommandLineOption overrideAppLocalDataPathOption("cache", "set test cache .", "dir"); - //QCommandLineOption scriptsOption("scripts", "Set path for defaultScripts.", "dir"); // Use this once SCRIPTS_SWITCH is removed. - QCommandLineOption allowMultipleInstancesOption("allowMultipleInstances", "Allow multiple instances to run."); - QCommandLineOption displaysOption("display", "Preferred display.", "displays"); - QCommandLineOption disableDisplaysOption("disable-displays", "Displays to disable."); - QCommandLineOption disableInputsOption("disable-inputs", "Inputs to disable."); - QCommandLineOption suppressSettingsResetOption("suppress-settings-reset", "Suppress the prompt to reset interface settings."); - QCommandLineOption oculusStoreOption("oculus-store", "Let the Oculus plugin know if interface was run from the Oculus Store."); - QCommandLineOption standaloneOption("standalone", "Emulate a standalone device."); - QCommandLineOption disableWatchdogOption("disableWatchdog", "Disable the watchdog thread. The interface will crash on deadlocks."); - QCommandLineOption systemCursorOption("system-cursor", "Needs clarification!"); - QCommandLineOption concurrentDownloadsOption("concurrent-downloads", "Maximum concurrent resource downloads. Default is 16, except for Android where it is 4."); - QCommandLineOption avatarURLOption("avatarURL", "Override the avatar U.R.L."); - QCommandLineOption replaceAvatarURLOption("replace-avatar-url", "Replaces the avatar U.R.L. When used with --avatarURL, this takes precedence."); - QCommandLineOption setBookmarkOption("setBookmark", "Set bookmark as key=value pair. Including the '=' symbol in either string is unsupported.", "string"); - QCommandLineOption forceCrashReportingOption("forceCrashReporting", "Force crash reporting to initialize."); + QCommandLineOption urlOption( + "url", + "Start at specified URL location.", + "value" + ); + QCommandLineOption protocolVersionOption( + "protocolVersion", + "Displays the protocol version." + ); + QCommandLineOption noUpdaterOption( + "no-updater", + "Do not show auto-updater." + ); + QCommandLineOption checkMinSpecOption( + "checkMinSpec", + "Check if machine meets minimum specifications." + ); + QCommandLineOption runServerOption( + "runServer", + "Whether to run the server." + ); + QCommandLineOption listenPortOption( + "listenPort", + "Port to listen on." + ); + QCommandLineOption serverContentPathOption( + "serverContentPath", + "Where to find server content .", + "serverContentPath" + ); // This data type will not be familiar to users. + QCommandLineOption overrideAppLocalDataPathOption( + "cache", + "set test cache .", + "dir" + ); + //QCommandLineOption scriptsOption( + // "scripts", + // "Set path for defaultScripts.", + // "dir" + //); // Use this once SCRIPTS_SWITCH is removed. + QCommandLineOption allowMultipleInstancesOption( + "allowMultipleInstances", + "Allow multiple instances to run." + ); + QCommandLineOption displaysOption( + "display", + "Preferred display.", + "displays" + ); + QCommandLineOption disableDisplaysOption( + "disable-displays", + "Displays to disable." + ); + QCommandLineOption disableInputsOption( + "disable-inputs", + "Inputs to disable." + ); + QCommandLineOption suppressSettingsResetOption( + "suppress-settings-reset", + "Suppress the prompt to reset interface settings." + ); + QCommandLineOption oculusStoreOption( + "oculus-store", + "Let the Oculus plugin know if interface was run from the Oculus Store." + ); + QCommandLineOption standaloneOption( + "standalone", + "Emulate a standalone device." + ); + QCommandLineOption disableWatchdogOption( + "disableWatchdog", + "Disable the watchdog thread. The interface will crash on deadlocks." + ); + QCommandLineOption systemCursorOption( + "system-cursor", + "Needs clarification!" + ); + QCommandLineOption concurrentDownloadsOption( + "concurrent-downloads", + "Maximum concurrent resource downloads. Default is 16, except for Android where it is 4." + ); + QCommandLineOption avatarURLOption( + "avatarURL", + "Override the avatar U.R.L." + ); + QCommandLineOption replaceAvatarURLOption( + "replace-avatar-url", + "Replaces the avatar U.R.L. When used with --avatarURL, this takes precedence." + ); + QCommandLineOption setBookmarkOption( + "setBookmark", + "Set bookmark as key=value pair. Including the '=' symbol in either string is unsupported.", + "string" + ); + QCommandLineOption forceCrashReportingOption( + "forceCrashReporting", + "Force crash reporting to initialize." + ); // The documented "--disable-lod" does not seem to exist. // Below are undocumented. - QCommandLineOption noLauncherOption("no-launcher", "Do not execute the launcher."); - QCommandLineOption overrideScriptsPathOption(SCRIPTS_SWITCH, "set scripts ", "path"); - QCommandLineOption responseTokensOption("tokens", "set response tokens .", "json"); - QCommandLineOption displayNameOption("displayName", "set user display name .", "string"); - QCommandLineOption defaultScriptOverrideOption("defaultScriptsOverride", "override defaultsScripts.js.", "string"); + QCommandLineOption noLauncherOption( + "no-launcher", + "Do not execute the launcher." + ); + QCommandLineOption overrideScriptsPathOption( + SCRIPTS_SWITCH, + "set scripts ", + "path" + ); + QCommandLineOption responseTokensOption( + "tokens", + "set response tokens .", + "json" + ); + QCommandLineOption displayNameOption( + "displayName", + "set user display name .", + "string" + ); + QCommandLineOption defaultScriptOverrideOption( + "defaultScriptsOverride", + "override defaultsScripts.js.", + "string" + ); // "--qmljsdebugger", which appears in output from "--help-all". parser.addOption(urlOption); From 9e2958d66847164cd74c815225fb0b42404171ea Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Mon, 25 Oct 2021 17:36:14 -0700 Subject: [PATCH 03/22] Removed unnecessary comments. --- interface/src/main.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 7dc7712f00d..f4f52cc1890 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -66,11 +66,6 @@ int main(int argc, const char* argv[]) { setupHifiApplication(BuildInfo::INTERFACE_NAME); - /*QStringList arguments; - for (int i = 0; i < argc; ++i) { - arguments << argv[i]; - }*/ - // grep -E 'getCmdOption|QCommandLineOption|cmdOptionExists' 'interface/src/Application.cpp' QCommandLineParser parser; @@ -460,7 +455,6 @@ int main(int argc, const char* argv[]) { // Oculus initialization MUST PRECEDE OpenGL context creation. // The nature of the Application constructor means this has to be either here, // or in the main window ctor, before GL startup. - //Application::initPlugins(arguments); Application::initPlugins(arguments); #ifdef Q_OS_WIN From 11c26d0465b21841a4f0d177c3dc2a7ec5b94f6b Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Mon, 25 Oct 2021 18:32:14 -0700 Subject: [PATCH 04/22] Added note of other parameters to fix. --- interface/src/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index f4f52cc1890..fc308fa3277 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -198,6 +198,11 @@ int main(int argc, const char* argv[]) { "string" ); // "--qmljsdebugger", which appears in output from "--help-all". + // Those below are found in this file but have not yet been moved here. + // --traceFile + // --clockSkew + // --ignore-gpu-blacklist + // --suppress-settings-reset parser.addOption(urlOption); parser.addOption(protocolVersionOption); From a31445161aef970b4e06c19da266fccb38a7967f Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Mon, 25 Oct 2021 22:32:47 -0700 Subject: [PATCH 05/22] Probably finished the ones in main. --- interface/src/main.cpp | 58 +++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index fc308fa3277..7a967113c09 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -179,28 +179,40 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption overrideScriptsPathOption( SCRIPTS_SWITCH, - "set scripts ", + "Set scripts ", "path" ); + QCommandLineOption defaultScriptOverrideOption( + "defaultScriptsOverride", + "Override defaultsScripts.js.", + "string" + ); QCommandLineOption responseTokensOption( "tokens", - "set response tokens .", + "Set response tokens .", "json" ); QCommandLineOption displayNameOption( "displayName", - "set user display name .", + "Set user display name .", "string" ); - QCommandLineOption defaultScriptOverrideOption( - "defaultScriptsOverride", - "override defaultsScripts.js.", - "string" + QCommandLineOption traceFileOption( + "traceFile", + "Probably writes a trace to a file?", + "path" + ); + QCommandLineOption traceDurationOption( + "traceDuration", + "Only works if \"--traceFile\" is provided.", + "value" + ); + QCommandLineOption clockSkewOption( + "clockSkew", + "Forces client instance's clock to skew for demonstration purposes." ); // "--qmljsdebugger", which appears in output from "--help-all". - // Those below are found in this file but have not yet been moved here. - // --traceFile - // --clockSkew + // Those below don't seem to be optional. // --ignore-gpu-blacklist // --suppress-settings-reset @@ -232,6 +244,9 @@ int main(int argc, const char* argv[]) { parser.addOption(responseTokensOption); parser.addOption(displayNameOption); parser.addOption(defaultScriptOverrideOption); + parser.addOption(traceFileOption); + parser.addOption(traceDurationOption); + parser.addOption(clockSkewOption); QStringList arguments; QString applicationPath; @@ -305,18 +320,14 @@ int main(int argc, const char* argv[]) { // Early check for --traceFile argument auto tracer = DependencyManager::set(); const char * traceFile = nullptr; - const QString traceFileFlag("--traceFile"); - float traceDuration = 0.0f; - for (int a = 1; a < argc; ++a) { - if (traceFileFlag == argv[a] && argc > a + 1) { - traceFile = argv[a + 1]; - if (argc > a + 2) { - traceDuration = atof(argv[a + 2]); - } - break; + float traceDuration; + if (parser.isSet(traceFileOption)) { + traceFile = parser.value(traceFileOption).toStdString().c_str(); + if (parser.isSet(traceDurationOption)) { + traceDuration = parser.value(traceDurationOption).toFloat(); + } else { + traceDuration = 0.0f; } - } - if (traceFile != nullptr) { tracer->startTracing(); } @@ -449,9 +460,8 @@ int main(int argc, const char* argv[]) { // Debug option to demonstrate that the client's local time does not // need to be in sync with any other network node. This forces clock // skew for the individual client - const char* CLOCK_SKEW = "--clockSkew"; - const char* clockSkewOption = getCmdOption(argc, argv, CLOCK_SKEW); - if (clockSkewOption) { + if (parser.isSet(clockSkewOption)) { + const char* clockSkewOption = parser.value(clockSkewOption).toStdString().c_str(); qint64 clockSkew = atoll(clockSkewOption); usecTimestampNowForceClockSkew(clockSkew); qCDebug(interfaceapp) << "clockSkewOption=" << clockSkewOption << "clockSkew=" << clockSkew; From 187962aa53c0b7df728713a04ea10c896f54ae0f Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Mon, 25 Oct 2021 22:37:13 -0700 Subject: [PATCH 06/22] Fixed spacing. --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 7a967113c09..35a1932697e 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -323,7 +323,7 @@ int main(int argc, const char* argv[]) { float traceDuration; if (parser.isSet(traceFileOption)) { traceFile = parser.value(traceFileOption).toStdString().c_str(); - if (parser.isSet(traceDurationOption)) { + if (parser.isSet(traceDurationOption)) { traceDuration = parser.value(traceDurationOption).toFloat(); } else { traceDuration = 0.0f; From 4c0609eec985b5a59d63d83784aa6f9d8a18d2d3 Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Tue, 26 Oct 2021 06:11:51 -0700 Subject: [PATCH 07/22] Suppose effect. --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 35a1932697e..bd781dcd993 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -148,7 +148,7 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption systemCursorOption( "system-cursor", - "Needs clarification!" + "Probably prevents changing the cursor when application has focus." ); QCommandLineOption concurrentDownloadsOption( "concurrent-downloads", From d08200f60aede42c5be71888a68539c84569a3cd Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Tue, 26 Oct 2021 07:13:59 -0700 Subject: [PATCH 08/22] Fixed handling of clockSkew parameter. --- interface/src/main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index bd781dcd993..4c346af75bb 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -209,7 +209,8 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption clockSkewOption( "clockSkew", - "Forces client instance's clock to skew for demonstration purposes." + "Forces client instance's clock to skew for demonstration purposes.", + "value" ); // "--qmljsdebugger", which appears in output from "--help-all". // Those below don't seem to be optional. @@ -461,10 +462,10 @@ int main(int argc, const char* argv[]) { // need to be in sync with any other network node. This forces clock // skew for the individual client if (parser.isSet(clockSkewOption)) { - const char* clockSkewOption = parser.value(clockSkewOption).toStdString().c_str(); - qint64 clockSkew = atoll(clockSkewOption); + const char* clockSkewValue = parser.value(clockSkewOption).toStdString().c_str(); + qint64 clockSkew = atoll(clockSkewValue); usecTimestampNowForceClockSkew(clockSkew); - qCDebug(interfaceapp) << "clockSkewOption=" << clockSkewOption << "clockSkew=" << clockSkew; + qCDebug(interfaceapp) << "clockSkewOption=" << clockSkewValue << "clockSkew=" << clockSkew; } // Oculus initialization MUST PRECEDE OpenGL context creation. From adf9d2c25f44cd4824d97c19ca008beb5bc68670 Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Tue, 26 Oct 2021 11:58:54 -0700 Subject: [PATCH 09/22] Streamlined handling with single parameter source. --- interface/src/Application.cpp | 203 +++++++++++++++------------------- interface/src/Application.h | 19 +++- interface/src/main.cpp | 63 ++++++++--- 3 files changed, 149 insertions(+), 136 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a235ed1c93a..81d6075b351 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -729,12 +728,9 @@ extern DisplayPluginList getDisplayPlugins(); extern InputPluginList getInputPlugins(); extern void saveInputPluginSettings(const InputPluginList& plugins); -// Parameters used for running tests from teh command line -const QString TEST_SCRIPT_COMMAND{ "--testScript" }; -const QString TEST_QUIT_WHEN_FINISHED_OPTION{ "quitWhenFinished" }; -const QString TEST_RESULTS_LOCATION_COMMAND{ "--testResultsLocation" }; +// Parameters used for running tests from the command line -bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { +bool setupEssentials(int& argc, char** argv, const QCommandLineParser* parser, bool runningMarkerExisted) { const char** constArgv = const_cast(argv); qInstallMessageHandler(messageHandler); @@ -742,6 +738,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { // HRS: I could not figure out how to move these any earlier in startup, so when using this option, be sure to also supply // --allowMultipleInstances auto reportAndQuit = [&](const char* commandSwitch, std::function report) { + // Do something about this: const char* reportfile = getCmdOption(argc, constArgv, commandSwitch); // Reports to the specified file, because stdout is set up to be captured for logging. if (reportfile) { @@ -760,36 +757,23 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { reportAndQuit("--protocolVersion", [&](FILE* fp) { auto version = protocolVersionsSignatureBase64(); fputs(version.toLatin1().data(), fp); - }); - reportAndQuit("--version", [&](FILE* fp) { + }); // This doesn't seem to work. + /*reportAndQuit("--version", [&](FILE* fp) { fputs(BuildInfo::VERSION.toLatin1().data(), fp); - }); + });*/ - const char* portStr = getCmdOption(argc, constArgv, "--listenPort"); - const int listenPort = portStr ? atoi(portStr) : INVALID_PORT; + const int listenPort = parser->isSet("listenPort") ? parser->value("listenPort").toInt() : INVALID_PORT; - static const auto SUPPRESS_SETTINGS_RESET = "--suppress-settings-reset"; - bool suppressPrompt = cmdOptionExists(argc, const_cast(argv), SUPPRESS_SETTINGS_RESET); + bool suppressPrompt = parser->isSet("suppress-settings-reset"); // set the OCULUS_STORE property so the oculus plugin can know if we ran from the Oculus Store - static const auto OCULUS_STORE_ARG = "--oculus-store"; - bool isStore = cmdOptionExists(argc, const_cast(argv), OCULUS_STORE_ARG); - qApp->setProperty(hifi::properties::OCULUS_STORE, isStore); + qApp->setProperty(hifi::properties::OCULUS_STORE, parser->isSet("oculus-store")); // emulate standalone device - static const auto STANDALONE_ARG = "--standalone"; - bool isStandalone = cmdOptionExists(argc, const_cast(argv), STANDALONE_ARG); - qApp->setProperty(hifi::properties::STANDALONE, isStandalone); + qApp->setProperty(hifi::properties::STANDALONE, parser->isSet("standalone")); // Ignore any previous crashes if running from command line with a test script. - bool inTestMode { false }; - for (int i = 0; i < argc; ++i) { - QString parameter(argv[i]); - if (parameter == TEST_SCRIPT_COMMAND) { - inTestMode = true; - break; - } - } + bool inTestMode = parser->isSet("testScript"); bool previousSessionCrashed { false }; if (!inTestMode) { @@ -797,10 +781,8 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { } // get dir to use for cache - static const auto CACHE_SWITCH = "--cache"; - QString cacheDir = getCmdOption(argc, const_cast(argv), CACHE_SWITCH); - if (!cacheDir.isEmpty()) { - qApp->setProperty(hifi::properties::APP_LOCAL_DATA_PATH, cacheDir); + if (parser->isSet("cache")) { + qApp->setProperty(hifi::properties::APP_LOCAL_DATA_PATH, parser->value("cache")); } { @@ -842,7 +824,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { QCoreApplication::addLibraryPath(audioDLLPath); #endif - QString defaultScriptsOverrideOption = getCmdOption(argc, constArgv, "--defaultScriptsOverride"); + QString defaultScriptsOverrideOption = parser->value("defaultScriptsOverride"); DependencyManager::registerInheritance(); DependencyManager::registerInheritance(); @@ -968,7 +950,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { }); - QString setBookmarkValue = getCmdOption(argc, constArgv, "--setBookmark"); + QString setBookmarkValue = parser->value("setBookmark"); if (!setBookmarkValue.isEmpty()) { // Bookmarks are expected to be in a name=url form. // An `=` character in the name or url is unsupported. @@ -1025,14 +1007,19 @@ QSharedPointer getOffscreenUI() { #endif } -Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runningMarkerExisted) : +Application::Application( + int& argc, char** argv, + const QCommandLineParser* parser, + QElapsedTimer& startupTimer, + bool runningMarkerExisted +) : QApplication(argc, argv), _window(new MainWindow(desktop())), _sessionRunTimer(startupTimer), #ifndef Q_OS_ANDROID _logger(new FileLogger(this)), #endif - _previousSessionCrashed(setupEssentials(argc, argv, runningMarkerExisted)), + _previousSessionCrashed(setupEssentials(argc, argv, parser, runningMarkerExisted)), _entitySimulation(new PhysicalEntitySimulation()), _physicsEngine(new PhysicsEngine(Vectors::ZERO)), _entityClipboard(new EntityTree()), @@ -1069,12 +1056,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo LogHandler::getInstance().setupRepeatedMessageFlusher(); { - const QStringList args = arguments(); - - for (int i = 0; i < args.size() - 1; ++i) { - if (args.at(i) == TEST_SCRIPT_COMMAND && (i + 1) < args.size()) { - QString testScriptPath = args.at(i + 1); - + if (parser->isSet("testScript")) { + QString testScriptPath = parser->value("testScript"); // If the URL scheme is http(s) or ftp, then use as is, else - treat it as a local file // This is done so as not break previous command line scripts if (testScriptPath.left(HIFI_URL_SCHEME_HTTP.length()) == HIFI_URL_SCHEME_HTTP || @@ -1085,20 +1068,20 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo setProperty(hifi::properties::TEST, QUrl::fromLocalFile(testScriptPath)); } - // quite when finished parameter must directly follow the test script - if ((i + 2) < args.size() && args.at(i + 2) == TEST_QUIT_WHEN_FINISHED_OPTION) { + if (parser->isSet("quitWhenFinished")) { quitWhenFinished = true; } - } else if (args.at(i) == TEST_RESULTS_LOCATION_COMMAND) { - // Set test snapshot location only if it is a writeable directory - QString path(args.at(i + 1)); + } + if (parser->isSet("testResultsLocation")) { + // Set test snapshot location only if it is a writeable directory + QString path = parser->value("testResultsLocation"); - QFileInfo fileInfo(path); - if (fileInfo.isDir() && fileInfo.isWritable()) { - TestScriptingInterface::getInstance()->setTestResultsLocation(path); - } + QFileInfo fileInfo(path); + if (fileInfo.isDir() && fileInfo.isWritable()) { + TestScriptingInterface::getInstance()->setTestResultsLocation(path); } } + _urlParam = parser->value("url"); } { @@ -1164,8 +1147,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo auto addressManager = DependencyManager::get(); addressManager->moveToThread(nodeList->thread()); - const char** constArgv = const_cast(argv); - if (cmdOptionExists(argc, constArgv, "--disableWatchdog")) { + if (parser->isSet("disableWatchdog")) { DISABLE_WATCHDOG = true; } // Set up a watchdog thread to intentionally crash the application on deadlocks @@ -1486,24 +1468,26 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo connect(&_entityEditSender, &EntityEditPacketSender::packetSent, this, &Application::packetSent); connect(&_entityEditSender, &EntityEditPacketSender::addingEntityWithCertificate, this, &Application::addingEntityWithCertificate); - QString concurrentDownloadsStr = getCmdOption(argc, constArgv, "--concurrent-downloads"); - bool success; - uint32_t concurrentDownloads = concurrentDownloadsStr.toUInt(&success); - if (!success) { - concurrentDownloads = MAX_CONCURRENT_RESOURCE_DOWNLOADS; + if (parser->isSet("concurrent-downloads")) { + bool success; + uint32_t concurrentDownloads = parser->value("concurrent-downloads").toUInt(&success); + if (!success) { + concurrentDownloads = MAX_CONCURRENT_RESOURCE_DOWNLOADS; + } + ResourceCache::setRequestLimit(concurrentDownloads); } - ResourceCache::setRequestLimit(concurrentDownloads); // perhaps override the avatar url. Since we will test later for validity // we don't need to do so here. - QString avatarURL = getCmdOption(argc, constArgv, "--avatarURL"); - _avatarOverrideUrl = QUrl::fromUserInput(avatarURL); + if (parser->isSet("avatarURL")) { + _avatarOverrideUrl = QUrl::fromUserInput(parser->value("avatarURL")); + } // If someone specifies both --avatarURL and --replaceAvatarURL, // the replaceAvatarURL wins. So only set the _overrideUrl if this // does have a non-empty string. - QString replaceURL = getCmdOption(argc, constArgv, "--replaceAvatarURL"); - if (!replaceURL.isEmpty()) { + if (parser->isSet("replaceAvatarURL")) { + QString replaceURL = parser->value("replaceAvatarURL"); _avatarOverrideUrl = QUrl::fromUserInput(replaceURL); _saveAvatarOverrideUrl = true; } @@ -1521,7 +1505,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _glWidget->setFocusPolicy(Qt::StrongFocus); _glWidget->setFocus(); - if (cmdOptionExists(argc, constArgv, "--system-cursor")) { + if (parser->isSet("system-cursor")) { _preferredCursor.set(Cursor::Manager::getIconName(Cursor::Icon::SYSTEM)); } showCursor(Cursor::Manager::lookupIcon(_preferredCursor.get())); @@ -1590,21 +1574,23 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo } }); +#if defined(Q_OS_ANDROID) || defined(DISABLE_QML) connect(offscreenUi.data(), &OffscreenUi::keyboardFocusActive, [this]() { -#if !defined(Q_OS_ANDROID) && !defined(DISABLE_QML) - // Do not show login dialog if requested not to on the command line - QString hifiNoLoginCommandLineKey = QString("--").append(HIFI_NO_LOGIN_COMMAND_LINE_KEY); - int index = arguments().indexOf(hifiNoLoginCommandLineKey); - if (index != -1 || _disableLoginScreen) { - resumeAfterLoginDialogActionTaken(); - return; - } - - showLoginScreen(); -#else resumeAfterLoginDialogActionTaken(); -#endif }); +#else + // Do not show login dialog if requested not to on the command line + if (_disableLoginScreen || parser->isSet("no-login-suggestion")) { + connect(offscreenUi.data(), &OffscreenUi::keyboardFocusActive, [this]() { + resumeAfterLoginDialogActionTaken(); + }); + } else { + connect(offscreenUi.data(), &OffscreenUi::keyboardFocusActive, [this]() { + showLoginScreen(); + resumeAfterLoginDialogActionTaken(); + }); + } +#endif // Initialize the user interface and menu system // Needs to happen AFTER the render engine initialization to access its configuration @@ -1966,13 +1952,17 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo userInputMapper->registerDevice(_touchscreenVirtualPadDevice->getInputDevice()); } - QString scriptsSwitch = QString("--").append(SCRIPTS_SWITCH); - _defaultScriptsLocation.setPath(getCmdOption(argc, constArgv, scriptsSwitch.toStdString().c_str())); + if (parser->isSet("scripts")) { + _defaultScriptsLocation.setPath(parser->value("scripts")); // Already done in "main.cpp". + _overrideDefaultScriptsLocation = true; + } else { + _overrideDefaultScriptsLocation = false; + } // Make sure we don't time out during slow operations at startup updateHeartbeat(); - loadSettings(); + loadSettings(parser); updateVerboseLogging(); @@ -2023,11 +2013,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo // If launched from Steam, let it handle updates - const QString HIFI_NO_UPDATER_COMMAND_LINE_KEY = "--no-updater"; - bool noUpdater = arguments().indexOf(HIFI_NO_UPDATER_COMMAND_LINE_KEY) != -1; bool buildCanUpdate = BuildInfo::BUILD_TYPE == BuildInfo::BuildType::Stable || BuildInfo::BUILD_TYPE == BuildInfo::BuildType::Master; - if (!noUpdater && buildCanUpdate) { + if (!parser->isSet("no-updater") && buildCanUpdate) { constexpr auto INSTALLER_TYPE_CLIENT_ONLY = "client_only"; auto applicationUpdater = DependencyManager::set(); @@ -2196,8 +2184,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo static int NEARBY_AVATAR_RADIUS_METERS = 10; // setup the stats interval depending on if the 1s faster hearbeat was requested - static const QString FAST_STATS_ARG = "--fast-heartbeat"; - static int SEND_STATS_INTERVAL_MS = arguments().indexOf(FAST_STATS_ARG) != -1 ? 1000 : 10000; + static int SEND_STATS_INTERVAL_MS; + if (parser->isSet("fast-heartbeat")) { + SEND_STATS_INTERVAL_MS = 1000; + } else { + SEND_STATS_INTERVAL_MS = 10000; + } static glm::vec3 lastAvatarPosition = myAvatar->getWorldPosition(); static glm::mat4 lastHMDHeadPose = getHMDSensorPose(); @@ -4027,16 +4019,11 @@ void Application::handleSandboxStatus(QNetworkReply* reply) { QString addressLookupString; // when --url in command line, teleport to location - QCommandLineParser parser; - QCommandLineOption urlOption("url", "", "value"); - parser.addOption(urlOption); - parser.parse(arguments()); - if (parser.isSet(urlOption)) { - QUrl url = QUrl(parser.value(urlOption)); - if (url.scheme() == URL_SCHEME_VIRCADIAAPP) { - Setting::Handle("startUpApp").set(url.path()); + if (!_urlParam.isEmpty()) { // Not sure if format supported by isValid(). + if (_urlParam.scheme() == URL_SCHEME_VIRCADIAAPP) { + Setting::Handle("startUpApp").set(_urlParam.path()); } else { - addressLookupString = url.toString(); + addressLookupString = _urlParam.toString(); } } @@ -5519,7 +5506,7 @@ bool Application::exportEntities(const QString& filename, float x, float y, floa return exportEntities(filename, entities, ¢er); } -void Application::loadSettings() { +void Application::loadSettings(const QCommandLineParser* parser) { sessionRunTime.set(0); // Just clean living. We're about to saveSettings, which will update value. DependencyManager::get()->loadSettings(); @@ -5549,7 +5536,7 @@ void Application::loadSettings() { } bool isFirstPerson = false; - if (arguments().contains("--no-launcher")) { + if (parser->isSet("no-launcher")) { auto displayPlugins = pluginManager->getDisplayPlugins(); for (auto& plugin : displayPlugins) { if (!plugin->isHmd()) { @@ -5854,7 +5841,7 @@ void Application::resumeAfterLoginDialogActionTaken() { scriptEngines->reloadLocalFiles(); // if the --scripts command-line argument was used. - if (_defaultScriptsLocation.exists() && (arguments().indexOf(QString("--").append(SCRIPTS_SWITCH))) != -1) { + if (_overrideDefaultScriptsLocation && _defaultScriptsLocation.exists()) { scriptEngines->loadDefaultScripts(); scriptEngines->defaultScriptsLocationOverridden(true); } else { @@ -5874,7 +5861,7 @@ void Application::resumeAfterLoginDialogActionTaken() { // Set last parameter to exit interface when the test script finishes, if so requested DependencyManager::get()->loadScript(testScript, false, false, false, false, quitWhenFinished); // This is done so we don't get a "connection time-out" message when we haven't passed in a URL. - if (arguments().contains("--url")) { + if (!_urlParam.isEmpty()) { auto reply = SandboxUtils::getStatus(); connect(reply, &QNetworkReply::finished, this, [this, reply] { handleSandboxStatus(reply); }); } @@ -8836,31 +8823,21 @@ void Application::sendLambdaEvent(const std::function& f) { } } -void Application::initPlugins(const QStringList& arguments) { - QCommandLineOption display("display", "Preferred displays", "displays"); - QCommandLineOption disableDisplays("disable-displays", "Displays to disable", "displays"); - QCommandLineOption disableInputs("disable-inputs", "Inputs to disable", "inputs"); - - QCommandLineParser parser; - parser.addOption(display); - parser.addOption(disableDisplays); - parser.addOption(disableInputs); - parser.parse(arguments); - - if (parser.isSet(display)) { - auto preferredDisplays = parser.value(display).split(',', Qt::SkipEmptyParts); +void Application::initPlugins(const QCommandLineParser* parser) { + if (parser->isSet("display")) { + auto preferredDisplays = parser->value("display").split(',', Qt::SkipEmptyParts); qInfo() << "Setting prefered display plugins:" << preferredDisplays; PluginManager::getInstance()->setPreferredDisplayPlugins(preferredDisplays); } - if (parser.isSet(disableDisplays)) { - auto disabledDisplays = parser.value(disableDisplays).split(',', Qt::SkipEmptyParts); + if (parser->isSet("disable-displays")) { + auto disabledDisplays = parser->value("disableDisplays").split(',', Qt::SkipEmptyParts); qInfo() << "Disabling following display plugins:" << disabledDisplays; PluginManager::getInstance()->disableDisplays(disabledDisplays); } - if (parser.isSet(disableInputs)) { - auto disabledInputs = parser.value(disableInputs).split(',', Qt::SkipEmptyParts); + if (parser->isSet("disable-inputs")) { + auto disabledInputs = parser->value("disableInputs").split(',', Qt::SkipEmptyParts); qInfo() << "Disabling following input plugins:" << disabledInputs; PluginManager::getInstance()->disableInputs(disabledInputs); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 215473ddfbc..8815f48e3cb 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -15,6 +15,7 @@ #include +#include #include #include #include @@ -22,6 +23,7 @@ #include #include + #include #include @@ -96,8 +98,6 @@ namespace controller { static const QString RUNNING_MARKER_FILENAME = "Interface.running"; -static const QString SCRIPTS_SWITCH = "scripts"; -static const QString HIFI_NO_LOGIN_COMMAND_LINE_KEY = "no-login-suggestion"; class Application; #if defined(qApp) @@ -130,10 +130,15 @@ class Application : public QApplication, virtual DisplayPluginPointer getActiveDisplayPlugin() const override; // FIXME? Empty methods, do we still need them? - static void initPlugins(const QStringList& arguments); + static void initPlugins(const QCommandLineParser* parser); static void shutdownPlugins(); - Application(int& argc, char** argv, QElapsedTimer& startup_time, bool runningMarkerExisted); + Application( + int& argc, char** argv, + const QCommandLineParser* parser, + QElapsedTimer& startup_time, + bool runningMarkerExisted + ); ~Application(); void postLambdaEvent(const std::function& f) override; @@ -505,7 +510,7 @@ private slots: void notifyPacketVersionMismatch(); - void loadSettings(); + void loadSettings(const QCommandLineParser* parser); void saveSettings() const; void setFailedToConnectToEntityServer(); @@ -705,6 +710,8 @@ private slots: QPointer _logDialog; QPointer _entityScriptServerLogDialog; QDir _defaultScriptsLocation; + // If above is only set by parameter, below is unnecessary. + bool _overrideDefaultScriptsLocation; TouchEvent _lastTouchEvent; @@ -830,6 +837,8 @@ private slots: bool quitWhenFinished { false }; + QUrl _urlParam; + bool _showTrackedObjects { false }; bool _prevShowTrackedObjects { false }; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 4c346af75bb..c141630177e 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -80,7 +80,8 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption protocolVersionOption( "protocolVersion", - "Displays the protocol version." + "Writes the protocol version base64 signature to a file?", + "path" // Why?? ); QCommandLineOption noUpdaterOption( "no-updater", @@ -108,11 +109,11 @@ int main(int argc, const char* argv[]) { "set test cache .", "dir" ); - //QCommandLineOption scriptsOption( - // "scripts", - // "Set path for defaultScripts.", - // "dir" - //); // Use this once SCRIPTS_SWITCH is removed. + QCommandLineOption scriptsOption( + "scripts", + "Set path for defaultScripts.", + "dir" + ); QCommandLineOption allowMultipleInstancesOption( "allowMultipleInstances", "Allow multiple instances to run." @@ -124,11 +125,13 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption disableDisplaysOption( "disable-displays", - "Displays to disable." + "Displays to disable.", + "string" ); QCommandLineOption disableInputsOption( "disable-inputs", - "Inputs to disable." + "Inputs to disable.", + "string" ); QCommandLineOption suppressSettingsResetOption( "suppress-settings-reset", @@ -177,11 +180,11 @@ int main(int argc, const char* argv[]) { "no-launcher", "Do not execute the launcher." ); - QCommandLineOption overrideScriptsPathOption( + /*QCommandLineOption overrideScriptsPathOption( SCRIPTS_SWITCH, "Set scripts ", "path" - ); + );*/ QCommandLineOption defaultScriptOverrideOption( "defaultScriptsOverride", "Override defaultsScripts.js.", @@ -197,6 +200,10 @@ int main(int argc, const char* argv[]) { "Set user display name .", "string" ); + QCommandLineOption noLoginOption( + "no-login-suggestion", + "Do not show log-in dialogue." + ); QCommandLineOption traceFileOption( "traceFile", "Probably writes a trace to a file?", @@ -212,6 +219,24 @@ int main(int argc, const char* argv[]) { "Forces client instance's clock to skew for demonstration purposes.", "value" ); + QCommandLineOption testScriptOption( + "testScript", + "Undocumented. Accepts parameter as U.R.L.", + "string" + ); + QCommandLineOption testResultsLocationOption( + "testResultsLocation", + "Undocumented", + "path" + ); + QCommandLineOption quitWhenFinishedOption( + "quitWhenFinished", + "Only works if \"--testScript\" is provided." + ); // Should probably also work on testResultsLocationOption. + QCommandLineOption fastHeartbeatOption( + "fast-heartbeat", + "Change stats polling interval from 10000ms to 1000ms." + ); // "--qmljsdebugger", which appears in output from "--help-all". // Those below don't seem to be optional. // --ignore-gpu-blacklist @@ -225,7 +250,7 @@ int main(int argc, const char* argv[]) { parser.addOption(listenPortOption); parser.addOption(serverContentPathOption); parser.addOption(overrideAppLocalDataPathOption); - //parser.addOption(scriptsOption); // Use this once SCRIPTS_SWITCH is removed. + parser.addOption(scriptsOption); // Also known as "overrideScriptsPathOption"? parser.addOption(allowMultipleInstancesOption); parser.addOption(displaysOption); parser.addOption(disableDisplaysOption); @@ -241,15 +266,17 @@ int main(int argc, const char* argv[]) { parser.addOption(setBookmarkOption); parser.addOption(forceCrashReportingOption); parser.addOption(noLauncherOption); - parser.addOption(overrideScriptsPathOption); // Remove this along with SCRIPTS_SWITCH. parser.addOption(responseTokensOption); parser.addOption(displayNameOption); parser.addOption(defaultScriptOverrideOption); parser.addOption(traceFileOption); parser.addOption(traceDurationOption); parser.addOption(clockSkewOption); + parser.addOption(testScriptOption); + parser.addOption(testResultsLocationOption); + parser.addOption(quitWhenFinishedOption); + parser.addOption(fastHeartbeatOption); - QStringList arguments; QString applicationPath; // A temporary application instance is needed to get the location of the running executable // Tests using high_resolution_clock show that this takes about 30-50 microseconds (on my machine, YMMV) @@ -259,7 +286,6 @@ int main(int argc, const char* argv[]) { QCoreApplication tempApp(argc, const_cast(argv)); parser.process(QCoreApplication::arguments()); // Must be run after QCoreApplication is initalised. - arguments = parser.positionalArguments(); // Must be run after parser processes arguments. #ifdef Q_OS_OSX if (QFileInfo::exists(QCoreApplication::applicationDirPath() + "/../../../config.json")) { @@ -388,12 +414,13 @@ int main(int argc, const char* argv[]) { // this needs to be done here in main, as the mechanism for setting the // scripts directory appears not to work. See the bug report // https://highfidelity.fogbugz.com/f/cases/5759/Issues-changing-scripts-directory-in-ScriptsEngine - if (parser.isSet(overrideScriptsPathOption)) { + // It is currently also done in "Application.cpp". Not sure if necessary. + /*if (parser.isSet(overrideScriptsPathOption)) { QDir scriptsPath(parser.value(overrideScriptsPathOption)); if (scriptsPath.exists()) { PathUtils::defaultScriptsLocation(scriptsPath.path()); } - } + }*/ if (instanceMightBeRunning) { // Try to connect and send message to existing interface instance @@ -471,7 +498,7 @@ int main(int argc, const char* argv[]) { // Oculus initialization MUST PRECEDE OpenGL context creation. // The nature of the Application constructor means this has to be either here, // or in the main window ctor, before GL startup. - Application::initPlugins(arguments); + Application::initPlugins(&parser); #ifdef Q_OS_WIN // If we're running in steam mode, we need to do an explicit check to ensure we're up to the required min spec @@ -519,7 +546,7 @@ int main(int argc, const char* argv[]) { PROFILE_SYNC_END(startup, "main startup", ""); PROFILE_SYNC_BEGIN(startup, "app full ctor", ""); - Application app(argcExtended, const_cast(argvExtended.data()), startupTime, runningMarkerExisted); + Application app(argcExtended, const_cast(argvExtended.data()), &parser, startupTime, runningMarkerExisted); PROFILE_SYNC_END(startup, "app full ctor", ""); #if defined(Q_OS_LINUX) From 09f6ec883dde90ad4cb140322f7faeec57cb792b Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Tue, 26 Oct 2021 12:29:21 -0700 Subject: [PATCH 10/22] Removed duplicate "--version". --- interface/src/Application.cpp | 5 +---- interface/src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 81d6075b351..cc83151cc50 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -757,10 +757,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser* parser, b reportAndQuit("--protocolVersion", [&](FILE* fp) { auto version = protocolVersionsSignatureBase64(); fputs(version.toLatin1().data(), fp); - }); // This doesn't seem to work. - /*reportAndQuit("--version", [&](FILE* fp) { - fputs(BuildInfo::VERSION.toLatin1().data(), fp); - });*/ + }); const int listenPort = parser->isSet("listenPort") ? parser->value("listenPort").toInt() : INVALID_PORT; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index c141630177e..c4f6264c959 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -218,7 +218,7 @@ int main(int argc, const char* argv[]) { "clockSkew", "Forces client instance's clock to skew for demonstration purposes.", "value" - ); + ); // This should probably be removed. QCommandLineOption testScriptOption( "testScript", "Undocumented. Accepts parameter as U.R.L.", From 510df4dbdb462b95c36ef0c1be4fcd4821c5f745 Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Tue, 26 Oct 2021 17:29:15 -0700 Subject: [PATCH 11/22] Fixed handling of traceFileOption. Moved last to main. --- interface/src/Application.cpp | 25 ------------------------- interface/src/main.cpp | 33 +++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index cc83151cc50..ca365a7914b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -728,36 +728,11 @@ extern DisplayPluginList getDisplayPlugins(); extern InputPluginList getInputPlugins(); extern void saveInputPluginSettings(const InputPluginList& plugins); -// Parameters used for running tests from the command line - bool setupEssentials(int& argc, char** argv, const QCommandLineParser* parser, bool runningMarkerExisted) { const char** constArgv = const_cast(argv); qInstallMessageHandler(messageHandler); - // HRS: I could not figure out how to move these any earlier in startup, so when using this option, be sure to also supply - // --allowMultipleInstances - auto reportAndQuit = [&](const char* commandSwitch, std::function report) { - // Do something about this: - const char* reportfile = getCmdOption(argc, constArgv, commandSwitch); - // Reports to the specified file, because stdout is set up to be captured for logging. - if (reportfile) { - FILE* fp = fopen(reportfile, "w"); - if (fp) { - report(fp); - fclose(fp); - if (!runningMarkerExisted) { // don't leave ours around - RunningMarker runingMarker(RUNNING_MARKER_FILENAME); - runingMarker.deleteRunningMarkerFile(); // happens in deleter, but making the side-effect explicit. - } - _exit(0); - } - } - }; - reportAndQuit("--protocolVersion", [&](FILE* fp) { - auto version = protocolVersionsSignatureBase64(); - fputs(version.toLatin1().data(), fp); - }); const int listenPort = parser->isSet("listenPort") ? parser->value("listenPort").toInt() : INVALID_PORT; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index c4f6264c959..f5e9e01abd9 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -66,8 +66,6 @@ int main(int argc, const char* argv[]) { setupHifiApplication(BuildInfo::INTERFACE_NAME); - // grep -E 'getCmdOption|QCommandLineOption|cmdOptionExists' 'interface/src/Application.cpp' - QCommandLineParser parser; parser.setApplicationDescription("Vircadia"); QCommandLineOption helpOption = parser.addHelpOption(); @@ -180,11 +178,6 @@ int main(int argc, const char* argv[]) { "no-launcher", "Do not execute the launcher." ); - /*QCommandLineOption overrideScriptsPathOption( - SCRIPTS_SWITCH, - "Set scripts ", - "path" - );*/ QCommandLineOption defaultScriptOverrideOption( "defaultScriptsOverride", "Override defaultsScripts.js.", @@ -206,12 +199,12 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption traceFileOption( "traceFile", - "Probably writes a trace to a file?", + "Probably writes a trace to a file? Only works if \"--traceDuration\" is specified.", "path" ); QCommandLineOption traceDurationOption( "traceDuration", - "Only works if \"--traceFile\" is provided.", + "Probably a number of seconds? Only works if \"--traceFile\" is specified.", "value" ); QCommandLineOption clockSkewOption( @@ -232,7 +225,7 @@ int main(int argc, const char* argv[]) { QCommandLineOption quitWhenFinishedOption( "quitWhenFinished", "Only works if \"--testScript\" is provided." - ); // Should probably also work on testResultsLocationOption. + ); // Should probably also be made to work on testResultsLocationOption. QCommandLineOption fastHeartbeatOption( "fast-heartbeat", "Change stats polling interval from 10000ms to 1000ms." @@ -308,6 +301,17 @@ int main(int argc, const char* argv[]) { parser.showHelp(); Q_UNREACHABLE(); } + if (parser.isSet(protocolVersionOption)) { + FILE* fp = fopen(parser.value(protocolVersionOption).toStdString().c_str(), "w"); + if (fp) { + fputs(protocolVersionsSignatureBase64().toStdString().c_str(), fp); + fclose(fp); + return 0; + } else { + qWarning() << "Failed to open file specified for --protocolVersion."; + return 1; + } + } static const QString APPLICATION_CONFIG_FILENAME = "config.json"; QDir applicationDir(applicationPath); @@ -347,15 +351,16 @@ int main(int argc, const char* argv[]) { // Early check for --traceFile argument auto tracer = DependencyManager::set(); const char * traceFile = nullptr; - float traceDuration; + float traceDuration = 0.0f; if (parser.isSet(traceFileOption)) { traceFile = parser.value(traceFileOption).toStdString().c_str(); if (parser.isSet(traceDurationOption)) { traceDuration = parser.value(traceDurationOption).toFloat(); + tracer->startTracing(); } else { - traceDuration = 0.0f; + qWarning() << "\"--traceDuration\" must be specified along with \"--traceFile\"..."; + return 1; } - tracer->startTracing(); } PROFILE_SYNC_BEGIN(startup, "main startup", ""); @@ -412,7 +417,7 @@ int main(int argc, const char* argv[]) { instanceMightBeRunning = false; } // this needs to be done here in main, as the mechanism for setting the - // scripts directory appears not to work. See the bug report + // scripts directory appears not to work. See the bug report (dead link) // https://highfidelity.fogbugz.com/f/cases/5759/Issues-changing-scripts-directory-in-ScriptsEngine // It is currently also done in "Application.cpp". Not sure if necessary. /*if (parser.isSet(overrideScriptsPathOption)) { From cd81fe99f51d2aa67e9c490ce88d89717dd98edf Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Tue, 26 Oct 2021 17:55:14 -0700 Subject: [PATCH 12/22] Made help info more helpful. --- interface/src/main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index f5e9e01abd9..2a578867553 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -74,7 +74,7 @@ int main(int argc, const char* argv[]) { QCommandLineOption urlOption( "url", "Start at specified URL location.", - "value" + "string" ); QCommandLineOption protocolVersionOption( "protocolVersion", @@ -87,11 +87,11 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption checkMinSpecOption( "checkMinSpec", - "Check if machine meets minimum specifications." + "Check if machine meets minimum specifications. The program will run if check passes." ); QCommandLineOption runServerOption( "runServer", - "Whether to run the server." + "Run the server." ); QCommandLineOption listenPortOption( "listenPort", @@ -99,12 +99,12 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption serverContentPathOption( "serverContentPath", - "Where to find server content .", + "Path to find server content.", // What content?? "serverContentPath" ); // This data type will not be familiar to users. QCommandLineOption overrideAppLocalDataPathOption( "cache", - "set test cache .", + "Set test cache.", "dir" ); QCommandLineOption scriptsOption( @@ -205,12 +205,12 @@ int main(int argc, const char* argv[]) { QCommandLineOption traceDurationOption( "traceDuration", "Probably a number of seconds? Only works if \"--traceFile\" is specified.", - "value" + "number" ); QCommandLineOption clockSkewOption( "clockSkew", "Forces client instance's clock to skew for demonstration purposes.", - "value" + "integer" ); // This should probably be removed. QCommandLineOption testScriptOption( "testScript", From 61f9669ef5c7946c02d80fd457ba5bdd32c4c22a Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Tue, 26 Oct 2021 18:32:24 -0700 Subject: [PATCH 13/22] Notational changes. --- interface/src/Application.cpp | 2 +- interface/src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ca365a7914b..da9955bdc44 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1925,7 +1925,7 @@ Application::Application( } if (parser->isSet("scripts")) { - _defaultScriptsLocation.setPath(parser->value("scripts")); // Already done in "main.cpp". + _defaultScriptsLocation.setPath(parser->value("scripts")); // Might need to be done in "main.cpp". _overrideDefaultScriptsLocation = true; } else { _overrideDefaultScriptsLocation = false; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 2a578867553..eac942bcca4 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -109,7 +109,7 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption scriptsOption( "scripts", - "Set path for defaultScripts.", + "Set path for defaultScripts. These are probably scripts that run automatically.", "dir" ); QCommandLineOption allowMultipleInstancesOption( From 1df3e0e8c9be1b0a87a6561a5e5638de795d8a60 Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Wed, 27 Oct 2021 14:09:23 -0700 Subject: [PATCH 14/22] Re-enabled overrideScriptsPathOption. --- interface/src/main.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index eac942bcca4..61161801b03 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -178,8 +178,13 @@ int main(int argc, const char* argv[]) { "no-launcher", "Do not execute the launcher." ); + QCommandLineOption overrideScriptsPathOption( + "overrideScriptsPath", + "Probably specifies where to look for scripts.", + "string" + ); QCommandLineOption defaultScriptOverrideOption( - "defaultScriptsOverride", + "defaultScriptOverride", "Override defaultsScripts.js.", "string" ); @@ -243,7 +248,7 @@ int main(int argc, const char* argv[]) { parser.addOption(listenPortOption); parser.addOption(serverContentPathOption); parser.addOption(overrideAppLocalDataPathOption); - parser.addOption(scriptsOption); // Also known as "overrideScriptsPathOption"? + parser.addOption(scriptsOption); parser.addOption(allowMultipleInstancesOption); parser.addOption(displaysOption); parser.addOption(disableDisplaysOption); @@ -261,6 +266,7 @@ int main(int argc, const char* argv[]) { parser.addOption(noLauncherOption); parser.addOption(responseTokensOption); parser.addOption(displayNameOption); + parser.addOption(overrideScriptsPathOption); parser.addOption(defaultScriptOverrideOption); parser.addOption(traceFileOption); parser.addOption(traceDurationOption); @@ -419,13 +425,12 @@ int main(int argc, const char* argv[]) { // this needs to be done here in main, as the mechanism for setting the // scripts directory appears not to work. See the bug report (dead link) // https://highfidelity.fogbugz.com/f/cases/5759/Issues-changing-scripts-directory-in-ScriptsEngine - // It is currently also done in "Application.cpp". Not sure if necessary. - /*if (parser.isSet(overrideScriptsPathOption)) { + if (parser.isSet(overrideScriptsPathOption)) { QDir scriptsPath(parser.value(overrideScriptsPathOption)); if (scriptsPath.exists()) { PathUtils::defaultScriptsLocation(scriptsPath.path()); } - }*/ + } if (instanceMightBeRunning) { // Try to connect and send message to existing interface instance From cfac024547d0a104f1c9d495e87b0119e3f10008 Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Fri, 5 Nov 2021 17:58:35 -0700 Subject: [PATCH 15/22] Fixed quibbles. --- interface/src/Application.cpp | 2 +- interface/src/main.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index da9955bdc44..9c9e04c504c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1926,7 +1926,7 @@ Application::Application( if (parser->isSet("scripts")) { _defaultScriptsLocation.setPath(parser->value("scripts")); // Might need to be done in "main.cpp". - _overrideDefaultScriptsLocation = true; + _overrideDefaultScriptsLocation = true; } else { _overrideDefaultScriptsLocation = false; } diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 61161801b03..e9946119bb0 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -95,7 +95,8 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption listenPortOption( "listenPort", - "Port to listen on." + "Port to listen on.", + "port_number" ); QCommandLineOption serverContentPathOption( "serverContentPath", @@ -153,15 +154,18 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption concurrentDownloadsOption( "concurrent-downloads", - "Maximum concurrent resource downloads. Default is 16, except for Android where it is 4." + "Maximum concurrent resource downloads. Default is 16, except for Android where it is 4.", + "integer" ); QCommandLineOption avatarURLOption( "avatarURL", - "Override the avatar U.R.L." + "Override the avatar U.R.L.", + "url" ); QCommandLineOption replaceAvatarURLOption( "replace-avatar-url", - "Replaces the avatar U.R.L. When used with --avatarURL, this takes precedence." + "Replaces the avatar U.R.L. When used with --avatarURL, this takes precedence.", + "url" ); QCommandLineOption setBookmarkOption( "setBookmark", From e9e3bd6bc58957566489a70c5d2d43f4c36f6c2f Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Fri, 5 Nov 2021 18:25:10 -0700 Subject: [PATCH 16/22] Fixed a spacing. --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9c9e04c504c..a954de42151 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1928,7 +1928,7 @@ Application::Application( _defaultScriptsLocation.setPath(parser->value("scripts")); // Might need to be done in "main.cpp". _overrideDefaultScriptsLocation = true; } else { - _overrideDefaultScriptsLocation = false; + _overrideDefaultScriptsLocation = false; } // Make sure we don't time out during slow operations at startup From 1f89923b96c621e540543d8d25ccb522135c079c Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Fri, 5 Nov 2021 18:27:15 -0700 Subject: [PATCH 17/22] Fixed a different kind of spacing. --- interface/src/Application.h | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index 8815f48e3cb..ab56daf67a2 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -23,7 +23,6 @@ #include #include - #include #include From 8eed5eb6da8ec44f077fab6ff85e871a9e14651a Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Sat, 20 Nov 2021 12:34:34 -0800 Subject: [PATCH 18/22] Changes parser pointer to reference. --- interface/src/Application.cpp | 78 +++++++++++++++++------------------ interface/src/Application.h | 6 +-- interface/src/main.cpp | 4 +- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a954de42151..cb669d4a302 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -728,24 +728,24 @@ extern DisplayPluginList getDisplayPlugins(); extern InputPluginList getInputPlugins(); extern void saveInputPluginSettings(const InputPluginList& plugins); -bool setupEssentials(int& argc, char** argv, const QCommandLineParser* parser, bool runningMarkerExisted) { +bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, bool runningMarkerExisted) { const char** constArgv = const_cast(argv); qInstallMessageHandler(messageHandler); - const int listenPort = parser->isSet("listenPort") ? parser->value("listenPort").toInt() : INVALID_PORT; + const int listenPort = parser.isSet("listenPort") ? parser.value("listenPort").toInt() : INVALID_PORT; - bool suppressPrompt = parser->isSet("suppress-settings-reset"); + bool suppressPrompt = parser.isSet("suppress-settings-reset"); // set the OCULUS_STORE property so the oculus plugin can know if we ran from the Oculus Store - qApp->setProperty(hifi::properties::OCULUS_STORE, parser->isSet("oculus-store")); + qApp->setProperty(hifi::properties::OCULUS_STORE, parser.isSet("oculus-store")); // emulate standalone device - qApp->setProperty(hifi::properties::STANDALONE, parser->isSet("standalone")); + qApp->setProperty(hifi::properties::STANDALONE, parser.isSet("standalone")); // Ignore any previous crashes if running from command line with a test script. - bool inTestMode = parser->isSet("testScript"); + bool inTestMode = parser.isSet("testScript"); bool previousSessionCrashed { false }; if (!inTestMode) { @@ -753,8 +753,8 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser* parser, b } // get dir to use for cache - if (parser->isSet("cache")) { - qApp->setProperty(hifi::properties::APP_LOCAL_DATA_PATH, parser->value("cache")); + if (parser.isSet("cache")) { + qApp->setProperty(hifi::properties::APP_LOCAL_DATA_PATH, parser.value("cache")); } { @@ -796,7 +796,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser* parser, b QCoreApplication::addLibraryPath(audioDLLPath); #endif - QString defaultScriptsOverrideOption = parser->value("defaultScriptsOverride"); + QString defaultScriptsOverrideOption = parser.value("defaultScriptsOverride"); DependencyManager::registerInheritance(); DependencyManager::registerInheritance(); @@ -922,7 +922,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser* parser, b }); - QString setBookmarkValue = parser->value("setBookmark"); + QString setBookmarkValue = parser.value("setBookmark"); if (!setBookmarkValue.isEmpty()) { // Bookmarks are expected to be in a name=url form. // An `=` character in the name or url is unsupported. @@ -981,7 +981,7 @@ QSharedPointer getOffscreenUI() { Application::Application( int& argc, char** argv, - const QCommandLineParser* parser, + const QCommandLineParser& parser, QElapsedTimer& startupTimer, bool runningMarkerExisted ) : @@ -1028,8 +1028,8 @@ Application::Application( LogHandler::getInstance().setupRepeatedMessageFlusher(); { - if (parser->isSet("testScript")) { - QString testScriptPath = parser->value("testScript"); + if (parser.isSet("testScript")) { + QString testScriptPath = parser.value("testScript"); // If the URL scheme is http(s) or ftp, then use as is, else - treat it as a local file // This is done so as not break previous command line scripts if (testScriptPath.left(HIFI_URL_SCHEME_HTTP.length()) == HIFI_URL_SCHEME_HTTP || @@ -1040,20 +1040,20 @@ Application::Application( setProperty(hifi::properties::TEST, QUrl::fromLocalFile(testScriptPath)); } - if (parser->isSet("quitWhenFinished")) { + if (parser.isSet("quitWhenFinished")) { quitWhenFinished = true; } } - if (parser->isSet("testResultsLocation")) { + if (parser.isSet("testResultsLocation")) { // Set test snapshot location only if it is a writeable directory - QString path = parser->value("testResultsLocation"); + QString path = parser.value("testResultsLocation"); QFileInfo fileInfo(path); if (fileInfo.isDir() && fileInfo.isWritable()) { TestScriptingInterface::getInstance()->setTestResultsLocation(path); } } - _urlParam = parser->value("url"); + _urlParam = parser.value("url"); } { @@ -1119,7 +1119,7 @@ Application::Application( auto addressManager = DependencyManager::get(); addressManager->moveToThread(nodeList->thread()); - if (parser->isSet("disableWatchdog")) { + if (parser.isSet("disableWatchdog")) { DISABLE_WATCHDOG = true; } // Set up a watchdog thread to intentionally crash the application on deadlocks @@ -1440,9 +1440,9 @@ Application::Application( connect(&_entityEditSender, &EntityEditPacketSender::packetSent, this, &Application::packetSent); connect(&_entityEditSender, &EntityEditPacketSender::addingEntityWithCertificate, this, &Application::addingEntityWithCertificate); - if (parser->isSet("concurrent-downloads")) { + if (parser.isSet("concurrent-downloads")) { bool success; - uint32_t concurrentDownloads = parser->value("concurrent-downloads").toUInt(&success); + uint32_t concurrentDownloads = parser.value("concurrent-downloads").toUInt(&success); if (!success) { concurrentDownloads = MAX_CONCURRENT_RESOURCE_DOWNLOADS; } @@ -1451,15 +1451,15 @@ Application::Application( // perhaps override the avatar url. Since we will test later for validity // we don't need to do so here. - if (parser->isSet("avatarURL")) { - _avatarOverrideUrl = QUrl::fromUserInput(parser->value("avatarURL")); + if (parser.isSet("avatarURL")) { + _avatarOverrideUrl = QUrl::fromUserInput(parser.value("avatarURL")); } // If someone specifies both --avatarURL and --replaceAvatarURL, // the replaceAvatarURL wins. So only set the _overrideUrl if this // does have a non-empty string. - if (parser->isSet("replaceAvatarURL")) { - QString replaceURL = parser->value("replaceAvatarURL"); + if (parser.isSet("replaceAvatarURL")) { + QString replaceURL = parser.value("replaceAvatarURL"); _avatarOverrideUrl = QUrl::fromUserInput(replaceURL); _saveAvatarOverrideUrl = true; } @@ -1477,7 +1477,7 @@ Application::Application( _glWidget->setFocusPolicy(Qt::StrongFocus); _glWidget->setFocus(); - if (parser->isSet("system-cursor")) { + if (parser.isSet("system-cursor")) { _preferredCursor.set(Cursor::Manager::getIconName(Cursor::Icon::SYSTEM)); } showCursor(Cursor::Manager::lookupIcon(_preferredCursor.get())); @@ -1552,7 +1552,7 @@ Application::Application( }); #else // Do not show login dialog if requested not to on the command line - if (_disableLoginScreen || parser->isSet("no-login-suggestion")) { + if (_disableLoginScreen || parser.isSet("no-login-suggestion")) { connect(offscreenUi.data(), &OffscreenUi::keyboardFocusActive, [this]() { resumeAfterLoginDialogActionTaken(); }); @@ -1924,8 +1924,8 @@ Application::Application( userInputMapper->registerDevice(_touchscreenVirtualPadDevice->getInputDevice()); } - if (parser->isSet("scripts")) { - _defaultScriptsLocation.setPath(parser->value("scripts")); // Might need to be done in "main.cpp". + if (parser.isSet("scripts")) { + _defaultScriptsLocation.setPath(parser.value("scripts")); // Might need to be done in "main.cpp". _overrideDefaultScriptsLocation = true; } else { _overrideDefaultScriptsLocation = false; @@ -1987,7 +1987,7 @@ Application::Application( // If launched from Steam, let it handle updates bool buildCanUpdate = BuildInfo::BUILD_TYPE == BuildInfo::BuildType::Stable || BuildInfo::BUILD_TYPE == BuildInfo::BuildType::Master; - if (!parser->isSet("no-updater") && buildCanUpdate) { + if (!parser.isSet("no-updater") && buildCanUpdate) { constexpr auto INSTALLER_TYPE_CLIENT_ONLY = "client_only"; auto applicationUpdater = DependencyManager::set(); @@ -2157,7 +2157,7 @@ Application::Application( // setup the stats interval depending on if the 1s faster hearbeat was requested static int SEND_STATS_INTERVAL_MS; - if (parser->isSet("fast-heartbeat")) { + if (parser.isSet("fast-heartbeat")) { SEND_STATS_INTERVAL_MS = 1000; } else { SEND_STATS_INTERVAL_MS = 10000; @@ -5478,7 +5478,7 @@ bool Application::exportEntities(const QString& filename, float x, float y, floa return exportEntities(filename, entities, ¢er); } -void Application::loadSettings(const QCommandLineParser* parser) { +void Application::loadSettings(const QCommandLineParser& parser) { sessionRunTime.set(0); // Just clean living. We're about to saveSettings, which will update value. DependencyManager::get()->loadSettings(); @@ -5508,7 +5508,7 @@ void Application::loadSettings(const QCommandLineParser* parser) { } bool isFirstPerson = false; - if (parser->isSet("no-launcher")) { + if (parser.isSet("no-launcher")) { auto displayPlugins = pluginManager->getDisplayPlugins(); for (auto& plugin : displayPlugins) { if (!plugin->isHmd()) { @@ -8795,21 +8795,21 @@ void Application::sendLambdaEvent(const std::function& f) { } } -void Application::initPlugins(const QCommandLineParser* parser) { - if (parser->isSet("display")) { - auto preferredDisplays = parser->value("display").split(',', Qt::SkipEmptyParts); +void Application::initPlugins(const QCommandLineParser& parser) { + if (parser.isSet("display")) { + auto preferredDisplays = parser.value("display").split(',', Qt::SkipEmptyParts); qInfo() << "Setting prefered display plugins:" << preferredDisplays; PluginManager::getInstance()->setPreferredDisplayPlugins(preferredDisplays); } - if (parser->isSet("disable-displays")) { - auto disabledDisplays = parser->value("disableDisplays").split(',', Qt::SkipEmptyParts); + if (parser.isSet("disable-displays")) { + auto disabledDisplays = parser.value("disableDisplays").split(',', Qt::SkipEmptyParts); qInfo() << "Disabling following display plugins:" << disabledDisplays; PluginManager::getInstance()->disableDisplays(disabledDisplays); } - if (parser->isSet("disable-inputs")) { - auto disabledInputs = parser->value("disableInputs").split(',', Qt::SkipEmptyParts); + if (parser.isSet("disable-inputs")) { + auto disabledInputs = parser.value("disableInputs").split(',', Qt::SkipEmptyParts); qInfo() << "Disabling following input plugins:" << disabledInputs; PluginManager::getInstance()->disableInputs(disabledInputs); } diff --git a/interface/src/Application.h b/interface/src/Application.h index ab56daf67a2..cd323eef08f 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -129,12 +129,12 @@ class Application : public QApplication, virtual DisplayPluginPointer getActiveDisplayPlugin() const override; // FIXME? Empty methods, do we still need them? - static void initPlugins(const QCommandLineParser* parser); + static void initPlugins(const QCommandLineParser& parser); static void shutdownPlugins(); Application( int& argc, char** argv, - const QCommandLineParser* parser, + const QCommandLineParser& parser, QElapsedTimer& startup_time, bool runningMarkerExisted ); @@ -509,7 +509,7 @@ private slots: void notifyPacketVersionMismatch(); - void loadSettings(const QCommandLineParser* parser); + void loadSettings(const QCommandLineParser& parser); void saveSettings() const; void setFailedToConnectToEntityServer(); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index e9946119bb0..d874a61fb16 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -512,7 +512,7 @@ int main(int argc, const char* argv[]) { // Oculus initialization MUST PRECEDE OpenGL context creation. // The nature of the Application constructor means this has to be either here, // or in the main window ctor, before GL startup. - Application::initPlugins(&parser); + Application::initPlugins(parser); #ifdef Q_OS_WIN // If we're running in steam mode, we need to do an explicit check to ensure we're up to the required min spec @@ -560,7 +560,7 @@ int main(int argc, const char* argv[]) { PROFILE_SYNC_END(startup, "main startup", ""); PROFILE_SYNC_BEGIN(startup, "app full ctor", ""); - Application app(argcExtended, const_cast(argvExtended.data()), &parser, startupTime, runningMarkerExisted); + Application app(argcExtended, const_cast(argvExtended.data()), parser, startupTime, runningMarkerExisted); PROFILE_SYNC_END(startup, "app full ctor", ""); #if defined(Q_OS_LINUX) From 9d7e8ea449b8426f685fd8b9456c848be56f8f9f Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Sat, 20 Nov 2021 17:12:49 -0800 Subject: [PATCH 19/22] Requested fixes (hopefully). --- interface/src/Application.cpp | 42 ++++++++++++++++++----------------- interface/src/main.cpp | 20 ++++++++--------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index cb669d4a302..567207cb31f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1342,25 +1342,27 @@ Application::Application( connect(this, &QCoreApplication::aboutToQuit, addressManager.data(), &AddressManager::storeCurrentAddress); connect(this, &Application::activeDisplayPluginChanged, this, &Application::updateThreadPoolCount); - connect(this, &Application::activeDisplayPluginChanged, this, [=](){ - qApp->setProperty(hifi::properties::HMD, qApp->isHMDMode()); - auto displayPlugin = qApp->getActiveDisplayPlugin(); + if (parser.isSet("system-cursor")) { + _preferredCursor.set(Cursor::Manager::getIconName(Cursor::Icon::SYSTEM)); - if (displayPlugin->isHmd()) { - if (_preferredCursor.get() == Cursor::Manager::getIconName(Cursor::Icon::RETICLE)) { - setPreferredCursor(Cursor::Manager::getIconName(Cursor::Icon::RETICLE)); - } - else { - setPreferredCursor(Cursor::Manager::getIconName(Cursor::Icon::ARROW)); + connect(this, &Application::activeDisplayPluginChanged, this, [=](){ + qApp->setProperty(hifi::properties::HMD, qApp->isHMDMode()); + auto displayPlugin = qApp->getActiveDisplayPlugin(); + + if (displayPlugin->isHmd()) { + if (_preferredCursor.get() == Cursor::Manager::getIconName(Cursor::Icon::RETICLE)) { + setPreferredCursor(Cursor::Manager::getIconName(Cursor::Icon::RETICLE)); + } else { + setPreferredCursor(Cursor::Manager::getIconName(Cursor::Icon::ARROW)); + } + } else { + setPreferredCursor(Cursor::Manager::getIconName(Cursor::Icon::SYSTEM)); } - } - else { - setPreferredCursor(Cursor::Manager::getIconName(Cursor::Icon::SYSTEM)); - } - setCrashAnnotation("display_plugin", displayPlugin->getName().toStdString()); - setCrashAnnotation("hmd", displayPlugin->isHmd() ? "1" : "0"); - }); + setCrashAnnotation("display_plugin", displayPlugin->getName().toStdString()); + setCrashAnnotation("hmd", displayPlugin->isHmd() ? "1" : "0"); + }); + } connect(this, &Application::activeDisplayPluginChanged, this, &Application::updateSystemTabletMode); connect(this, &Application::activeDisplayPluginChanged, this, [&](){ if (getLoginDialogPoppedUp()) { @@ -1477,9 +1479,9 @@ Application::Application( _glWidget->setFocusPolicy(Qt::StrongFocus); _glWidget->setFocus(); - if (parser.isSet("system-cursor")) { + /*if (parser.isSet("system-cursor")) { // This is now done above, since the conditional was needed anyway. _preferredCursor.set(Cursor::Manager::getIconName(Cursor::Icon::SYSTEM)); - } + }*/ showCursor(Cursor::Manager::lookupIcon(_preferredCursor.get())); // enable mouse tracking; otherwise, we only get drag events @@ -5814,10 +5816,10 @@ void Application::resumeAfterLoginDialogActionTaken() { // if the --scripts command-line argument was used. if (_overrideDefaultScriptsLocation && _defaultScriptsLocation.exists()) { - scriptEngines->loadDefaultScripts(); + scriptEngines->loadScripts(); scriptEngines->defaultScriptsLocationOverridden(true); } else { - scriptEngines->loadScripts(); + scriptEngines->loadDefaultScripts(); } } diff --git a/interface/src/main.cpp b/interface/src/main.cpp index d874a61fb16..a173ef45f99 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -67,7 +67,7 @@ int main(int argc, const char* argv[]) { setupHifiApplication(BuildInfo::INTERFACE_NAME); QCommandLineParser parser; - parser.setApplicationDescription("Vircadia"); + parser.setApplicationDescription("Vircadia -- A free/libre and open-source metaverse client"); QCommandLineOption helpOption = parser.addHelpOption(); QCommandLineOption versionOption = parser.addVersionOption(); @@ -150,7 +150,7 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption systemCursorOption( "system-cursor", - "Probably prevents changing the cursor when application has focus." + "Use the default system cursor." ); QCommandLineOption concurrentDownloadsOption( "concurrent-downloads", @@ -184,12 +184,12 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption overrideScriptsPathOption( "overrideScriptsPath", - "Probably specifies where to look for scripts.", + "Specifies path to default directory where the application will look for scripts to load.", "string" ); - QCommandLineOption defaultScriptOverrideOption( - "defaultScriptOverride", - "Override defaultsScripts.js.", + QCommandLineOption defaultScriptsOverrideOption( + "defaultScriptsOverride", + "Override default script to run automatically on start. Default is \"defaultsScripts.js\".", "string" ); QCommandLineOption responseTokensOption( @@ -208,13 +208,13 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption traceFileOption( "traceFile", - "Probably writes a trace to a file? Only works if \"--traceDuration\" is specified.", + "Writes a trace to a file in the documents folder. Only works if \"--traceDuration\" is specified.", "path" ); QCommandLineOption traceDurationOption( "traceDuration", - "Probably a number of seconds? Only works if \"--traceFile\" is specified.", - "number" + "Automatically quit interface after duration. Only works if \"--traceFile\" is specified.", + "seconds" ); QCommandLineOption clockSkewOption( "clockSkew", @@ -271,7 +271,7 @@ int main(int argc, const char* argv[]) { parser.addOption(responseTokensOption); parser.addOption(displayNameOption); parser.addOption(overrideScriptsPathOption); - parser.addOption(defaultScriptOverrideOption); + parser.addOption(defaultScriptsOverrideOption); parser.addOption(traceFileOption); parser.addOption(traceDurationOption); parser.addOption(clockSkewOption); From 917ee269d442adc222c344a5a758fd13ca1d015c Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Sun, 21 Nov 2021 06:18:36 -0800 Subject: [PATCH 20/22] Swapped functions back. --- interface/src/Application.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 567207cb31f..93666ec5a70 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5816,10 +5816,10 @@ void Application::resumeAfterLoginDialogActionTaken() { // if the --scripts command-line argument was used. if (_overrideDefaultScriptsLocation && _defaultScriptsLocation.exists()) { - scriptEngines->loadScripts(); + scriptEngines->loadDefaultScripts(); scriptEngines->defaultScriptsLocationOverridden(true); } else { - scriptEngines->loadDefaultScripts(); + scriptEngines->loadScripts(); } } From 4c7854a63d2073c01eefa0426272766c67afa13f Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Sun, 21 Nov 2021 07:15:49 -0800 Subject: [PATCH 21/22] Added warning that --scripts does not seem to work. --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index a173ef45f99..6a37f33506a 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -110,7 +110,7 @@ int main(int argc, const char* argv[]) { ); QCommandLineOption scriptsOption( "scripts", - "Set path for defaultScripts. These are probably scripts that run automatically.", + "Set path for defaultScripts. These are probably scripts that run automatically. This parameter does not seem to work.", "dir" ); QCommandLineOption allowMultipleInstancesOption( From 3a2646e56bbde7d33b24b80fd7f0d44490b702ec Mon Sep 17 00:00:00 2001 From: Penguin-Guru Date: Wed, 1 Dec 2021 14:49:34 -0800 Subject: [PATCH 22/22] Added warning that --no-launcher supposedly does not work. --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 6a37f33506a..4de77ffe190 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -180,7 +180,7 @@ int main(int argc, const char* argv[]) { // Below are undocumented. QCommandLineOption noLauncherOption( "no-launcher", - "Do not execute the launcher." + "Supposedly does something for the server, unrelated to the application launcher. The feature may never have been implemented." ); QCommandLineOption overrideScriptsPathOption( "overrideScriptsPath",