Skip to content

Commit

Permalink
refactor application.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
HifiExperiments committed Apr 4, 2024
1 parent f1475e4 commit 65e9f88
Show file tree
Hide file tree
Showing 32 changed files with 9,736 additions and 9,437 deletions.
10,653 changes: 1,753 additions & 8,900 deletions interface/src/Application.cpp

Large diffs are not rendered by default.

1,037 changes: 527 additions & 510 deletions interface/src/Application.h

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions interface/src/ApplicationEventHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// ApplicationEventHandler.h
// interface/src
//
// Split from Application.cpp by HifiExperiments on 3/30/24
// Created by Andrzej Kapolka on 5/10/13.
// Copyright 2013 High Fidelity, Inc.
// Copyright 2020 Vircadia contributors.
// Copyright 2022-2023 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// SPDX-License-Identifier: Apache-2.0
//

#ifndef hifi_ApplicationEventHandler_h
#define hifi_ApplicationEventHandler_h

#include <QtCore/QAbstractNativeEventFilter>
#include <qsystemdetection.h>

#include <MainWindow.h>

#include "Application.h"

#ifdef Q_OS_WIN
static const UINT UWM_IDENTIFY_INSTANCES =
RegisterWindowMessage("UWM_IDENTIFY_INSTANCES_{8AB82783-B74A-4258-955B-8188C22AA0D6}_" + qgetenv("USERNAME"));
static const UINT UWM_SHOW_APPLICATION =
RegisterWindowMessage("UWM_SHOW_APPLICATION_{71123FD6-3DA8-4DC1-9C27-8A12A6250CBA}_" + qgetenv("USERNAME"));

class MyNativeEventFilter : public QAbstractNativeEventFilter {
public:
static MyNativeEventFilter& getInstance() {
static MyNativeEventFilter staticInstance;
return staticInstance;
}

bool nativeEventFilter(const QByteArray &eventType, void* msg, long* result) Q_DECL_OVERRIDE {
if (eventType == "windows_generic_MSG") {
MSG* message = (MSG*)msg;

if (message->message == UWM_IDENTIFY_INSTANCES) {
*result = UWM_IDENTIFY_INSTANCES;
return true;
}

if (message->message == UWM_SHOW_APPLICATION) {
MainWindow* applicationWindow = qApp->getWindow();
if (applicationWindow->isMinimized()) {
applicationWindow->showNormal(); // Restores to windowed or maximized state appropriately.
}
qApp->setActiveWindow(applicationWindow); // Flashes the taskbar icon if not focus.
return true;
}

// Attempting to close MIDI interfaces of a hot-unplugged device can result in audio-driver deadlock.
// Detecting MIDI devices that have been added/removed after starting Inteface has been disabled.
// https://support.microsoft.com/en-us/help/4460006/midi-device-app-hangs-when-former-midi-api-is-used
#if 0
if (message->message == WM_DEVICECHANGE) {
const float MIN_DELTA_SECONDS = 2.0f; // de-bounce signal
static float lastTriggerTime = 0.0f;
const float deltaSeconds = secTimestampNow() - lastTriggerTime;
lastTriggerTime = secTimestampNow();
if (deltaSeconds > MIN_DELTA_SECONDS) {
Midi::USBchanged(); // re-scan the MIDI bus
}
}
#endif
}
return false;
}
};
#endif

#endif // hifi_ApplicationEventHandler_h
67 changes: 67 additions & 0 deletions interface/src/ApplicationMeshProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// ApplicationMeshProvider.h
// interface/src
//
// Split from Application.cpp by HifiExperiments on 3/30/24
// Created by Andrzej Kapolka on 5/10/13.
// Copyright 2013 High Fidelity, Inc.
// Copyright 2020 Vircadia contributors.
// Copyright 2022-2023 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// SPDX-License-Identifier: Apache-2.0
//

#ifndef hifi_ApplicationMeshProvider_h
#define hifi_ApplicationMeshProvider_h

#include <graphics/Forward.h>

class ApplicationMeshProvider : public scriptable::ModelProviderFactory {
public:
virtual scriptable::ModelProviderPointer lookupModelProvider(const QUuid& uuid) override {
bool success;
if (auto nestable = DependencyManager::get<SpatialParentFinder>()->find(uuid, success).lock()) {
auto type = nestable->getNestableType();
#ifdef SCRIPTABLE_MESH_DEBUG
qCDebug(interfaceapp) << "ApplicationMeshProvider::lookupModelProvider" << uuid << SpatiallyNestable::nestableTypeToString(type);
#endif
switch (type) {
case NestableType::Entity:
return getEntityModelProvider(static_cast<EntityItemID>(uuid));
case NestableType::Avatar:
return getAvatarModelProvider(uuid);
}
}
return nullptr;
}

private:
scriptable::ModelProviderPointer getEntityModelProvider(EntityItemID entityID) {
scriptable::ModelProviderPointer provider;
auto entityTreeRenderer = qApp->getEntities();
auto entityTree = entityTreeRenderer->getTree();
if (auto entity = entityTree->findEntityByID(entityID)) {
if (auto renderer = entityTreeRenderer->renderableForEntityId(entityID)) {
provider = std::dynamic_pointer_cast<scriptable::ModelProvider>(renderer);
provider->modelProviderType = NestableType::Entity;
} else {
qCWarning(interfaceapp) << "no renderer for entity ID" << entityID.toString();
}
}
return provider;
}

scriptable::ModelProviderPointer getAvatarModelProvider(QUuid sessionUUID) {
scriptable::ModelProviderPointer provider;
auto avatarManager = DependencyManager::get<AvatarManager>();
if (auto avatar = avatarManager->getAvatarBySessionID(sessionUUID)) {
provider = std::dynamic_pointer_cast<scriptable::ModelProvider>(avatar);
provider->modelProviderType = NestableType::Avatar;
}
return provider;
}
};

#endif // hifi_ApplicationMeshProvider_h
Loading

0 comments on commit 65e9f88

Please sign in to comment.