History

Initial effort to reorganize the startup code.

This is intended to make things like plugin initialization more sane, and make Qt happier. Qt wants QApplication to start as soon as possible, but our code's attempt to load the entire world in the Application constructor doesn't quite mesh with this. This is an effort to first create Application much earlier, and do as little as possible in the constructor, moving almost all initialization to a later init function. A later stage would be to split the giant mess of init code into more digestible sections that run in some sort of logical order.

Dale Glass committed 3 years ago

Commit 059600e1 parent 85a99873 files · +87 −25Browse files

Showing the changes to interface/src/Application.cpp (1 of 3 files). Show all

Unified · Split

interface/src/Application.cpp+28−9
@@ -724,7 +724,7 @@ extern DisplayPluginList getDisplayPlugins(); · 723 unmodified lines
724extern InputPluginList getInputPlugins();724extern InputPluginList getInputPlugins();
725extern void saveInputPluginSettings(const InputPluginList& plugins);725extern void saveInputPluginSettings(const InputPluginList& plugins);
726 726
727bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, bool runningMarkerExisted) {727bool setupEssentials(const QCommandLineParser& parser, bool runningMarkerExisted) {
728 qInstallMessageHandler(messageHandler);728 qInstallMessageHandler(messageHandler);
729 729
730 730
@@ -743,6 +743,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, b · 12 unmodified lines
743 743
744 bool previousSessionCrashed { false };744 bool previousSessionCrashed { false };
745 if (!inTestMode) {745 if (!inTestMode) {
746 // TODO: FIX
746 previousSessionCrashed = CrashRecoveryHandler::checkForResetSettings(runningMarkerExisted, suppressPrompt);747 previousSessionCrashed = CrashRecoveryHandler::checkForResetSettings(runningMarkerExisted, suppressPrompt);
747 }748 }
748 749
@@ -764,6 +765,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, b · 15 unmodified lines
764 }765 }
765 766
766 // Tell the plugin manager about our statically linked plugins767 // Tell the plugin manager about our statically linked plugins
768 DependencyManager::set<PathUtils>();
767 DependencyManager::set<ScriptInitializers>();769 DependencyManager::set<ScriptInitializers>();
768 DependencyManager::set<PluginManager>();770 DependencyManager::set<PluginManager>();
769 auto pluginManager = PluginManager::getInstance();771 auto pluginManager = PluginManager::getInstance();
@@ -777,6 +779,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, b · 7 unmodified lines
777 oculusPlatform->init();779 oculusPlatform->init();
778 }780 }
779 781
782
780 PROFILE_SET_THREAD_NAME("Main Thread");783 PROFILE_SET_THREAD_NAME("Main Thread");
781 784
782#if defined(Q_OS_WIN)785#if defined(Q_OS_WIN)
@@ -993,8 +996,7 @@ bool Application::initMenu() { · 210 unmodified lines
993Application::Application(996Application::Application(
994 int& argc, char** argv,997 int& argc, char** argv,
995 const QCommandLineParser& parser,998 const QCommandLineParser& parser,
996 QElapsedTimer& startupTimer,999 QElapsedTimer& startupTimer
997 bool runningMarkerExisted
998) :1000) :
999 QApplication(argc, argv),1001 QApplication(argc, argv),
1000 _window(new MainWindow(desktop())),1002 _window(new MainWindow(desktop())),
@@ -1004,7 +1006,7 @@ Application::Application( · 3 unmodified lines
1004#ifndef Q_OS_ANDROID1006#ifndef Q_OS_ANDROID
1005 _logger(new FileLogger(this)),1007 _logger(new FileLogger(this)),
1006#endif1008#endif
1007 _previousSessionCrashed(setupEssentials(argc, argv, parser, runningMarkerExisted)),1009 _previousSessionCrashed(setupEssentials(parser, false)),
1008 _entitySimulation(std::make_shared<PhysicalEntitySimulation>()),1010 _entitySimulation(std::make_shared<PhysicalEntitySimulation>()),
1009 _physicsEngine(std::make_shared<PhysicsEngine>(Vectors::ZERO)),1011 _physicsEngine(std::make_shared<PhysicsEngine>(Vectors::ZERO)),
1010 _entityClipboard(std::make_shared<EntityTree>()),1012 _entityClipboard(std::make_shared<EntityTree>()),
@@ -1032,12 +1034,22 @@ Application::Application( · 21 unmodified lines
1032 _snapshotSound(nullptr),1034 _snapshotSound(nullptr),
1033 _sampleSound(nullptr)1035 _sampleSound(nullptr)
1034{1036{
1035 auto steamClient = PluginManager::getInstance()->getSteamClientPlugin();
1036 setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning()));
1037 setProperty(hifi::properties::CRASHED, _previousSessionCrashed);1037 setProperty(hifi::properties::CRASHED, _previousSessionCrashed);
1038 1038
1039 LogHandler::getInstance().moveToThread(thread());1039 LogHandler::getInstance().moveToThread(thread());
1040 LogHandler::getInstance().setupRepeatedMessageFlusher();1040 LogHandler::getInstance().setupRepeatedMessageFlusher();
1041}
1042
1043void Application::initialize(const QCommandLineParser &parser) {
1044
1045 //qCDebug(interfaceapp) << "Setting up essentials";
1046 //setupEssentials(parser, _previousSessionCrashed);
1047 qCDebug(interfaceapp) << "Initializing application";
1048
1049
1050 auto steamClient = PluginManager::getInstance()->getSteamClientPlugin();
1051 setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning()));
1052
1041 1053
1042 {1054 {
1043 if (parser.isSet("testScript")) {1055 if (parser.isSet("testScript")) {
@@ -2375,7 +2387,7 @@ Application::Application( · 1331 unmodified lines
2375 2387
2376 connect(this, &Application::applicationStateChanged, this, &Application::activeChanged);2388 connect(this, &Application::applicationStateChanged, this, &Application::activeChanged);
2377 connect(_window, SIGNAL(windowMinimizedChanged(bool)), this, SLOT(windowMinimizedChanged(bool)));2389 connect(_window, SIGNAL(windowMinimizedChanged(bool)), this, SLOT(windowMinimizedChanged(bool)));
2378 qCDebug(interfaceapp, "Startup time: %4.2f seconds.", (double)startupTimer.elapsed() / 1000.0);2390 qCDebug(interfaceapp, "Startup time: %4.2f seconds.", (double)_sessionRunTimer.elapsed() / 1000.0);
2379 2391
2380 EntityTreeRenderer::setEntitiesShouldFadeFunction([this]() {2392 EntityTreeRenderer::setEntitiesShouldFadeFunction([this]() {
2381 SharedNodePointer entityServerNode = DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::EntityServer);2393 SharedNodePointer entityServerNode = DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::EntityServer);
@@ -4201,7 +4213,9 @@ bool Application::handleFileOpenEvent(QFileOpenEvent* fileEvent) { · 1819 unmodified lines
4201}4213}
4202 4214
4203bool Application::notify(QObject * object, QEvent * event) {4215bool Application::notify(QObject * object, QEvent * event) {
4204 if (thread() == QThread::currentThread()) {4216 if (thread() == QThread::currentThread() && _profilingInitialized ) {
4217 // _profilingInitialized gets set once we're reading for profiling.
4218 // this prevents a deadlock due to profiling not working yet
4205 PROFILE_RANGE_IF_LONGER(app, "notify", 2)4219 PROFILE_RANGE_IF_LONGER(app, "notify", 2)
4206 return QApplication::notify(object, event);4220 return QApplication::notify(object, event);
4207 }4221 }
@@ -8762,7 +8776,11 @@ void Application::sendLambdaEvent(const std::function<void()>& f) { · 4554 unmodified lines
8762 }8776 }
8763}8777}
8764 8778
8765void Application::initPlugins(const QCommandLineParser& parser) {8779void Application::configurePlugins(const QCommandLineParser& parser) {
8780 // This must be a member function -- PluginManager must exist, and for that
8781 // QApplication must exist, or it can't find the plugin path, as QCoreApplication:applicationDirPath
8782 // won't work yet.
8783
8766 if (parser.isSet("display")) {8784 if (parser.isSet("display")) {
8767 auto preferredDisplays = parser.value("display").split(',', Qt::SkipEmptyParts);8785 auto preferredDisplays = parser.value("display").split(',', Qt::SkipEmptyParts);
8768 qInfo() << "Setting prefered display plugins:" << preferredDisplays;8786 qInfo() << "Setting prefered display plugins:" << preferredDisplays;
@@ -8780,6 +8798,7 @@ void Application::initPlugins(const QCommandLineParser& parser) { · 11 unmodified lines
8780 qInfo() << "Disabling following input plugins:" << disabledInputs;8798 qInfo() << "Disabling following input plugins:" << disabledInputs;
8781 PluginManager::getInstance()->disableInputs(disabledInputs);8799 PluginManager::getInstance()->disableInputs(disabledInputs);
8782 }8800 }
8801
8783}8802}
8784 8803
8785void Application::shutdownPlugins() {8804void Application::shutdownPlugins() {