Overte C++ Documentation
Application.h
1 //
2 // Application.h
3 // interface/src
4 //
5 // Created by Andrzej Kapolka on 5/10/13.
6 // Copyright 2013 High Fidelity, Inc.
7 // Copyright 2020 Vircadia contributors.
8 // Copyright 2022-2023 Overte e.V.
9 //
10 // Distributed under the Apache License, Version 2.0.
11 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
12 // SPDX-License-Identifier: Apache-2.0
13 //
14 
15 #ifndef hifi_Application_h
16 #define hifi_Application_h
17 
18 #include <QtWidgets/QApplication>
19 
20 #include <AbstractScriptingServicesInterface.h>
21 #include <AbstractUriHandler.h>
22 #include <AbstractViewStateInterface.h>
23 #include <AvatarHashMap.h>
24 #include <EntityEditPacketSender.h>
25 #include <ModerationFlags.h>
26 #include <OctreeQuery.h>
27 #include <PhysicsEngine.h>
28 #include <ShapeManager.h>
29 #include <TouchEvent.h>
30 #include <ui-plugins/PluginContainer.h>
31 
32 #include "avatar/MyAvatar.h"
33 #include "ConnectionMonitor.h"
34 #include "CursorManager.h"
35 #include "FancyCamera.h"
36 #include "graphics/GraphicsEngine.h"
37 #include "LoginStateManager.h"
38 #include "octree/OctreePacketProcessor.h"
39 #include "PerformanceManager.h"
40 #include "RefreshRateManager.h"
41 #include "scripting/DialogsManagerScriptingInterface.h"
42 #include "ui/ApplicationOverlay.h"
43 #include "ui/OverlayConductor.h"
44 #include "ui/overlays/Overlays.h"
45 #include "VisionSqueeze.h"
46 #include "workload/GameWorkload.h"
47 #ifndef USE_GL
48 #include "VKCanvas.h"
49 #endif
50 
52 class AudioInjector;
53 class CompositorHelper;
54 class ControllerScriptingInterface;
55 class DiscordPresence;
56 class EntityScriptServerLogDialog;
57 class FileLogger;
58 class GLCanvas;
59 class KeyboardMouseDevice;
60 class LogDialog;
61 class MainWindow;
62 class ModalDialogListener;
63 class OffscreenUi;
64 class TouchscreenDevice;
65 class TouchscreenVirtualPadDevice;
66 class QCommandLineParser;
67 class QGestureEvent;
68 class QQmlContext;
69 class QQuickItem;
70 
71 namespace controller {
72  class StateController;
73 }
74 
75 class Application;
76 #if defined(qApp)
77 #undef qApp
78 #endif
79 #define qApp (static_cast<Application*>(QCoreApplication::instance()))
80 
81 class Application : public QApplication,
84  public AbstractUriHandler,
85  public PluginContainer
86 {
87  Q_OBJECT
88 
89 public:
90  Application(
91  int& argc, char** argv,
92  const QCommandLineParser& parser,
93  QElapsedTimer& startup_time
94  );
95  ~Application();
96 
106  void initialize(const QCommandLineParser &parser);
107 
108  MainWindow* getWindow() const { return _window; }
109  virtual QThread* getMainThread() override { return thread(); }
110 
111  bool isAboutToQuit() const { return _aboutToQuit; }
112  bool isServerlessMode() const;
113  bool isInterstitialMode() const { return _interstitialMode; }
114  bool failedToConnectToEntityServer() const { return _failedToConnectToEntityServer; }
115 
116  void setPreviousSessionCrashed(bool value) { _previousSessionCrashed = value; }
117 
118  // Return an HTTP User-Agent string with OS and device information.
119  Q_INVOKABLE QString getUserAgent();
120 
121  PerformanceManager& getPerformanceManager() { return _performanceManager; }
122  RefreshRateManager& getRefreshRateManager() { return _refreshRateManager; }
123  float getGameLoopRate() const { return _gameLoopCounter.rate(); }
124 
125 #ifndef Q_OS_ANDROID
126  FileLogger* getLogger() const { return _logger; }
127 #endif
128 
129  bool getUseDiscordPresence() const { return _useDiscordPresence.get(); }
130  void setUseDiscordPresence(bool enable);
131 
132  QString getPreviousScriptLocation() { return _previousScriptLocation.get(); }
133  void setPreviousScriptLocation(const QString& previousScriptLocation) { _previousScriptLocation.set(previousScriptLocation); }
134 
135  void replaceDomainContent(const QString& url, const QString& itemName);
136 
137  void openDirectory(const QString& path);
138 
139  void overrideEntry() { _overrideEntry = true; }
140  void forceDisplayName(const QString& displayName) { getMyAvatar()->setDisplayName(displayName); }
141  void forceLoginWithTokens(const QString& tokens);
142  void setConfigFileURL(const QString& fileUrl);
143 
144  void loadAvatarScripts(const QVector<QString>& urls);
145  void unloadAvatarScripts();
146 
147  Q_INVOKABLE void copyToClipboard(const QString& text);
148 
149  Q_INVOKABLE void setMinimumGPUTextureMemStabilityCount(int stabilityCount) { _minimumGPUTextureMemSizeStabilityCount = stabilityCount; }
150 
151  virtual ControllerScriptingInterface* getControllerScriptingInterface() { return _controllerScriptingInterface; }
152  virtual void registerScriptEngineWithApplicationServices(ScriptManagerPointer& scriptManager) override;
153 
154  // used by preferences and HMDScriptingInterface...
155  VisionSqueeze& getVisionSqueeze() { return _visionSqueeze; }
156 
157 
158  // UI
159  virtual ui::Menu* getPrimaryMenu() override;
160  virtual void showDisplayPluginsTools(bool show) override;
161 #ifdef USE_GL
162  virtual GLWidget* getPrimaryWidget() override;
163 #else
164  virtual VKWidget* getPrimaryWidget() override;
165 #endif
166  virtual MainWindow* getPrimaryWindow() override;
167  virtual QOpenGLContext* getPrimaryContext() override;
168  virtual bool isForeground() const override;
169 
170  bool hasFocus() const;
171  void setFocus();
172  void raise();
173 
174  void showCursor(const Cursor::Icon& cursor);
175 
176  Overlays& getOverlays() { return _overlays; }
177  ApplicationOverlay& getApplicationOverlay() { return *_applicationOverlay; }
178  const ApplicationOverlay& getApplicationOverlay() const { return *_applicationOverlay; }
179  CompositorHelper& getApplicationCompositor() const;
180 
181  virtual PickRay computePickRay(float x, float y) const override;
182 
183  static void setupQmlSurface(QQmlContext* surfaceContext, bool setAdditionalContextProperties);
184 
185  float getHMDTabletScale() { return _hmdTabletScale.get(); }
186  void setHMDTabletScale(float hmdTabletScale) { _hmdTabletScale.set(hmdTabletScale); }
187  float getDesktopTabletScale() { return _desktopTabletScale.get(); }
188  void setDesktopTabletScale(float desktopTabletScale) { _desktopTabletScale.set(desktopTabletScale); }
189 
190  bool getDesktopTabletBecomesToolbarSetting() { return _desktopTabletBecomesToolbarSetting.get(); }
191  void setDesktopTabletBecomesToolbarSetting(bool value);
192  bool getHmdTabletBecomesToolbarSetting() { return _hmdTabletBecomesToolbarSetting.get(); }
193  void setHmdTabletBecomesToolbarSetting(bool value);
194 
195  bool getLogWindowOnTopSetting() { return _keepLogWindowOnTop.get(); }
196  void setLogWindowOnTopSetting(bool keepOnTop) { _keepLogWindowOnTop.set(keepOnTop); }
197  bool getPreferStylusOverLaser() { return _preferStylusOverLaserSetting.get(); }
198  void setPreferStylusOverLaser(bool value) { _preferStylusOverLaserSetting.set(value); }
199  bool getPreferAvatarFingerOverStylus() { return _preferAvatarFingerOverStylusSetting.get(); }
200  void setPreferAvatarFingerOverStylus(bool value) { _preferAvatarFingerOverStylusSetting.set(value); }
201 
202  void setMouseCaptureVR(bool value);
203  bool getMouseCaptureVR();
204 
205  bool getMiniTabletEnabled() { return _miniTabletEnabledSetting.get(); }
206  void setMiniTabletEnabled(bool enabled);
207 
208  float getSettingConstrainToolbarPosition() { return _constrainToolbarPosition.get(); }
209  void setSettingConstrainToolbarPosition(bool setting);
210 
211  float getAwayStateWhenFocusLostInVREnabled() { return _awayStateWhenFocusLostInVREnabled.get(); }
212  void setAwayStateWhenFocusLostInVREnabled(bool setting);
213 
214  QUuid getTabletScreenID() const;
215  QUuid getTabletHomeButtonID() const;
216  QUuid getTabletFrameID() const;
217  QVector<QUuid> getTabletIDs() const;
218 
219  void confirmConnectWithoutAvatarEntities();
220 
221  bool getLoginDialogPoppedUp() const { return _loginDialogPoppedUp; }
222  void createLoginDialog();
223  void updateLoginDialogPosition();
224 
225  void createAvatarInputsBar();
226  void destroyAvatarInputsBar();
227 
228 
229  // Plugins
239  void initializePluginManager(const QCommandLineParser& parser);
240 
241  virtual void requestReset() override { resetSensors(false); }
242  virtual bool makeRenderingContextCurrent() override { return true; }
243 
244  static void shutdownPlugins();
245 
246  void initializeDisplayPlugins();
247  virtual DisplayPluginPointer getActiveDisplayPlugin() const override;
248  void setActiveDisplayPlugin(const QString& pluginName);
249 
250  glm::uvec2 getUiSize() const;
251  QRect getRecommendedHUDRect() const;
252  glm::vec2 getDeviceSize() const;
253  bool isThrottleRendering() const;
254  float getTargetRenderFrameRate() const; // frames/second
255 
256  // Check if a headset is connected
257  bool hasRiftControllers();
258  bool hasViveControllers();
259 
260  // the isHMDMode is true whenever we use the interface from an HMD and not a standard flat display
261  // rendering of several elements depend on that
262  // TODO: carry that information on the Camera as a setting
263  virtual bool isHMDMode() const override;
264  glm::mat4 getHMDSensorPose() const;
265  glm::mat4 getEyeOffset(int eye) const;
266  glm::mat4 getEyeProjection(int eye) const;
267 
268 
269  // Graphics
270  void initializeGL();
271  void initializeRenderEngine();
272  void initializeUi();
273 
274  void resizeGL();
275 
276  glm::uvec2 getCanvasSize() const;
277  float getRenderResolutionScale() const;
278 
279  render::ScenePointer getMain3DScene() override { return _graphicsEngine->getRenderScene(); }
280  render::EnginePointer getRenderEngine() override { return _graphicsEngine->getRenderEngine(); }
281  gpu::ContextPointer getGPUContext() const { return _graphicsEngine->getGPUContext(); }
282  float getRenderLoopRate() const { return _graphicsEngine->getRenderLoopRate(); }
283 
284 
285  // Events
286  bool notify(QObject*, QEvent*) override;
287  bool event(QEvent* event) override;
288  bool eventFilter(QObject* object, QEvent* event) override;
289 
290  void postLambdaEvent(const std::function<void()>& f) override;
291  void sendLambdaEvent(const std::function<void()>& f) override;
292  virtual void pushPostUpdateLambda(void* key, const std::function<void()>& func) override;
293 
294 
295  // Camera
296  Camera& getCamera() { return _myCamera; }
297  const Camera& getCamera() const { return _myCamera; }
298  // Represents the current view frustum of the avatar.
299  void copyViewFrustum(ViewFrustum& viewOut) const;
300  // Represents the view frustum of the current rendering pass,
301  // which might be different from the viewFrustum, i.e. shadowmap
302  // passes, mirror window passes, etc
303  void copyDisplayViewFrustum(ViewFrustum& viewOut) const;
304 
305  void updateCamera(RenderArgs& renderArgs, float deltaTime);
306  void updateSecondaryCameraViewFrustum();
307 
308  const ConicalViewFrustums& getConicalViews() const override { return _conicalViews; }
309 
310  float getFieldOfView() { return _fieldOfView.get(); }
311  void setFieldOfView(float fov);
312 
313  bool getCameraClippingEnabled() { return _cameraClippingEnabled.get(); }
314  void setCameraClippingEnabled(bool enabled);
315 
316  void updateMyAvatarLookAtPosition(float deltaTime);
317 
318 
319  // Entities
320  QSharedPointer<EntityTreeRenderer> getEntities() const { return DependencyManager::get<EntityTreeRenderer>(); }
321  EntityTreePointer getEntityClipboard() const { return _entityClipboard; }
322  const OctreePacketProcessor& getOctreePacketProcessor() const { return *_octreeProcessor; }
323  std::shared_ptr<EntityEditPacketSender> getEntityEditPacketSender() { return _entityEditSender; }
324 
325  void setMaxOctreePacketsPerSecond(int maxOctreePPS);
326  int getMaxOctreePacketsPerSecond() const { return _maxOctreePPS; }
327  bool isMissingSequenceNumbers() { return _isMissingSequenceNumbers; }
328 
329  NodeToOctreeSceneStats* getOcteeSceneStats() { return _octreeProcessor->getOctreeSceneStats(); }
330 
331 
332  // Assets
333  virtual bool canAcceptURL(const QString& url) const override;
334  virtual bool acceptURL(const QString& url, bool defaultUpload = false) override;
335 
336 
337  // Physics
338  bool isPhysicsEnabled() const { return _physicsEnabled; }
339  PhysicsEnginePointer getPhysicsEngine() { return _physicsEngine; }
340  const GameWorkload& getGameWorkload() const { return _gameWorkload; }
341 
342  float getNumCollisionObjects() const { return _physicsEngine ? _physicsEngine->getNumCollisionObjects() : 0; }
343  void saveNextPhysicsStats(QString filename) { _physicsEngine->saveNextPhysicsStats(filename); }
344 
345 
346  // Avatar
347  virtual glm::vec3 getAvatarPosition() const override { return getMyAvatar()->getWorldPosition(); }
348 
349  void clearAvatarOverrideUrl() { _avatarOverrideUrl = QUrl(); _saveAvatarOverrideUrl = false; }
350  QUrl getAvatarOverrideUrl() { return _avatarOverrideUrl; }
351  bool getSaveAvatarOverrideUrl() { return _saveAvatarOverrideUrl; }
352 
353  int getOtherAvatarsReplicaCount() { return DependencyManager::get<AvatarHashMap>()->getReplicaCount(); }
354  void setOtherAvatarsReplicaCount(int count) { DependencyManager::get<AvatarHashMap>()->setReplicaCount(count); }
355 
356 
357  // Snapshots
358  using SnapshotOperator = std::tuple<std::function<void(const QImage&)>, float, bool>;
359  void addSnapshotOperator(const SnapshotOperator& snapshotOperator);
360  bool takeSnapshotOperators(std::queue<SnapshotOperator>& snapshotOperators);
361 
362  void takeSnapshot(bool notify, bool includeAnimated = false, float aspectRatio = 0.0f, const QString& filename = QString());
363  void takeSecondaryCameraSnapshot(const bool& notify, const QString& filename = QString());
364  void takeSecondaryCamera360Snapshot(const glm::vec3& cameraPosition,
365  const bool& cubemapOutputFormat,
366  const bool& notify,
367  const QString& filename = QString());
368  void shareSnapshot(const QString& filename, const QUrl& href = QUrl(""));
369 
370 
371 #if defined(Q_OS_ANDROID)
372  void beforeEnterBackground();
373  void enterBackground();
374  void enterForeground();
375  void toggleAwayMode();
376 #endif
377 
378 signals:
379  void svoImportRequested(const QString& url);
380 
381  void fullAvatarURLChanged(const QString& newValue, const QString& modelName);
382 
383  void beforeAboutToQuit();
384  void activeDisplayPluginChanged();
385 
386  void uploadRequest(QString path);
387 
388  void interstitialModeChanged(bool isInInterstitialMode);
389 
390  void loginDialogFocusEnabled();
391  void loginDialogFocusDisabled();
392 
393  void miniTabletEnabledChanged(bool enabled);
394  void awayStateWhenFocusLostInVRChanged(bool enabled);
395 
396  void darkThemePreferenceChanged(bool useDarkTheme);
397  void menuBarVisibilityChanged(bool visible);
398 
399 public slots:
400  void updateThreadPoolCount() const;
401 
402  static void gotoTutorial();
403  void goToErrorDomainURL(QUrl errorDomainURL);
404  void handleLocalServerConnection() const;
405  void readArgumentsFromLocalSocket() const;
406  void showUrlHandler(const QUrl& url);
407 
408 #if (PR_BUILD || DEV_BUILD)
409  void sendWrongProtocolVersionsSignature(bool checked) { ::sendWrongProtocolVersionsSignature(checked); }
410 #endif
411 
412  void hmdVisibleChanged(bool visible);
413 
414  void reloadResourceCaches();
415 
416  void updateHeartbeat() const;
417 
418  static void deadlockApplication();
419  static void unresponsiveApplication(); // cause main thread to be unresponsive for 35 seconds
420  void crashOnShutdown(); // used to test "shutdown" crash annotation.
421 
422  void rotationModeChanged() const;
423 
424  void setIsServerlessMode(bool serverlessDomain);
425  std::map<QString, QString> prepareServerlessDomainContents(QUrl domainURL, QByteArray data);
426 
427  void loadServerlessDomain(QUrl domainURL);
428  void loadErrorDomain(QUrl domainURL);
429  void setIsInterstitialMode(bool interstitialMode);
430 
431  void updateVerboseLogging();
432 
433  void setCachebustRequire();
434 
435  QString getGraphicsCardType();
436  bool gpuTextureMemSizeStable();
437 
438  Q_INVOKABLE SharedSoundPointer getSampleSound() const { return _sampleSound; }
439 
440  static void runTests();
441 
442  // UI
443  void showDialog(const QUrl& widgetUrl, const QUrl& tabletUrl, const QString& name) const;
444  Q_INVOKABLE void loadDialog();
445  Q_INVOKABLE void loadScriptURLDialog() const;
446  void toggleLogDialog();
447  void recreateLogWindow(int);
448  void toggleEntityScriptServerLogDialog();
449  Q_INVOKABLE void showAssetServerWidget(QString filePath = "");
450  Q_INVOKABLE void loadAddAvatarBookmarkDialog() const;
451  Q_INVOKABLE void loadAvatarBrowser() const;
452 
453  void showLoginScreen();
454  static void showHelp();
455 
456  void updateSystemTabletMode();
457 
458  void captureMouseChanged(bool captureMouse);
459  void toggleOverlays();
460  void setOverlaysVisible(bool visible);
461  Q_INVOKABLE void centerUI() { _overlayConductor.centerUI(); }
462 
463  void addAssetToWorldMessageClose();
464 
465  void loadLODToolsDialog();
466  void loadEntityStatisticsDialog();
467  void loadDomainConnectionDialog();
468  void showScriptLogs();
469 
470  const QString getPreferredCursor() const { return _preferredCursor.get(); }
471  void setPreferredCursor(const QString& cursor);
472 
473  bool getDarkThemePreference() const { return _darkTheme.get(); }
474  void setDarkThemePreference(bool value);
475 
476  bool getMenuBarVisible() const { return _menuBarVisible.get(); }
477  void setMenuBarVisible(bool visible);
478 
488  Q_INVOKABLE void showVRKeyboardForHudUI(bool show);
489 
490 
491  // Plugins
492  void resetSensors(bool andReload = false);
493 
494 
495  // Entities
496  QVector<EntityItemID> pasteEntities(const QString& entityHostType, float x, float y, float z);
497  bool exportEntities(const QString& filename, const QVector<QUuid>& entityIDs, const glm::vec3* givenOffset = nullptr);
498  bool exportEntities(const QString& filename, float x, float y, float z, float scale);
499  bool importEntities(const QString& url, const bool isObservable = true, const qint64 callerId = -1);
500 
501  void setKeyboardFocusHighlight(const glm::vec3& position, const glm::quat& rotation, const glm::vec3& dimensions);
502  QUuid getKeyboardFocusEntity() const { return _keyboardFocusedEntity.get(); } // thread-safe
503  void setKeyboardFocusEntity(const QUuid& id);
504 
505 
506  // Assets
507  void addAssetToWorldFromURL(QString url);
508  void addAssetToWorldFromURLRequestFinished();
509  void addAssetToWorld(QString filePath, QString zipFile, bool isZip = false);
510  void addAssetToWorldUnzipFailure(QString filePath);
511  void addAssetToWorldWithNewMapping(QString filePath, QString mapping, int copy, bool isZip = false);
512  void addAssetToWorldUpload(QString filePath, QString mapping, bool isZip = false);
513  void addAssetToWorldSetMapping(QString filePath, QString mapping, QString hash, bool isZip = false);
514  void addAssetToWorldAddEntity(QString filePath, QString mapping);
515 
516  void handleUnzip(QString sourceFile, QStringList destinationFile, bool autoAdd, bool isZip);
517 
518  ArchiveDownloadInterface* getFileDownloadInterface() { return _fileDownload; }
519 
520  static void packageModel();
521 
522 
523  // Camera
524  void cycleCamera();
525  void cameraModeChanged();
526  void cameraMenuChanged();
527 
528  void changeViewAsNeeded(float boomLength);
529 
530 
531  // Physics
532  void resetPhysicsReadyInformation();
533 
534 
535 private slots:
536  void onAboutToQuit();
537 
538  void loadSettings(const QCommandLineParser& parser);
539  void saveSettings() const;
540  void setFailedToConnectToEntityServer() { _failedToConnectToEntityServer = true; }
541 
542  bool acceptSnapshot(const QString& urlString);
543 
544  void setSessionUUID(const QUuid& sessionUUID) const;
545 
546  void domainURLChanged(QUrl domainURL);
547  void domainConnectionRefused(const QString& reasonMessage, int reason, const QString& extraInfo);
548 
549  void updateWindowTitle() const;
550  void nodeAdded(SharedNodePointer node);
551  void nodeActivated(SharedNodePointer node);
552  void nodeKilled(SharedNodePointer node);
553 
554  void handleSandboxStatus(QNetworkReply* reply);
555 
556 
557  // UI
558  void onDesktopRootItemCreated(QQuickItem* qmlContext);
559  void onDesktopRootContextCreated(QQmlContext* qmlContext);
560  void showDesktop();
561 
562  void notifyPacketVersionMismatch();
563 
564  bool askToSetAvatarUrl(const QString& url);
565  bool askToLoadScript(const QString& scriptFilenameOrURL);
566  bool askToReplaceDomainContent(const QString& url);
567 
568  void onDismissedLoginDialog();
569 
570 
571  // Entities
572  void clearDomainOctreeDetails(bool clearAll = true);
573  void resettingDomain();
574 
575 
576  // Events
577  void onPresent(quint32 frameCount);
578 
579  void activeChanged(Qt::ApplicationState state);
580  void windowMinimizedChanged(bool minimized);
581 
582 
583  // Plugins
584  void updateDisplayMode();
585  void switchDisplayMode();
586  void setDisplayPlugin(DisplayPluginPointer newPlugin);
587 
588 
589  // Assets
590  void addAssetToWorldCheckModelSize();
591  void onAssetToWorldMessageBoxClosed();
592  void addAssetToWorldInfoTimeout();
593  void addAssetToWorldErrorTimeout();
594 
595 
596  // Physics
597  void setShowBulletWireframe(bool value) { _physicsEngine->setShowBulletWireframe(value); }
598  void setShowBulletAABBs(bool value) { _physicsEngine->setShowBulletAABBs(value); }
599  void setShowBulletContactPoints(bool value) { _physicsEngine->setShowBulletContactPoints(value); }
600  void setShowBulletConstraints(bool value) { _physicsEngine->setShowBulletConstraints(value); }
601  void setShowBulletConstraintLimits(bool value) { _physicsEngine->setShowBulletConstraintLimits(value); }
602 
603  void setShowTrackedObjects(bool value) { _showTrackedObjects = value; }
604 
605 private:
606  void cleanupBeforeQuit();
607 
608  void idle();
609  void update(float deltaTime);
610  void updateLOD(float deltaTime) const;
611  void updateThreads(float deltaTime);
612 
613  void userKickConfirmation(const QUuid& nodeID, unsigned int banFlags = ModerationFlags::getDefaultBanFlags());
614 
615 
616  // Setup
617  void init();
618  void setupSignalsAndOperators();
619 
620 
621  // UI
622  bool initMenu();
623  void pauseUntilLoginDetermined();
624  void resumeAfterLoginDialogActionTaken();
625 
626  static QSharedPointer<OffscreenUi> getOffscreenUI();
627 
628  void updateDialogs(float deltaTime) const;
629 
630  void maybeToggleMenuVisible(QMouseEvent* event) const;
631  void toggleTabletUI(bool shouldOpen = false) const;
632 
633  bool shouldCaptureMouse() const;
634  void checkChangeCursor();
635 
636  void addAssetToWorldInfo(QString modelName, QString infoText);
637  void addAssetToWorldInfoClear(QString modelName);
638  void addAssetToWorldInfoDone(QString modelName);
639  void addAssetToWorldError(QString modelName, QString errorText);
640 
641 
642  // Events
643  void resizeEvent(QResizeEvent* size) { resizeGL(); }
644 
645  void keyPressEvent(QKeyEvent* event);
646  void keyReleaseEvent(QKeyEvent* event);
647 
648  void focusOutEvent(QFocusEvent* event);
649  void synthesizeKeyReleasEvents();
650 
651  void mouseMoveEvent(QMouseEvent* event);
652  void mousePressEvent(QMouseEvent* event);
653  void mouseDoublePressEvent(QMouseEvent* event);
654  void mouseReleaseEvent(QMouseEvent* event);
655 
656  void touchBeginEvent(QTouchEvent* event);
657  void touchEndEvent(QTouchEvent* event);
658  void touchUpdateEvent(QTouchEvent* event);
659  void touchGestureEvent(QGestureEvent* event);
660 
661  void wheelEvent(QWheelEvent* event) const;
662  void dropEvent(QDropEvent* event);
663  static void dragEnterEvent(QDragEnterEvent* event) { event->acceptProposedAction(); }
664 
665  bool handleInputMethodEventForFocusedEntity(QEvent* event);
666  bool handleKeyEventForFocusedEntity(QEvent* event);
667  bool handleFileOpenEvent(QFileOpenEvent* event);
668 
669  void processDriverBlocklistReply(const QString& fullDriverToTest, const QString& os, const QString& vendor, const QString& renderer, const QString& api,
670  const QString& driver);
671 
672 
673  // Entities
674  void queryOctree(NodeType_t serverType, PacketType packetType);
675 
676  int sendNackPackets();
677 
678 
679  // Graphics
680  void updateRenderArgs(float deltaTime);
681 
682 
683  // Plugins
684  void startHMDStandBySession();
685  void endHMDSession();
686 
687 
688  // Assets
689  bool importJSONFromURL(const QString& urlString);
690  bool importSVOFromURL(const QString& urlString);
691  bool importFromZIP(const QString& filePath);
692  bool importImage(const QString& urlString);
693 
694 
695  // Avatars
696  std::shared_ptr<MyAvatar> getMyAvatar() const;
697  void checkSkeleton() const;
698 
699  void queryAvatars();
700 
701 
702  // Physics
703  void tryToEnablePhysics();
704 
705 
706  // Member Variables
707  // The window needs to be initialized early as other initializers try to access it
708 #ifndef USE_GL
709  VKWindow* _vkWindow;
710  QWidget *_vkWindowWrapper;
711 #endif
712  MainWindow* _window;
713  // _isMenuInitialized: used to initialize menu early enough before it's needed by other
714  // initializers. Fixes a deadlock issue with recent Qt versions.
715  bool _isMenuInitialized;
716 
717  bool _startUpFinished { false };
718  bool _quitWhenFinished { false };
719  bool _crashOnShutdown { false };
720  bool _aboutToQuit { false };
721  bool _previousSessionCrashed { false };
722 
723  QUrl _urlParam;
724  bool _overrideEntry { false };
725  bool _settingsLoaded { false };
726 
727  bool _domainLoadingInProgress { false };
728  bool _interstitialMode { false };
729  bool _interstitialModeEnabled { false };
730 
731  PerformanceManager _performanceManager;
732  RefreshRateManager _refreshRateManager;
733  GameWorkload _gameWorkload;
734 
735  ConnectionMonitor _connectionMonitor;
736 
737 #ifndef Q_OS_ANDROID
738  FileLogger* _logger { nullptr };
739 #endif
740 
741  QElapsedTimer& _sessionRunTimer;
742  QElapsedTimer _lastTimeUpdated;
743  QTimer _locationUpdateTimer;
744  QTimer _minimizedWindowTimer;
745  // Frame Rate Measurement
746  RateCounter<500> _gameLoopCounter;
747 
748  using SteadyClock = std::chrono::steady_clock;
749  using TimePoint = SteadyClock::time_point;
750  TimePoint _queryExpiry;
751 
752  quint64 _lastNackTime;
753  quint64 _lastSendDownstreamAudioStats;
754 
755  bool _notifiedPacketVersionMismatchThisDomain { false };
756 
757  QDir _defaultScriptsLocation;
758  // If above is only set by parameter, below is unnecessary.
759  bool _overrideDefaultScriptsLocation;
760 
761  qint64 _gpuTextureMemSizeStabilityCount { 0 };
762  qint64 _gpuTextureMemSizeAtLastCheck { 0 };
763  int _minimumGPUTextureMemSizeStabilityCount { 30 };
764 
765  SharedSoundPointer _sampleSound { nullptr };
766 
767  VisionSqueeze _visionSqueeze;
768 
769  DiscordPresence* _discordPresence { nullptr };
770  Setting::Handle<bool> _useDiscordPresence;
771 
772  Setting::Handle<bool> _firstRun;
773  Setting::Handle<QString> _previousScriptLocation;
774  Setting::Handle<int> _previousPreferredDisplayMode;
775 
776 
777  // UI
778 #ifdef USE_GL
779  GLCanvas* _primaryWidget{ nullptr };
780 #else
781  VKCanvas* _primaryWidget{ nullptr };
782 #endif
783 
784  Overlays _overlays;
785  std::shared_ptr<ApplicationOverlay> _applicationOverlay;
786  OverlayConductor _overlayConductor;
787 
788  mutable QRecursiveMutex _changeCursorLock;
789  Qt::CursorShape _desiredCursor { Qt::BlankCursor };
790  bool _cursorNeedsChanging { false };
791  bool _useSystemCursor { false };
792 
793  DialogsManagerScriptingInterface* _dialogsManagerScriptingInterface;
794 
795  QPointer<LogDialog> _logDialog;
796  QPointer<EntityScriptServerLogDialog> _entityScriptServerLogDialog;
797  ModalDialogListener* _confirmConnectWithoutAvatarEntitiesDialog { nullptr };
798 
799  QUuid _loginDialogID;
800  QUuid _avatarInputsBarID;
801  LoginStateManager _loginStateManager;
802 
803  QQuickItem* _addAssetToWorldMessageBox { nullptr };
804  QStringList _addAssetToWorldInfoKeys; // Model name
805  QStringList _addAssetToWorldInfoMessages; // Info message
806  QTimer _addAssetToWorldInfoTimer;
807  QTimer _addAssetToWorldErrorTimer;
808 
809  ArchiveDownloadInterface* _fileDownload;
810 
811  bool _loginDialogPoppedUp { false };
812  bool _developerMenuVisible { false };
813  bool _noLoginSuggestion { false };
814 
815  bool _resumeAfterLoginDialogActionTaken_WasPostponed { false };
816  bool _resumeAfterLoginDialogActionTaken_SafeToRun { false };
817 
818  bool _isForeground { true }; // starts out assumed to be in foreground
819 
820  Setting::Handle<float> _hmdTabletScale;
821  Setting::Handle<float> _desktopTabletScale;
822  Setting::Handle<bool> _desktopTabletBecomesToolbarSetting;
823  Setting::Handle<bool> _hmdTabletBecomesToolbarSetting;
824  Setting::Handle<bool> _preferStylusOverLaserSetting;
825  Setting::Handle<bool> _preferAvatarFingerOverStylusSetting;
826  Setting::Handle<bool> _defaultMouseCaptureVR;
827  Setting::Handle<bool> _constrainToolbarPosition;
828  Setting::Handle<bool> _awayStateWhenFocusLostInVREnabled;
829  Setting::Handle<QString> _preferredCursor;
830  // TODO Qt6: Qt5 doesn't have anything for system theme preferences, Qt6.5+ does
831  Setting::Handle<bool> _darkTheme;
832  Setting::Handle<bool> _miniTabletEnabledSetting;
833  Setting::Handle<bool> _keepLogWindowOnTop { "keepLogWindowOnTop", false };
834  Setting::Handle<bool> _menuBarVisible { "menuBarVisible", true };
835 
836  void updateThemeColors();
837 
838 
839  // Plugins
840  DisplayPluginPointer _displayPlugin;
841  mutable std::mutex _displayPluginLock;
842 
843  std::shared_ptr<controller::StateController> _applicationStateDevice; // Default ApplicationDevice reflecting the state of different properties of the session
844  std::shared_ptr<KeyboardMouseDevice> _keyboardMouseDevice; // Default input device, the good old keyboard mouse and maybe touchpad
845  std::shared_ptr<TouchscreenDevice> _touchscreenDevice; // the good old touchscreen
846  std::shared_ptr<TouchscreenVirtualPadDevice> _touchscreenVirtualPadDevice;
847  bool _keyboardDeviceHasFocus { true };
848 
849  ControllerScriptingInterface* _controllerScriptingInterface { nullptr };
850 
851  DisplayPluginPointer _autoSwitchDisplayModeSupportedHMDPlugin { nullptr };
852  QString _autoSwitchDisplayModeSupportedHMDPluginName;
853  bool _previousHMDWornStatus { false };
854 
855 
856  // Events
857  QHash<int, QKeyEvent> _keysPressed;
858  TouchEvent _lastTouchEvent;
859  quint64 _lastAcceptedKeyPress { 0 };
860 
861  ThreadSafeValueCache<EntityItemID> _keyboardFocusedEntity;
862 
863  bool _reticleClickPressed { false };
864  bool _keyboardFocusWaitingOnRenderable { false };
865 
866  bool _captureMouse { false };
867  bool _ignoreMouseMove { false };
868  QPointF _mouseCaptureTarget { NAN, NAN };
869 
870  std::map<void*, std::function<void()>> _postUpdateLambdas;
871  std::mutex _postUpdateLambdasLock;
872 
873  std::atomic<bool> _pendingIdleEvent { true };
874 
875 
876  // Entities
877  EntityTreePointer _entityClipboard;
878 
879  std::shared_ptr<OctreePacketProcessor> _octreeProcessor;
880  std::shared_ptr<EntityEditPacketSender> _entityEditSender;
881  OctreeQuery _octreeQuery { true }; // NodeData derived class for querying octee cells from octree servers
882  bool _enableProcessOctreeThread { true };
883 
884  uint32_t _fullSceneCounterAtLastPhysicsCheck { 0 }; // _fullSceneReceivedCounter last time we checked physics ready
885 
886  mutable QTimer _entityServerConnectionTimer;
887 
888  QUuid _keyboardFocusHighlightID;
889 
890  bool _failedToConnectToEntityServer { false };
891  bool _isMissingSequenceNumbers { false };
892 
893  Setting::Handle<int> _maxOctreePacketsPerSecond;
894  int _maxOctreePPS { DEFAULT_MAX_OCTREE_PPS };
895 
896 
897  // Assets
898  typedef bool (Application::*AcceptURLMethod)(const QString&);
899  static const std::vector<std::pair<QString, AcceptURLMethod>> _acceptedExtensions;
900 
901  QTimer _addAssetToWorldResizeTimer;
902  QHash<QUuid, int> _addAssetToWorldResizeList;
903 
904 
905  // Camera
906  FancyCamera _myCamera; // My view onto the world
907 
908  CameraMode _previousCameraMode;
909  glm::vec3 _thirdPersonHMDCameraBoom { 0.0f, 0.0f, -1.0f };
910  bool _thirdPersonHMDCameraBoomValid { true };
911  float _scaleMirror { 1.0f };
912  float _mirrorYawOffset { 0.0f };
913  float _raiseMirror { 0.0f };
914 
915  mutable QRecursiveMutex _viewMutex;
916  ViewFrustum _viewFrustum; // current state of view frustum, perspective, orientation, etc.
917  ViewFrustum _displayViewFrustum;
918 
919  ConicalViewFrustums _conicalViews;
920  ConicalViewFrustums _lastQueriedViews; // last views used to query servers
921 
922  Setting::Handle<float> _fieldOfView;
923  Setting::Handle<float> _cameraClippingEnabled;
924 
925  bool _prevCameraClippingEnabled { false };
926  unsigned int _cameraClippingRayPickID;
927 
928 
929  // Graphics
930  std::shared_ptr<GraphicsEngine> _graphicsEngine;
931  glm::uvec2 _renderResolution;
932 
933  Setting::Handle<QString> _prevCheckedDriver { "prevCheckedDriver", "" };
934  bool _isGLInitialized { false };
935 
936 
937  // Avatars
938  QString _previousAvatarSkeletonModel;
939  float _previousAvatarTargetScale;
940 
941  QUrl _avatarOverrideUrl;
942  bool _saveAvatarOverrideUrl { false };
943 
944 
945  // Physics
946  ShapeManager _shapeManager;
947  PhysicalEntitySimulationPointer _entitySimulation;
948  PhysicsEnginePointer _physicsEngine;
949 
950  bool _physicsEnabled { false };
951  // This is needed so that physics do not get re-enabled before safe landing starts when moving from
952  // serverless to domain server.
953  // It's set to true by Application::clearDomainOctreeData and is cleared by Application::setIsServerlessMode
954  bool _waitForServerlessToBeSet { true };
955 
956  bool _showTrackedObjects { false };
957  bool _prevShowTrackedObjects { false };
958 
959 
960  // Snapshots
961  std::mutex _snapshotMutex;
962  std::queue<SnapshotOperator> _snapshotOperators;
963  bool _hasPrimarySnapshot { false };
964 };
965 #endif // hifi_Application_h
quint8 NodeType_t
An 8-bit value identifying the type of a node - domain server, audio mixer, etc.
Definition: NodeType.h:22
Interface provided by Application to other objects that need access to scripting services of the appl...
Definition: AbstractScriptingServicesInterface.h:26
virtual void registerScriptEngineWithApplicationServices(ScriptManagerPointer &scriptEngine)=0
Registers application specific services with a script engine.
Interface provided by Application to other objects that need access to the current view state details...
Definition: AbstractViewStateInterface.h:31
The ArchiveDownloadInterface API provides some facilities for working with the file system.
Definition: ArchiveDownloadInterface.h:27
customized canvas that simply forwards requests/events to the singleton application
Definition: GLCanvas.h:18
customized canvas that simply forwards requests/events to the singleton application
Definition: GLWidget.h:22
Definition: OctreeSceneStats.h:274
Definition: OctreePacketProcessor.h:25
Represents a display or device event to the scripting engine. Exposed as TouchEvent
Definition: TouchEvent.h:30
customized canvas that simply forwards requests/events to the singleton application
Definition: VKCanvas.h:22
customized canvas that simply forwards requests/events to the singleton application
Definition: VKWidget.h:31