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