Showing the changes to interface/src/Application.cpp (1 of 329 files). Show all
Unified · Split
| @@ -967,7 +967,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 966 unmodified lines | |||
| 967 | _entitySimulation(new PhysicalEntitySimulation()), | 967 | _entitySimulation(new PhysicalEntitySimulation()), |
| 968 | _physicsEngine(new PhysicsEngine(Vectors::ZERO)), | 968 | _physicsEngine(new PhysicsEngine(Vectors::ZERO)), |
| 969 | _entityClipboard(new EntityTree()), | 969 | _entityClipboard(new EntityTree()), |
| 970 | _lastQueriedTime(usecTimestampNow()), | ||
| 971 | _previousScriptLocation("LastScriptLocation", DESKTOP_LOCATION), | 970 | _previousScriptLocation("LastScriptLocation", DESKTOP_LOCATION), |
| 972 | _fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES), | 971 | _fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES), |
| 973 | _hmdTabletScale("hmdTabletScale", DEFAULT_HMD_TABLET_SCALE_PERCENT), | 972 | _hmdTabletScale("hmdTabletScale", DEFAULT_HMD_TABLET_SCALE_PERCENT), |
| @@ -1325,6 +1324,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 351 unmodified lines | |||
| 1325 | 1324 | ||
| 1326 | // Create the main thread context, the GPU backend, and the display plugins | 1325 | // Create the main thread context, the GPU backend, and the display plugins |
| 1327 | initializeGL(); | 1326 | initializeGL(); |
| 1327 | DependencyManager::get<TextureCache>()->setGPUContext(_gpuContext); | ||
| 1328 | qCDebug(interfaceapp, "Initialized Display."); | 1328 | qCDebug(interfaceapp, "Initialized Display."); |
| 1329 | // Create the rendering engine. This can be slow on some machines due to lots of | 1329 | // Create the rendering engine. This can be slow on some machines due to lots of |
| 1330 | // GPU pipeline creation. | 1330 | // GPU pipeline creation. |
| @@ -5081,7 +5081,7 @@ void Application::reloadResourceCaches() { · 3750 unmodified lines | |||
| 5081 | resetPhysicsReadyInformation(); | 5081 | resetPhysicsReadyInformation(); |
| 5082 | 5082 | ||
| 5083 | // Query the octree to refresh everything in view | 5083 | // Query the octree to refresh everything in view |
| 5084 | _lastQueriedTime = 0; | 5084 | _queryExpiry = SteadyClock::now(); |
| 5085 | _octreeQuery.incrementConnectionID(); | 5085 | _octreeQuery.incrementConnectionID(); |
| 5086 | 5086 | ||
| 5087 | queryOctree(NodeType::EntityServer, PacketType::EntityQuery); | 5087 | queryOctree(NodeType::EntityServer, PacketType::EntityQuery); |
| @@ -5224,13 +5224,12 @@ void Application::updateSecondaryCameraViewFrustum() { · 136 unmodified lines | |||
| 5224 | auto renderConfig = _renderEngine->getConfiguration(); | 5224 | auto renderConfig = _renderEngine->getConfiguration(); |
| 5225 | assert(renderConfig); | 5225 | assert(renderConfig); |
| 5226 | auto camera = dynamic_cast<SecondaryCameraJobConfig*>(renderConfig->getConfig("SecondaryCamera")); | 5226 | auto camera = dynamic_cast<SecondaryCameraJobConfig*>(renderConfig->getConfig("SecondaryCamera")); |
| 5227 | assert(camera); | ||
| 5228 | 5227 | ||
| 5229 | if (!camera->isEnabled()) { | 5228 | if (!camera || !camera->isEnabled()) { |
| 5230 | _hasSecondaryViewFrustum = false; | ||
| 5231 | return; | 5229 | return; |
| 5232 | } | 5230 | } |
| 5233 | 5231 | ||
| 5232 | ViewFrustum secondaryViewFrustum; | ||
| 5234 | if (camera->mirrorProjection && !camera->attachedEntityId.isNull()) { | 5233 | if (camera->mirrorProjection && !camera->attachedEntityId.isNull()) { |
| 5235 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); | 5234 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); |
| 5236 | auto entityProperties = entityScriptingInterface->getEntityProperties(camera->attachedEntityId); | 5235 | auto entityProperties = entityScriptingInterface->getEntityProperties(camera->attachedEntityId); |
| @@ -5255,36 +5254,37 @@ void Application::updateSecondaryCameraViewFrustum() { · 18 unmodified lines | |||
| 5255 | 5254 | ||
| 5256 | // set frustum position to be mirrored camera and set orientation to mirror's adjusted rotation | 5255 | // set frustum position to be mirrored camera and set orientation to mirror's adjusted rotation |
| 5257 | glm::quat mirrorCameraOrientation = glm::quat_cast(worldFromMirrorRotation); | 5256 | glm::quat mirrorCameraOrientation = glm::quat_cast(worldFromMirrorRotation); |
| 5258 | _secondaryViewFrustum.setPosition(mirrorCameraPositionWorld); | 5257 | secondaryViewFrustum.setPosition(mirrorCameraPositionWorld); |
| 5259 | _secondaryViewFrustum.setOrientation(mirrorCameraOrientation); | 5258 | secondaryViewFrustum.setOrientation(mirrorCameraOrientation); |
| 5260 | 5259 | ||
| 5261 | // build frustum using mirror space translation of mirrored camera | 5260 | // build frustum using mirror space translation of mirrored camera |
| 5262 | float nearClip = mirrorCameraPositionMirror.z + mirrorPropertiesDimensions.z * 2.0f; | 5261 | float nearClip = mirrorCameraPositionMirror.z + mirrorPropertiesDimensions.z * 2.0f; |
| 5263 | glm::vec3 upperRight = halfMirrorPropertiesDimensions - mirrorCameraPositionMirror; | 5262 | glm::vec3 upperRight = halfMirrorPropertiesDimensions - mirrorCameraPositionMirror; |
| 5264 | glm::vec3 bottomLeft = -halfMirrorPropertiesDimensions - mirrorCameraPositionMirror; | 5263 | glm::vec3 bottomLeft = -halfMirrorPropertiesDimensions - mirrorCameraPositionMirror; |
| 5265 | glm::mat4 frustum = glm::frustum(bottomLeft.x, upperRight.x, bottomLeft.y, upperRight.y, nearClip, camera->farClipPlaneDistance); | 5264 | glm::mat4 frustum = glm::frustum(bottomLeft.x, upperRight.x, bottomLeft.y, upperRight.y, nearClip, camera->farClipPlaneDistance); |
| 5266 | _secondaryViewFrustum.setProjection(frustum); | 5265 | secondaryViewFrustum.setProjection(frustum); |
| 5267 | } else { | 5266 | } else { |
| 5268 | if (!camera->attachedEntityId.isNull()) { | 5267 | if (!camera->attachedEntityId.isNull()) { |
| 5269 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); | 5268 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); |
| 5270 | auto entityProperties = entityScriptingInterface->getEntityProperties(camera->attachedEntityId); | 5269 | auto entityProperties = entityScriptingInterface->getEntityProperties(camera->attachedEntityId); |
| 5271 | _secondaryViewFrustum.setPosition(entityProperties.getPosition()); | 5270 | secondaryViewFrustum.setPosition(entityProperties.getPosition()); |
| 5272 | _secondaryViewFrustum.setOrientation(entityProperties.getRotation()); | 5271 | secondaryViewFrustum.setOrientation(entityProperties.getRotation()); |
| 5273 | } else { | 5272 | } else { |
| 5274 | _secondaryViewFrustum.setPosition(camera->position); | 5273 | secondaryViewFrustum.setPosition(camera->position); |
| 5275 | _secondaryViewFrustum.setOrientation(camera->orientation); | 5274 | secondaryViewFrustum.setOrientation(camera->orientation); |
| 5276 | } | 5275 | } |
| 5277 | 5276 | ||
| 5278 | float aspectRatio = (float)camera->textureWidth / (float)camera->textureHeight; | 5277 | float aspectRatio = (float)camera->textureWidth / (float)camera->textureHeight; |
| 5279 | _secondaryViewFrustum.setProjection(camera->vFoV, | 5278 | secondaryViewFrustum.setProjection(camera->vFoV, |
| 5280 | aspectRatio, | 5279 | aspectRatio, |
| 5281 | camera->nearClipPlaneDistance, | 5280 | camera->nearClipPlaneDistance, |
| 5282 | camera->farClipPlaneDistance); | 5281 | camera->farClipPlaneDistance); |
| 5283 | } | 5282 | } |
| 5284 | // Without calculating the bound planes, the secondary camera will use the same culling frustum as the main camera, | 5283 | // Without calculating the bound planes, the secondary camera will use the same culling frustum as the main camera, |
| 5285 | // which is not what we want here. | 5284 | // which is not what we want here. |
| 5286 | _secondaryViewFrustum.calculate(); | 5285 | secondaryViewFrustum.calculate(); |
| 5287 | _hasSecondaryViewFrustum = true; | 5286 | |
| 5287 | _conicalViews.push_back(secondaryViewFrustum); | ||
| 5288 | } | 5288 | } |
| 5289 | 5289 | ||
| 5290 | static bool domainLoadingInProgress = false; | 5290 | static bool domainLoadingInProgress = false; |
| @@ -5641,6 +5641,8 @@ void Application::update(float deltaTime) { · 350 unmodified lines | |||
| 5641 | QMutexLocker viewLocker(&_viewMutex); | 5641 | QMutexLocker viewLocker(&_viewMutex); |
| 5642 | _myCamera.loadViewFrustum(_viewFrustum); | 5642 | _myCamera.loadViewFrustum(_viewFrustum); |
| 5643 | 5643 | ||
| 5644 | _conicalViews.clear(); | ||
| 5645 | _conicalViews.push_back(_viewFrustum); | ||
| 5644 | // TODO: Fix this by modeling the way the secondary camera works on how the main camera works | 5646 | // TODO: Fix this by modeling the way the secondary camera works on how the main camera works |
| 5645 | // ie. Use a camera object stored in the game logic and informs the Engine on where the secondary | 5647 | // ie. Use a camera object stored in the game logic and informs the Engine on where the secondary |
| 5646 | // camera should be. | 5648 | // camera should be. |
| @@ -5654,21 +5656,31 @@ void Application::update(float deltaTime) { · 7 unmodified lines | |||
| 5654 | PROFILE_RANGE_EX(app, "QueryOctree", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); | 5656 | PROFILE_RANGE_EX(app, "QueryOctree", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); |
| 5655 | PerformanceTimer perfTimer("queryOctree"); | 5657 | PerformanceTimer perfTimer("queryOctree"); |
| 5656 | QMutexLocker viewLocker(&_viewMutex); | 5658 | QMutexLocker viewLocker(&_viewMutex); |
| 5657 | quint64 sinceLastQuery = now - _lastQueriedTime; | 5659 | |
| 5658 | const quint64 TOO_LONG_SINCE_LAST_QUERY = 3 * USECS_PER_SECOND; | 5660 | bool viewIsDifferentEnough = false; |
| 5659 | bool queryIsDue = sinceLastQuery > TOO_LONG_SINCE_LAST_QUERY; | 5661 | if (_conicalViews.size() == _lastQueriedViews.size()) { |
| 5660 | bool viewIsDifferentEnough = !_lastQueriedViewFrustum.isVerySimilar(_viewFrustum); | 5662 | for (size_t i = 0; i < _conicalViews.size(); ++i) { |
| 5661 | viewIsDifferentEnough |= _hasSecondaryViewFrustum && !_lastQueriedSecondaryViewFrustum.isVerySimilar(_secondaryViewFrustum); | 5663 | if (!_conicalViews[i].isVerySimilar(_lastQueriedViews[i])) { |
| 5664 | viewIsDifferentEnough = true; | ||
| 5665 | break; | ||
| 5666 | } | ||
| 5667 | } | ||
| 5668 | } else { | ||
| 5669 | viewIsDifferentEnough = true; | ||
| 5670 | } | ||
| 5671 | |||
| 5662 | 5672 | ||
| 5663 | // if it's been a while since our last query or the view has significantly changed then send a query, otherwise suppress it | 5673 | // if it's been a while since our last query or the view has significantly changed then send a query, otherwise suppress it |
| 5664 | if (queryIsDue || viewIsDifferentEnough) { | 5674 | static const std::chrono::seconds MIN_PERIOD_BETWEEN_QUERIES { 3 }; |
| 5665 | _lastQueriedTime = now; | 5675 | auto now = SteadyClock::now(); |
| 5676 | if (now > _queryExpiry || viewIsDifferentEnough) { | ||
| 5666 | if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderEntities()) { | 5677 | if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderEntities()) { |
| 5667 | queryOctree(NodeType::EntityServer, PacketType::EntityQuery); | 5678 | queryOctree(NodeType::EntityServer, PacketType::EntityQuery); |
| 5668 | } | 5679 | } |
| 5669 | sendAvatarViewFrustum(); | 5680 | queryAvatars(); |
| 5670 | _lastQueriedViewFrustum = _viewFrustum; | 5681 | |
| 5671 | _lastQueriedSecondaryViewFrustum = _secondaryViewFrustum; | 5682 | _lastQueriedViews = _conicalViews; |
| 5683 | _queryExpiry = now + MIN_PERIOD_BETWEEN_QUERIES; | ||
| 5672 | } | 5684 | } |
| 5673 | } | 5685 | } |
| 5674 | 5686 | ||
| @@ -5840,18 +5852,20 @@ void Application::update(float deltaTime) { · 165 unmodified lines | |||
| 5840 | } | 5852 | } |
| 5841 | } | 5853 | } |
| 5842 | 5854 | ||
| 5843 | void Application::sendAvatarViewFrustum() { | 5855 | void Application::queryAvatars() { |
| 5844 | uint8_t numFrustums = 1; | 5856 | auto avatarPacket = NLPacket::create(PacketType::AvatarQuery); |
| 5845 | QByteArray viewFrustumByteArray = _viewFrustum.toByteArray(); | 5857 | auto destinationBuffer = reinterpret_cast<unsigned char*>(avatarPacket->getPayload()); |
| 5858 | unsigned char* bufferStart = destinationBuffer; | ||
| 5846 | 5859 | ||
| 5847 | if (_hasSecondaryViewFrustum) { | 5860 | uint8_t numFrustums = (uint8_t)_conicalViews.size(); |
| 5848 | ++numFrustums; | 5861 | memcpy(destinationBuffer, &numFrustums, sizeof(numFrustums)); |
| 5849 | viewFrustumByteArray += _secondaryViewFrustum.toByteArray(); | 5862 | destinationBuffer += sizeof(numFrustums); |
| 5863 | |||
| 5864 | for (const auto& view : _conicalViews) { | ||
| 5865 | destinationBuffer += view.serialize(destinationBuffer); | ||
| 5850 | } | 5866 | } |
| 5851 | 5867 | ||
| 5852 | auto avatarPacket = NLPacket::create(PacketType::ViewFrustum, viewFrustumByteArray.size() + sizeof(numFrustums)); | 5868 | avatarPacket->setPayloadSize(destinationBuffer - bufferStart); |
| 5853 | avatarPacket->writePrimitive(numFrustums); | ||
| 5854 | avatarPacket->write(viewFrustumByteArray); | ||
| 5855 | 5869 | ||
| 5856 | DependencyManager::get<NodeList>()->broadcastToNodes(std::move(avatarPacket), NodeSet() << NodeType::AvatarMixer); | 5870 | DependencyManager::get<NodeList>()->broadcastToNodes(std::move(avatarPacket), NodeSet() << NodeType::AvatarMixer); |
| 5857 | } | 5871 | } |
| @@ -5913,16 +5927,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType) { · 55 unmodified lines | |||
| 5913 | return; // bail early if settings are not loaded | 5927 | return; // bail early if settings are not loaded |
| 5914 | } | 5928 | } |
| 5915 | 5929 | ||
| 5916 | ViewFrustum viewFrustum; | 5930 | _octreeQuery.setConicalViews(_conicalViews); |
| 5917 | copyViewFrustum(viewFrustum); | ||
| 5918 | _octreeQuery.setMainViewFrustum(viewFrustum); | ||
| 5919 | |||
| 5920 | if (hasSecondaryViewFrustum()) { | ||
| 5921 | copySecondaryViewFrustum(viewFrustum); | ||
| 5922 | _octreeQuery.setSecondaryViewFrustum(viewFrustum); | ||
| 5923 | } else { | ||
| 5924 | _octreeQuery.clearSecondaryViewFrustum(); | ||
| 5925 | } | ||
| 5926 | 5931 | ||
| 5927 | auto lodManager = DependencyManager::get<LODManager>(); | 5932 | auto lodManager = DependencyManager::get<LODManager>(); |
| 5928 | _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale()); | 5933 | _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale()); |
| @@ -6007,11 +6012,6 @@ void Application::copyDisplayViewFrustum(ViewFrustum& viewOut) const { · 78 unmodified lines | |||
| 6007 | viewOut = _displayViewFrustum; | 6012 | viewOut = _displayViewFrustum; |
| 6008 | } | 6013 | } |
| 6009 | 6014 | ||
| 6010 | void Application::copySecondaryViewFrustum(ViewFrustum& viewOut) const { | ||
| 6011 | QMutexLocker viewLocker(&_viewMutex); | ||
| 6012 | viewOut = _secondaryViewFrustum; | ||
| 6013 | } | ||
| 6014 | |||
| 6015 | void Application::resetSensors(bool andReload) { | 6015 | void Application::resetSensors(bool andReload) { |
| 6016 | DependencyManager::get<DdeFaceTracker>()->reset(); | 6016 | DependencyManager::get<DdeFaceTracker>()->reset(); |
| 6017 | DependencyManager::get<EyeTracker>()->reset(); | 6017 | DependencyManager::get<EyeTracker>()->reset(); |
| @@ -6137,7 +6137,7 @@ void Application::nodeActivated(SharedNodePointer node) { · 119 unmodified lines | |||
| 6137 | // If we get a new EntityServer activated, reset lastQueried time | 6137 | // If we get a new EntityServer activated, reset lastQueried time |
| 6138 | // so we will do a proper query during update | 6138 | // so we will do a proper query during update |
| 6139 | if (node->getType() == NodeType::EntityServer) { | 6139 | if (node->getType() == NodeType::EntityServer) { |
| 6140 | _lastQueriedTime = 0; | 6140 | _queryExpiry = SteadyClock::now(); |
| 6141 | _octreeQuery.incrementConnectionID(); | 6141 | _octreeQuery.incrementConnectionID(); |
| 6142 | } | 6142 | } |
| 6143 | 6143 | ||
| @@ -6146,6 +6146,8 @@ void Application::nodeActivated(SharedNodePointer node) { · 2 unmodified lines | |||
| 6146 | } | 6146 | } |
| 6147 | 6147 | ||
| 6148 | if (node->getType() == NodeType::AvatarMixer) { | 6148 | if (node->getType() == NodeType::AvatarMixer) { |
| 6149 | _queryExpiry = SteadyClock::now(); | ||
| 6150 | |||
| 6149 | // new avatar mixer, send off our identity packet on next update loop | 6151 | // new avatar mixer, send off our identity packet on next update loop |
| 6150 | // Reset skeletonModelUrl if the last server modified our choice. | 6152 | // Reset skeletonModelUrl if the last server modified our choice. |
| 6151 | // Override the avatar url (but not model name) here too. | 6153 | // Override the avatar url (but not model name) here too. |