-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Application.cpp #939
Open
HifiExperiments
wants to merge
6
commits into
overte-org:master
Choose a base branch
from
HifiExperiments:application
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e6d7ffd
refactor application.cpp
HifiExperiments 0f16e8c
CR
HifiExperiments 16e7b8d
I fucked up the merge but this was 74's fix for the QML header names
HifiExperiments 2345bcc
fix audio devices + login popup
HifiExperiments c6731d2
Merge remote-tracking branch 'overte/master' into application
HifiExperiments 7f4efaf
Merge remote-tracking branch 'overte/master' into application
HifiExperiments File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some places, for example in
EntitySendThread
there'swithReadLock
aroundfindEntityID
call.getEntityModelProvider
is called fromGraphics.canUpdateModel
so it can be called from any script engine thread. I wonder if it needs a lock here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe as a later PR we should do a thread safety audit of all the places where entity tree is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wow great catch.
EntityTree::findEntityByID
actually callsEntityTree::findEntityByEntityItemID
which does internally use a read lock, but thenEntityTreeRenderer::renderableForEntityId
looks like it needs it? I filed #1015