Showing the changes to interface/src/Application.cpp (1 of 134 files). Show all
Unified · Split
| @@ -23,6 +23,7 @@ · 22 unmodified lines | ||
| 23 | 23 | // include this before QGLWidget, which includes an earlier version of OpenGL |
| 24 | 24 | #include "InterfaceConfig.h" |
| 25 | 25 | |
| 26 | +#include <QAbstractNativeEventFilter> | |
| 26 | 27 | #include <QActionGroup> |
| 27 | 28 | #include <QColorDialog> |
| 28 | 29 | #include <QDesktopWidget> |
| @@ -81,13 +82,15 @@ · 52 unmodified lines | ||
| 81 | 82 | #include <UUID.h> |
| 82 | 83 | |
| 83 | 84 | #include "Application.h" |
| 84 | −#include "Audio.h" | |
| 85 | +#include "AudioClient.h" | |
| 85 | 86 | #include "InterfaceVersion.h" |
| 86 | 87 | #include "LODManager.h" |
| 87 | 88 | #include "Menu.h" |
| 88 | 89 | #include "ModelUploader.h" |
| 89 | 90 | #include "Util.h" |
| 90 | 91 | |
| 92 | +#include "avatar/AvatarManager.h" | |
| 93 | + | |
| 91 | 94 | #include "audio/AudioToolBox.h" |
| 92 | 95 | #include "audio/AudioIOStatsRenderer.h" |
| 93 | 96 | #include "audio/AudioScope.h" |
| @@ -127,8 +130,6 @@ · 33 unmodified lines | ||
| 127 | 130 | #include "ui/StandAloneJSConsole.h" |
| 128 | 131 | #include "ui/Stats.h" |
| 129 | 132 | |
| 130 | − | |
| 131 | − | |
| 132 | 133 | using namespace std; |
| 133 | 134 | |
| 134 | 135 | // Starfield information |
| @@ -144,6 +145,37 @@ const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::D · 9 unmodified lines | ||
| 144 | 145 | |
| 145 | 146 | const QString DEFAULT_SCRIPTS_JS_URL = "http://s3.amazonaws.com/hifi-public/scripts/defaultScripts.js"; |
| 146 | 147 | |
| 148 | +#ifdef Q_OS_WIN | |
| 149 | +class MyNativeEventFilter : public QAbstractNativeEventFilter { | |
| 150 | +public: | |
| 151 | + static MyNativeEventFilter& getInstance() { | |
| 152 | + static MyNativeEventFilter staticInstance; | |
| 153 | + return staticInstance; | |
| 154 | + } | |
| 155 | + | |
| 156 | + bool nativeEventFilter(const QByteArray &eventType, void* msg, long* result) Q_DECL_OVERRIDE { | |
| 157 | + if (eventType == "windows_generic_MSG") { | |
| 158 | + MSG* message = (MSG*)msg; | |
| 159 | + if (message->message == UWM_IDENTIFY_INSTANCES) { | |
| 160 | + *result = UWM_IDENTIFY_INSTANCES; | |
| 161 | + return true; | |
| 162 | + } | |
| 163 | + if (message->message == WM_SHOWWINDOW) { | |
| 164 | + Application::getInstance()->getWindow()->showNormal(); | |
| 165 | + } | |
| 166 | + if (message->message == WM_COPYDATA) { | |
| 167 | + COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)(message->lParam); | |
| 168 | + QUrl url = QUrl((const char*)(pcds->lpData)); | |
| 169 | + if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) { | |
| 170 | + DependencyManager::get<AddressManager>()->handleLookupString(url.toString()); | |
| 171 | + } | |
| 172 | + } | |
| 173 | + } | |
| 174 | + return false; | |
| 175 | + } | |
| 176 | +}; | |
| 177 | +#endif | |
| 178 | + | |
| 147 | 179 | void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { |
| 148 | 180 | QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message); |
| 149 | 181 | |
| @@ -163,6 +195,7 @@ bool setupEssentials(int& argc, char** argv) { · 13 unmodified lines | ||
| 163 | 195 | QCoreApplication::setApplicationVersion(BUILD_VERSION); |
| 164 | 196 | |
| 165 | 197 | DependencyManager::registerInheritance<LimitedNodeList, NodeList>(); |
| 198 | + DependencyManager::registerInheritance<AvatarHashMap, AvatarManager>(); | |
| 166 | 199 | |
| 167 | 200 | // Set dependencies |
| 168 | 201 | auto glCanvas = DependencyManager::set<GLCanvas>(); |
| @@ -171,7 +204,7 @@ bool setupEssentials(int& argc, char** argv) { · 2 unmodified lines | ||
| 171 | 204 | auto geometryCache = DependencyManager::set<GeometryCache>(); |
| 172 | 205 | auto glowEffect = DependencyManager::set<GlowEffect>(); |
| 173 | 206 | auto faceshift = DependencyManager::set<Faceshift>(); |
| 174 | − auto audio = DependencyManager::set<Audio>(); | |
| 207 | + auto audio = DependencyManager::set<AudioClient>(); | |
| 175 | 208 | auto audioScope = DependencyManager::set<AudioScope>(); |
| 176 | 209 | auto audioIOStatsRenderer = DependencyManager::set<AudioIOStatsRenderer>(); |
| 177 | 210 | auto deferredLightingEffect = DependencyManager::set<DeferredLightingEffect>(); |
| @@ -182,6 +215,7 @@ bool setupEssentials(int& argc, char** argv) { · 4 unmodified lines | ||
| 182 | 215 | auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>(); |
| 183 | 216 | auto modelBlender = DependencyManager::set<ModelBlender>(); |
| 184 | 217 | auto audioToolBox = DependencyManager::set<AudioToolBox>(); |
| 218 | + auto avatarManager = DependencyManager::set<AvatarManager>(); | |
| 185 | 219 | auto lodManager = DependencyManager::set<LODManager>(); |
| 186 | 220 | auto jsConsole = DependencyManager::set<StandAloneJSConsole>(); |
| 187 | 221 | auto dialogsManager = DependencyManager::set<DialogsManager>(); |
| @@ -242,9 +276,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 54 unmodified lines | ||
| 242 | 276 | _aboutToQuit(false), |
| 243 | 277 | _notifiedPacketVersionMismatchThisDomain(false) |
| 244 | 278 | { |
| 279 | +#ifdef Q_OS_WIN | |
| 280 | + installNativeEventFilter(&MyNativeEventFilter::getInstance()); | |
| 281 | +#endif | |
| 282 | + | |
| 245 | 283 | _logger = new FileLogger(this); // After setting organization name in order to get correct directory |
| 246 | 284 | qInstallMessageHandler(messageHandler); |
| 247 | − | |
| 285 | + | |
| 248 | 286 | QFontDatabase::addApplicationFont(PathUtils::resourcesPath() + "styles/Inconsolata.otf"); |
| 249 | 287 | _window->setWindowTitle("Interface"); |
| 250 | 288 | |
| @@ -253,7 +291,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 2 unmodified lines | ||
| 253 | 291 | auto glCanvas = DependencyManager::get<GLCanvas>(); |
| 254 | 292 | auto nodeList = DependencyManager::get<NodeList>(); |
| 255 | 293 | |
| 256 | − _myAvatar = _avatarManager.getMyAvatar(); | |
| 294 | + _myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); | |
| 257 | 295 | |
| 258 | 296 | _applicationStartupTime = startup_time; |
| 259 | 297 | |
| @@ -284,9 +322,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 24 unmodified lines | ||
| 284 | 322 | QThread* audioThread = new QThread(this); |
| 285 | 323 | audioThread->setObjectName("Audio Thread"); |
| 286 | 324 | |
| 287 | − auto audioIO = DependencyManager::get<Audio>(); | |
| 325 | + auto audioIO = DependencyManager::get<AudioClient>(); | |
| 326 | + | |
| 327 | + audioIO->setPositionGetter(getPositionForAudio); | |
| 328 | + audioIO->setOrientationGetter(getOrientationForAudio); | |
| 329 | + | |
| 288 | 330 | audioIO->moveToThread(audioThread); |
| 289 | − connect(audioThread, &QThread::started, audioIO.data(), &Audio::start); | |
| 331 | + connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start); | |
| 290 | 332 | connect(audioIO.data(), SIGNAL(muteToggled()), this, SLOT(audioMuteToggled())); |
| 291 | 333 | |
| 292 | 334 | audioThread->start(); |
| @@ -330,9 +372,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 37 unmodified lines | ||
| 330 | 372 | auto dialogsManager = DependencyManager::get<DialogsManager>(); |
| 331 | 373 | connect(&accountManager, &AccountManager::authRequired, dialogsManager.data(), &DialogsManager::showLoginDialog); |
| 332 | 374 | connect(&accountManager, &AccountManager::usernameChanged, this, &Application::updateWindowTitle); |
| 333 | − | |
| 334 | − // once we have a profile in account manager make sure we generate a new keypair | |
| 335 | − connect(&accountManager, &AccountManager::profileChanged, &accountManager, &AccountManager::generateNewKeypair); | |
| 336 | 375 | |
| 337 | 376 | // set the account manager's root URL and trigger a login request if we don't have the access token |
| 338 | 377 | accountManager.setAuthURL(DEFAULT_NODE_AUTH_URL); |
| @@ -497,7 +536,7 @@ Application::~Application() { · 158 unmodified lines | ||
| 497 | 536 | // kill any audio injectors that are still around |
| 498 | 537 | AudioScriptingInterface::getInstance().stopAllInjectors(); |
| 499 | 538 | |
| 500 | − auto audioIO = DependencyManager::get<Audio>(); | |
| 539 | + auto audioIO = DependencyManager::get<AudioClient>(); | |
| 501 | 540 | |
| 502 | 541 | // stop the audio process |
| 503 | 542 | QMetaObject::invokeMethod(audioIO.data(), "stop", Qt::BlockingQueuedConnection); |
| @@ -706,7 +745,7 @@ void Application::runTests() { · 202 unmodified lines | ||
| 706 | 745 | void Application::audioMuteToggled() { |
| 707 | 746 | QAction* muteAction = Menu::getInstance()->getActionForOption(MenuOption::MuteAudio); |
| 708 | 747 | Q_CHECK_PTR(muteAction); |
| 709 | − muteAction->setChecked(DependencyManager::get<Audio>()->isMuted()); | |
| 748 | + muteAction->setChecked(DependencyManager::get<AudioClient>()->isMuted()); | |
| 710 | 749 | } |
| 711 | 750 | |
| 712 | 751 | void Application::aboutApp() { |
| @@ -1566,13 +1605,16 @@ bool Application::exportEntities(const QString& filename, float x, float y, floa · 853 unmodified lines | ||
| 1566 | 1605 | } |
| 1567 | 1606 | |
| 1568 | 1607 | void Application::loadSettings() { |
| 1569 | − DependencyManager::get<Audio>()->loadSettings(); | |
| 1608 | + | |
| 1609 | + DependencyManager::get<AudioClient>()->loadSettings(); | |
| 1610 | + | |
| 1570 | 1611 | Menu::getInstance()->loadSettings(); |
| 1571 | 1612 | _myAvatar->loadData(); |
| 1572 | 1613 | } |
| 1573 | 1614 | |
| 1574 | 1615 | void Application::saveSettings() { |
| 1575 | − DependencyManager::get<Audio>()->saveSettings(); | |
| 1616 | + DependencyManager::get<AudioClient>()->saveSettings(); | |
| 1617 | + | |
| 1576 | 1618 | Menu::getInstance()->saveSettings(); |
| 1577 | 1619 | _myAvatar->saveData(); |
| 1578 | 1620 | } |
| @@ -1606,7 +1648,7 @@ void Application::init() { · 27 unmodified lines | ||
| 1606 | 1648 | DependencyManager::get<AmbientOcclusionEffect>()->init(this); |
| 1607 | 1649 | |
| 1608 | 1650 | // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager |
| 1609 | − _avatarManager.init(); | |
| 1651 | + DependencyManager::get<AvatarManager>()->init(); | |
| 1610 | 1652 | _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); |
| 1611 | 1653 | |
| 1612 | 1654 | _mirrorCamera.setMode(CAMERA_MODE_MIRROR); |
| @@ -1985,7 +2027,7 @@ void Application::update(float deltaTime) { · 372 unmodified lines | ||
| 1985 | 2027 | |
| 1986 | 2028 | updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process... |
| 1987 | 2029 | |
| 1988 | − _avatarManager.updateOtherAvatars(deltaTime); //loop through all the other avatars and simulate them... | |
| 2030 | + DependencyManager::get<AvatarManager>()->updateOtherAvatars(deltaTime); //loop through all the other avatars and simulate them... | |
| 1989 | 2031 | |
| 1990 | 2032 | updateMetavoxels(deltaTime); // update metavoxels |
| 1991 | 2033 | updateCamera(deltaTime); // handle various camera tweaks like off axis projection |
| @@ -2012,7 +2054,7 @@ void Application::update(float deltaTime) { · 20 unmodified lines | ||
| 2012 | 2054 | { |
| 2013 | 2055 | PerformanceTimer perfTimer("myAvatar"); |
| 2014 | 2056 | updateMyAvatarLookAtPosition(); |
| 2015 | − updateMyAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes | |
| 2057 | + DependencyManager::get<AvatarManager>()->updateMyAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes | |
| 2016 | 2058 | } |
| 2017 | 2059 | |
| 2018 | 2060 | { |
| @@ -2069,31 +2111,11 @@ void Application::update(float deltaTime) { · 50 unmodified lines | ||
| 2069 | 2111 | if (sinceLastNack > TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS) { |
| 2070 | 2112 | _lastSendDownstreamAudioStats = now; |
| 2071 | 2113 | |
| 2072 | − QMetaObject::invokeMethod(DependencyManager::get<Audio>().data(), "sendDownstreamAudioStatsPacket", Qt::QueuedConnection); | |
| 2114 | + QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "sendDownstreamAudioStatsPacket", Qt::QueuedConnection); | |
| 2073 | 2115 | } |
| 2074 | 2116 | } |
| 2075 | 2117 | } |
| 2076 | 2118 | |
| 2077 | −void Application::updateMyAvatar(float deltaTime) { | |
| 2078 | − bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | |
| 2079 | − PerformanceWarning warn(showWarnings, "Application::updateMyAvatar()"); | |
| 2080 | − | |
| 2081 | − _myAvatar->update(deltaTime); | |
| 2082 | − | |
| 2083 | − quint64 now = usecTimestampNow(); | |
| 2084 | − quint64 dt = now - _lastSendAvatarDataTime; | |
| 2085 | − | |
| 2086 | − if (dt > MIN_TIME_BETWEEN_MY_AVATAR_DATA_SENDS) { | |
| 2087 | − // send head/hand data to the avatar mixer and voxel server | |
| 2088 | − PerformanceTimer perfTimer("send"); | |
| 2089 | − QByteArray packet = byteArrayWithPopulatedHeader(PacketTypeAvatarData); | |
| 2090 | − packet.append(_myAvatar->toByteArray()); | |
| 2091 | − controlledBroadcastToNodes(packet, NodeSet() << NodeType::AvatarMixer); | |
| 2092 | − | |
| 2093 | − _lastSendAvatarDataTime = now; | |
| 2094 | − } | |
| 2095 | −} | |
| 2096 | − | |
| 2097 | 2119 | int Application::sendNackPackets() { |
| 2098 | 2120 | |
| 2099 | 2121 | if (Menu::getInstance()->isOptionChecked(MenuOption::DisableNackPackets)) { |
| @@ -2533,7 +2555,7 @@ void Application::updateShadowMap() { · 433 unmodified lines | ||
| 2533 | 2555 | |
| 2534 | 2556 | { |
| 2535 | 2557 | PerformanceTimer perfTimer("avatarManager"); |
| 2536 | − _avatarManager.renderAvatars(Avatar::SHADOW_RENDER_MODE); | |
| 2558 | + DependencyManager::get<AvatarManager>()->renderAvatars(Avatar::SHADOW_RENDER_MODE); | |
| 2537 | 2559 | } |
| 2538 | 2560 | |
| 2539 | 2561 | { |
| @@ -2789,7 +2811,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 249 unmodified lines | ||
| 2789 | 2811 | bool mirrorMode = (theCamera.getMode() == CAMERA_MODE_MIRROR); |
| 2790 | 2812 | { |
| 2791 | 2813 | PerformanceTimer perfTimer("avatars"); |
| 2792 | − _avatarManager.renderAvatars(mirrorMode ? Avatar::MIRROR_RENDER_MODE : Avatar::NORMAL_RENDER_MODE, | |
| 2814 | + DependencyManager::get<AvatarManager>()->renderAvatars(mirrorMode ? Avatar::MIRROR_RENDER_MODE : Avatar::NORMAL_RENDER_MODE, | |
| 2793 | 2815 | false, selfAvatarOnly); |
| 2794 | 2816 | } |
| 2795 | 2817 | |
| @@ -2804,7 +2826,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 8 unmodified lines | ||
| 2804 | 2826 | |
| 2805 | 2827 | { |
| 2806 | 2828 | PerformanceTimer perfTimer("avatarsPostLighting"); |
| 2807 | − _avatarManager.renderAvatars(mirrorMode ? Avatar::MIRROR_RENDER_MODE : Avatar::NORMAL_RENDER_MODE, | |
| 2829 | + DependencyManager::get<AvatarManager>()->renderAvatars(mirrorMode ? Avatar::MIRROR_RENDER_MODE : Avatar::NORMAL_RENDER_MODE, | |
| 2808 | 2830 | true, selfAvatarOnly); |
| 2809 | 2831 | } |
| 2810 | 2832 | |
| @@ -3068,7 +3090,7 @@ void Application::resetSensors() { · 257 unmodified lines | ||
| 3068 | 3090 | |
| 3069 | 3091 | _myAvatar->reset(); |
| 3070 | 3092 | |
| 3071 | − QMetaObject::invokeMethod(DependencyManager::get<Audio>().data(), "reset", Qt::QueuedConnection); | |
| 3093 | + QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "reset", Qt::QueuedConnection); | |
| 3072 | 3094 | } |
| 3073 | 3095 | |
| 3074 | 3096 | static void setShortcutsEnabled(QWidget* widget, bool enabled) { |
| @@ -3208,7 +3230,7 @@ void Application::nodeKilled(SharedNodePointer node) { · 133 unmodified lines | ||
| 3208 | 3230 | _entityEditSender.nodeKilled(node); |
| 3209 | 3231 | |
| 3210 | 3232 | if (node->getType() == NodeType::AudioMixer) { |
| 3211 | − QMetaObject::invokeMethod(DependencyManager::get<Audio>().data(), "audioMixerKilled"); | |
| 3233 | + QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "audioMixerKilled"); | |
| 3212 | 3234 | } |
| 3213 | 3235 | |
| 3214 | 3236 | if (node->getType() == NodeType::EntityServer) { |
| @@ -3251,7 +3273,7 @@ void Application::nodeKilled(SharedNodePointer node) { · 36 unmodified lines | ||
| 3251 | 3273 | |
| 3252 | 3274 | } else if (node->getType() == NodeType::AvatarMixer) { |
| 3253 | 3275 | // our avatar mixer has gone away - clear the hash of avatars |
| 3254 | − _avatarManager.clearOtherAvatars(); | |
| 3276 | + DependencyManager::get<AvatarManager>()->clearOtherAvatars(); | |
| 3255 | 3277 | } |
| 3256 | 3278 | } |
| 3257 | 3279 | |
| @@ -3400,7 +3422,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 142 unmodified lines | ||
| 3400 | 3422 | |
| 3401 | 3423 | // hook our avatar and avatar hash map object into this script engine |
| 3402 | 3424 | scriptEngine->setAvatarData(_myAvatar, "MyAvatar"); // leave it as a MyAvatar class to expose thrust features |
| 3403 | − scriptEngine->setAvatarHashMap(&_avatarManager, "AvatarList"); | |
| 3425 | + scriptEngine->setAvatarHashMap(DependencyManager::get<AvatarManager>().data(), "AvatarList"); | |
| 3404 | 3426 | |
| 3405 | 3427 | scriptEngine->registerGlobalObject("Camera", &_myCamera); |
| 3406 | 3428 | |
| @@ -3441,7 +3463,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 34 unmodified lines | ||
| 3441 | 3463 | scriptEngine->registerGlobalObject("GlobalServices", GlobalServicesScriptingInterface::getInstance()); |
| 3442 | 3464 | qScriptRegisterMetaType(scriptEngine, DownloadInfoResultToScriptValue, DownloadInfoResultFromScriptValue); |
| 3443 | 3465 | |
| 3444 | − scriptEngine->registerGlobalObject("AvatarManager", &_avatarManager); | |
| 3466 | + scriptEngine->registerGlobalObject("AvatarManager", DependencyManager::get<AvatarManager>().data()); | |
| 3445 | 3467 | |
| 3446 | 3468 | scriptEngine->registerGlobalObject("Joysticks", &JoystickScriptingInterface::getInstance()); |
| 3447 | 3469 | qScriptRegisterMetaType(scriptEngine, joystickToScriptValue, joystickFromScriptValue); |
| @@ -3741,10 +3763,6 @@ void Application::toggleLogDialog() { · 293 unmodified lines | ||
| 3741 | 3763 | } |
| 3742 | 3764 | } |
| 3743 | 3765 | |
| 3744 | −void Application::initAvatarAndViewFrustum() { | |
| 3745 | − updateMyAvatar(0.0f); | |
| 3746 | −} | |
| 3747 | − | |
| 3748 | 3766 | void Application::checkVersion() { |
| 3749 | 3767 | QNetworkRequest latestVersionRequest((QUrl(CHECK_VERSION_URL))); |
| 3750 | 3768 | latestVersionRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); |