Showing the changes to interface/src/Application.cpp (1 of 158 files). Show all
Unified · Split
| @@ -335,10 +335,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 334 unmodified lines | ||
| 335 | 335 | _frameCount(0), |
| 336 | 336 | _fps(60.0f), |
| 337 | 337 | _justStarted(true), |
| 338 | − _physicsEngine(glm::vec3(0.0f)), | |
| 338 | + _physicsEngine(new PhysicsEngine(Vectors::ZERO)), | |
| 339 | 339 | _entities(true, this, this), |
| 340 | 340 | _entityClipboardRenderer(false, this, this), |
| 341 | − _entityClipboard(), | |
| 341 | + _entityClipboard(new EntityTree()), | |
| 342 | 342 | _viewFrustum(), |
| 343 | 343 | _lastQueriedViewFrustum(), |
| 344 | 344 | _lastQueriedTime(usecTimestampNow()), |
| @@ -372,6 +372,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 27 unmodified lines | ||
| 372 | 372 | { |
| 373 | 373 | setInstance(this); |
| 374 | 374 | |
| 375 | + _entityClipboard->createRootElement(); | |
| 376 | + | |
| 375 | 377 | _pluginContainer = new PluginContainerProxy(); |
| 376 | 378 | Plugin::setContainer(_pluginContainer); |
| 377 | 379 | #ifdef Q_OS_WIN |
| @@ -861,17 +863,15 @@ void Application::emptyLocalCache() { · 483 unmodified lines | ||
| 861 | 863 | } |
| 862 | 864 | |
| 863 | 865 | Application::~Application() { |
| 864 | − EntityTree* tree = _entities.getTree(); | |
| 865 | − tree->lockForWrite(); | |
| 866 | − _entities.getTree()->setSimulation(NULL); | |
| 867 | − tree->unlock(); | |
| 866 | + EntityTreePointer tree = _entities.getTree(); | |
| 867 | + tree->setSimulation(NULL); | |
| 868 | 868 | |
| 869 | 869 | _octreeProcessor.terminate(); |
| 870 | 870 | _entityEditSender.terminate(); |
| 871 | 871 | |
| 872 | 872 | Menu::getInstance()->deleteLater(); |
| 873 | 873 | |
| 874 | − _physicsEngine.setCharacterController(NULL); | |
| 874 | + _physicsEngine->setCharacterController(NULL); | |
| 875 | 875 | _myAvatar = NULL; |
| 876 | 876 | |
| 877 | 877 | ModelEntityItem::cleanupLoadedAnimations(); |
| @@ -886,7 +886,9 @@ Application::~Application() { · 8 unmodified lines | ||
| 886 | 886 | |
| 887 | 887 | // remove avatars from physics engine |
| 888 | 888 | DependencyManager::get<AvatarManager>()->clearOtherAvatars(); |
| 889 | − _physicsEngine.deleteObjects(DependencyManager::get<AvatarManager>()->getObjectsToDelete()); | |
| 889 | + VectorOfMotionStates motionStates; | |
| 890 | + DependencyManager::get<AvatarManager>()->getObjectsToDelete(motionStates); | |
| 891 | + _physicsEngine->deleteObjects(motionStates); | |
| 890 | 892 | |
| 891 | 893 | DependencyManager::destroy<OffscreenUi>(); |
| 892 | 894 | DependencyManager::destroy<AvatarManager>(); |
| @@ -1513,7 +1515,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 620 unmodified lines | ||
| 1513 | 1515 | break; |
| 1514 | 1516 | |
| 1515 | 1517 | case Qt::Key_F: { |
| 1516 | − _physicsEngine.dumpNextStats(); | |
| 1518 | + _physicsEngine->dumpNextStats(); | |
| 1517 | 1519 | break; |
| 1518 | 1520 | } |
| 1519 | 1521 | |
| @@ -2395,7 +2397,7 @@ void Application::saveSettings() { · 875 unmodified lines | ||
| 2395 | 2397 | } |
| 2396 | 2398 | |
| 2397 | 2399 | bool Application::importEntities(const QString& urlOrFilename) { |
| 2398 | − _entityClipboard.eraseAllOctreeElements(); | |
| 2400 | + _entityClipboard->eraseAllOctreeElements(); | |
| 2399 | 2401 | |
| 2400 | 2402 | QUrl url(urlOrFilename); |
| 2401 | 2403 | |
| @@ -2404,15 +2406,15 @@ bool Application::importEntities(const QString& urlOrFilename) { · 2 unmodified lines | ||
| 2404 | 2406 | url = QUrl::fromLocalFile(urlOrFilename); |
| 2405 | 2407 | } |
| 2406 | 2408 | |
| 2407 | − bool success = _entityClipboard.readFromURL(url.toString()); | |
| 2409 | + bool success = _entityClipboard->readFromURL(url.toString()); | |
| 2408 | 2410 | if (success) { |
| 2409 | − _entityClipboard.reaverageOctreeElements(); | |
| 2411 | + _entityClipboard->reaverageOctreeElements(); | |
| 2410 | 2412 | } |
| 2411 | 2413 | return success; |
| 2412 | 2414 | } |
| 2413 | 2415 | |
| 2414 | 2416 | QVector<EntityItemID> Application::pasteEntities(float x, float y, float z) { |
| 2415 | − return _entityClipboard.sendEntities(&_entityEditSender, _entities.getTree(), x, y, z); | |
| 2417 | + return _entityClipboard->sendEntities(&_entityEditSender, _entities.getTree(), x, y, z); | |
| 2416 | 2418 | } |
| 2417 | 2419 | |
| 2418 | 2420 | void Application::initDisplay() { |
| @@ -2457,10 +2459,10 @@ void Application::init() { · 38 unmodified lines | ||
| 2457 | 2459 | _entities.setViewFrustum(getViewFrustum()); |
| 2458 | 2460 | |
| 2459 | 2461 | ObjectMotionState::setShapeManager(&_shapeManager); |
| 2460 | − _physicsEngine.init(); | |
| 2462 | + _physicsEngine->init(); | |
| 2461 | 2463 | |
| 2462 | − EntityTree* tree = _entities.getTree(); | |
| 2463 | − _entitySimulation.init(tree, &_physicsEngine, &_entityEditSender); | |
| 2464 | + EntityTreePointer tree = _entities.getTree(); | |
| 2465 | + _entitySimulation.init(tree, _physicsEngine, &_entityEditSender); | |
| 2464 | 2466 | tree->setSimulation(&_entitySimulation); |
| 2465 | 2467 | |
| 2466 | 2468 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); |
| @@ -2475,23 +2477,47 @@ void Application::init() { · 8 unmodified lines | ||
| 2475 | 2477 | |
| 2476 | 2478 | _entityClipboardRenderer.init(); |
| 2477 | 2479 | _entityClipboardRenderer.setViewFrustum(getViewFrustum()); |
| 2478 | − _entityClipboardRenderer.setTree(&_entityClipboard); | |
| 2480 | + _entityClipboardRenderer.setTree(_entityClipboard); | |
| 2479 | 2481 | |
| 2480 | 2482 | // Make sure any new sounds are loaded as soon as know about them. |
| 2481 | − connect(tree, &EntityTree::newCollisionSoundURL, DependencyManager::get<SoundCache>().data(), &SoundCache::getSound); | |
| 2483 | + connect(tree.get(), &EntityTree::newCollisionSoundURL, DependencyManager::get<SoundCache>().data(), &SoundCache::getSound); | |
| 2482 | 2484 | connect(_myAvatar, &MyAvatar::newCollisionSoundURL, DependencyManager::get<SoundCache>().data(), &SoundCache::getSound); |
| 2483 | 2485 | |
| 2484 | − setAvatarUpdateThreading(Menu::getInstance()->isOptionChecked(MenuOption::EnableAvatarUpdateThreading)); | |
| 2486 | + setAvatarUpdateThreading(); | |
| 2485 | 2487 | } |
| 2486 | 2488 | |
| 2487 | −void Application::setAvatarUpdateThreading(bool isThreaded) { | |
| 2489 | +void Application::setAvatarUpdateThreading() { | |
| 2490 | + setAvatarUpdateThreading(Menu::getInstance()->isOptionChecked(MenuOption::EnableAvatarUpdateThreading)); | |
| 2491 | +} | |
| 2492 | +void Application::setRawAvatarUpdateThreading() { | |
| 2493 | + setRawAvatarUpdateThreading(Menu::getInstance()->isOptionChecked(MenuOption::EnableAvatarUpdateThreading)); | |
| 2494 | +} | |
| 2495 | +void Application::setRawAvatarUpdateThreading(bool isThreaded) { | |
| 2488 | 2496 | if (_avatarUpdate) { |
| 2489 | − getMyAvatar()->destroyAnimGraph(); | |
| 2497 | + if (_avatarUpdate->isThreaded() == isThreaded) { | |
| 2498 | + return; | |
| 2499 | + } | |
| 2490 | 2500 | _avatarUpdate->terminate(); |
| 2491 | 2501 | } |
| 2492 | 2502 | _avatarUpdate = new AvatarUpdate(); |
| 2493 | 2503 | _avatarUpdate->initialize(isThreaded); |
| 2494 | 2504 | } |
| 2505 | +void Application::setAvatarUpdateThreading(bool isThreaded) { | |
| 2506 | + if (_avatarUpdate && (_avatarUpdate->isThreaded() == isThreaded)) { | |
| 2507 | + return; | |
| 2508 | + } | |
| 2509 | + bool isRigEnabled = getMyAvatar()->getEnableRigAnimations(); | |
| 2510 | + bool isGraphEnabled = getMyAvatar()->getEnableAnimGraph(); | |
| 2511 | + if (_avatarUpdate) { | |
| 2512 | + _avatarUpdate->terminate(); // Must be before we shutdown anim graph. | |
| 2513 | + } | |
| 2514 | + getMyAvatar()->setEnableRigAnimations(false); | |
| 2515 | + getMyAvatar()->setEnableAnimGraph(false); | |
| 2516 | + _avatarUpdate = new AvatarUpdate(); | |
| 2517 | + _avatarUpdate->initialize(isThreaded); | |
| 2518 | + getMyAvatar()->setEnableRigAnimations(isRigEnabled); | |
| 2519 | + getMyAvatar()->setEnableAnimGraph(isGraphEnabled); | |
| 2520 | +} | |
| 2495 | 2521 | |
| 2496 | 2522 | |
| 2497 | 2523 | void Application::closeMirrorView() { |
| @@ -2861,51 +2887,45 @@ void Application::update(float deltaTime) { · 363 unmodified lines | ||
| 2861 | 2887 | PerformanceTimer perfTimer("physics"); |
| 2862 | 2888 | _myAvatar->relayDriveKeysToCharacterController(); |
| 2863 | 2889 | |
| 2864 | − _entitySimulation.lock(); | |
| 2865 | − _physicsEngine.deleteObjects(_entitySimulation.getObjectsToDelete()); | |
| 2866 | − _entitySimulation.unlock(); | |
| 2890 | + static VectorOfMotionStates motionStates; | |
| 2891 | + _entitySimulation.getObjectsToDelete(motionStates); | |
| 2892 | + _physicsEngine->deleteObjects(motionStates); | |
| 2867 | 2893 | |
| 2868 | − _entities.getTree()->lockForWrite(); | |
| 2869 | − _entitySimulation.lock(); | |
| 2870 | − _physicsEngine.addObjects(_entitySimulation.getObjectsToAdd()); | |
| 2871 | − _entitySimulation.unlock(); | |
| 2872 | − _entities.getTree()->unlock(); | |
| 2894 | + _entities.getTree()->withWriteLock([&] { | |
| 2895 | + _entitySimulation.getObjectsToAdd(motionStates); | |
| 2896 | + _physicsEngine->addObjects(motionStates); | |
| 2873 | 2897 | |
| 2874 | − _entities.getTree()->lockForWrite(); | |
| 2875 | − _entitySimulation.lock(); | |
| 2876 | − VectorOfMotionStates stillNeedChange = _physicsEngine.changeObjects(_entitySimulation.getObjectsToChange()); | |
| 2877 | − _entitySimulation.setObjectsToChange(stillNeedChange); | |
| 2878 | − _entitySimulation.unlock(); | |
| 2879 | − _entities.getTree()->unlock(); | |
| 2898 | + }); | |
| 2899 | + _entities.getTree()->withWriteLock([&] { | |
| 2900 | + _entitySimulation.getObjectsToChange(motionStates); | |
| 2901 | + VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates); | |
| 2902 | + _entitySimulation.setObjectsToChange(stillNeedChange); | |
| 2903 | + }); | |
| 2880 | 2904 | |
| 2881 | − _entitySimulation.lock(); | |
| 2882 | 2905 | _entitySimulation.applyActionChanges(); |
| 2883 | − _entitySimulation.unlock(); | |
| 2884 | 2906 | |
| 2885 | 2907 | AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data(); |
| 2886 | − _physicsEngine.deleteObjects(avatarManager->getObjectsToDelete()); | |
| 2887 | − _physicsEngine.addObjects(avatarManager->getObjectsToAdd()); | |
| 2888 | − _physicsEngine.changeObjects(avatarManager->getObjectsToChange()); | |
| 2889 | − | |
| 2890 | − _entities.getTree()->lockForWrite(); | |
| 2891 | − _physicsEngine.stepSimulation(); | |
| 2892 | − _entities.getTree()->unlock(); | |
| 2893 | − | |
| 2894 | − if (_physicsEngine.hasOutgoingChanges()) { | |
| 2895 | − _entities.getTree()->lockForWrite(); | |
| 2896 | − _entitySimulation.lock(); | |
| 2897 | − _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID()); | |
| 2898 | − _entitySimulation.unlock(); | |
| 2899 | − _entities.getTree()->unlock(); | |
| 2900 | − | |
| 2901 | − _entities.getTree()->lockForWrite(); | |
| 2902 | − avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges()); | |
| 2903 | − _entities.getTree()->unlock(); | |
| 2904 | − | |
| 2905 | − auto collisionEvents = _physicsEngine.getCollisionEvents(); | |
| 2908 | + avatarManager->getObjectsToDelete(motionStates); | |
| 2909 | + _physicsEngine->deleteObjects(motionStates); | |
| 2910 | + avatarManager->getObjectsToAdd(motionStates); | |
| 2911 | + _physicsEngine->addObjects(motionStates); | |
| 2912 | + avatarManager->getObjectsToChange(motionStates); | |
| 2913 | + _physicsEngine->changeObjects(motionStates); | |
| 2914 | + | |
| 2915 | + _entities.getTree()->withWriteLock([&] { | |
| 2916 | + _physicsEngine->stepSimulation(); | |
| 2917 | + }); | |
| 2918 | + | |
| 2919 | + if (_physicsEngine->hasOutgoingChanges()) { | |
| 2920 | + _entities.getTree()->withWriteLock([&] { | |
| 2921 | + _entitySimulation.handleOutgoingChanges(_physicsEngine->getOutgoingChanges(), _physicsEngine->getSessionID()); | |
| 2922 | + avatarManager->handleOutgoingChanges(_physicsEngine->getOutgoingChanges()); | |
| 2923 | + }); | |
| 2924 | + | |
| 2925 | + auto collisionEvents = _physicsEngine->getCollisionEvents(); | |
| 2906 | 2926 | avatarManager->handleCollisionEvents(collisionEvents); |
| 2907 | 2927 | |
| 2908 | − _physicsEngine.dumpStatsIfNecessary(); | |
| 2928 | + _physicsEngine->dumpStatsIfNecessary(); | |
| 2909 | 2929 | |
| 2910 | 2930 | if (!_aboutToQuit) { |
| 2911 | 2931 | PerformanceTimer perfTimer("entities"); |
| @@ -3019,27 +3039,21 @@ int Application::sendNackPackets() { · 107 unmodified lines | ||
| 3019 | 3039 | return; |
| 3020 | 3040 | } |
| 3021 | 3041 | |
| 3022 | − _octreeSceneStatsLock.lockForRead(); | |
| 3042 | + QSet<OCTREE_PACKET_SEQUENCE> missingSequenceNumbers; | |
| 3043 | + _octreeServerSceneStats.withReadLock([&] { | |
| 3044 | + // retreive octree scene stats of this node | |
| 3045 | + if (_octreeServerSceneStats.find(nodeUUID) == _octreeServerSceneStats.end()) { | |
| 3046 | + return; | |
| 3047 | + } | |
| 3048 | + // get sequence number stats of node, prune its missing set, and make a copy of the missing set | |
| 3049 | + SequenceNumberStats& sequenceNumberStats = _octreeServerSceneStats[nodeUUID].getIncomingOctreeSequenceNumberStats(); | |
| 3050 | + sequenceNumberStats.pruneMissingSet(); | |
| 3051 | + missingSequenceNumbers = sequenceNumberStats.getMissingSet(); | |
| 3052 | + }); | |
| 3023 | 3053 | |
| 3024 | − // retreive octree scene stats of this node | |
| 3025 | − if (_octreeServerSceneStats.find(nodeUUID) == _octreeServerSceneStats.end()) { | |
| 3026 | − _octreeSceneStatsLock.unlock(); | |
| 3027 | − return; | |
| 3028 | − } | |
| 3029 | − | |
| 3030 | − // get sequence number stats of node, prune its missing set, and make a copy of the missing set | |
| 3031 | − SequenceNumberStats& sequenceNumberStats = _octreeServerSceneStats[nodeUUID].getIncomingOctreeSequenceNumberStats(); | |
| 3032 | − sequenceNumberStats.pruneMissingSet(); | |
| 3033 | − const QSet<OCTREE_PACKET_SEQUENCE> missingSequenceNumbers = sequenceNumberStats.getMissingSet(); | |
| 3034 | − | |
| 3035 | − _octreeSceneStatsLock.unlock(); | |
| 3036 | − | |
| 3037 | 3054 | // construct nack packet(s) for this node |
| 3038 | − auto it = missingSequenceNumbers.constBegin(); | |
| 3039 | − while (it != missingSequenceNumbers.constEnd()) { | |
| 3040 | − OCTREE_PACKET_SEQUENCE missingNumber = *it; | |
| 3055 | + foreach(const OCTREE_PACKET_SEQUENCE& missingNumber, missingSequenceNumbers) { | |
| 3041 | 3056 | nackPacketList->writePrimitive(missingNumber); |
| 3042 | − ++it; | |
| 3043 | 3057 | } |
| 3044 | 3058 | |
| 3045 | 3059 | if (nackPacketList->getNumPackets()) { |
| @@ -3772,13 +3786,13 @@ void Application::clearDomainOctreeDetails() { · 726 unmodified lines | ||
| 3772 | 3786 | // reset the environment so that we don't erroneously end up with multiple |
| 3773 | 3787 | |
| 3774 | 3788 | // reset our node to stats and node to jurisdiction maps... since these must be changing... |
| 3775 | − _entityServerJurisdictions.lockForWrite(); | |
| 3776 | − _entityServerJurisdictions.clear(); | |
| 3777 | − _entityServerJurisdictions.unlock(); | |
| 3789 | + _entityServerJurisdictions.withWriteLock([&] { | |
| 3790 | + _entityServerJurisdictions.clear(); | |
| 3791 | + }); | |
| 3778 | 3792 | |
| 3779 | − _octreeSceneStatsLock.lockForWrite(); | |
| 3780 | − _octreeServerSceneStats.clear(); | |
| 3781 | − _octreeSceneStatsLock.unlock(); | |
| 3793 | + _octreeServerSceneStats.withWriteLock([&] { | |
| 3794 | + _octreeServerSceneStats.clear(); | |
| 3795 | + }); | |
| 3782 | 3796 | |
| 3783 | 3797 | // reset the model renderer |
| 3784 | 3798 | _entities.clear(); |
| @@ -3848,29 +3862,31 @@ void Application::nodeKilled(SharedNodePointer node) { · 63 unmodified lines | ||
| 3848 | 3862 | |
| 3849 | 3863 | QUuid nodeUUID = node->getUUID(); |
| 3850 | 3864 | // see if this is the first we've heard of this node... |
| 3851 | − _entityServerJurisdictions.lockForRead(); | |
| 3852 | − if (_entityServerJurisdictions.find(nodeUUID) != _entityServerJurisdictions.end()) { | |
| 3865 | + _entityServerJurisdictions.withReadLock([&] { | |
| 3866 | + if (_entityServerJurisdictions.find(nodeUUID) == _entityServerJurisdictions.end()) { | |
| 3867 | + return; | |
| 3868 | + } | |
| 3869 | + | |
| 3853 | 3870 | unsigned char* rootCode = _entityServerJurisdictions[nodeUUID].getRootOctalCode(); |
| 3854 | 3871 | VoxelPositionSize rootDetails; |
| 3855 | 3872 | voxelDetailsForCode(rootCode, rootDetails); |
| 3856 | − _entityServerJurisdictions.unlock(); | |
| 3857 | 3873 | |
| 3858 | 3874 | qCDebug(interfaceapp, "model server going away...... v[%f, %f, %f, %f]", |
| 3859 | − (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s); | |
| 3875 | + (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s); | |
| 3876 | + | |
| 3877 | + }); | |
| 3860 | 3878 | |
| 3861 | − // If the model server is going away, remove it from our jurisdiction map so we don't send voxels to a dead server | |
| 3862 | − _entityServerJurisdictions.lockForWrite(); | |
| 3879 | + // If the model server is going away, remove it from our jurisdiction map so we don't send voxels to a dead server | |
| 3880 | + _entityServerJurisdictions.withWriteLock([&] { | |
| 3863 | 3881 | _entityServerJurisdictions.erase(_entityServerJurisdictions.find(nodeUUID)); |
| 3864 | − } | |
| 3865 | − _entityServerJurisdictions.unlock(); | |
| 3882 | + }); | |
| 3866 | 3883 | |
| 3867 | 3884 | // also clean up scene stats for that server |
| 3868 | − _octreeSceneStatsLock.lockForWrite(); | |
| 3869 | − if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) { | |
| 3870 | − _octreeServerSceneStats.erase(nodeUUID); | |
| 3871 | − } | |
| 3872 | − _octreeSceneStatsLock.unlock(); | |
| 3873 | − | |
| 3885 | + _octreeServerSceneStats.withWriteLock([&] { | |
| 3886 | + if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) { | |
| 3887 | + _octreeServerSceneStats.erase(nodeUUID); | |
| 3888 | + } | |
| 3889 | + }); | |
| 3874 | 3890 | } else if (node->getType() == NodeType::AvatarMixer) { |
| 3875 | 3891 | // our avatar mixer has gone away - clear the hash of avatars |
| 3876 | 3892 | DependencyManager::get<AvatarManager>()->clearOtherAvatars(); |
| @@ -3888,12 +3904,12 @@ void Application::trackIncomingOctreePacket(NLPacket& packet, SharedNodePointer · 11 unmodified lines | ||
| 3888 | 3904 | const QUuid& nodeUUID = sendingNode->getUUID(); |
| 3889 | 3905 | |
| 3890 | 3906 | // now that we know the node ID, let's add these stats to the stats for that node... |
| 3891 | − _octreeSceneStatsLock.lockForWrite(); | |
| 3892 | − if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) { | |
| 3893 | − OctreeSceneStats& stats = _octreeServerSceneStats[nodeUUID]; | |
| 3894 | − stats.trackIncomingOctreePacket(packet, wasStatsPacket, sendingNode->getClockSkewUsec()); | |
| 3895 | − } | |
| 3896 | − _octreeSceneStatsLock.unlock(); | |
| 3907 | + _octreeServerSceneStats.withWriteLock([&] { | |
| 3908 | + if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) { | |
| 3909 | + OctreeSceneStats& stats = _octreeServerSceneStats[nodeUUID]; | |
| 3910 | + stats.trackIncomingOctreePacket(packet, wasStatsPacket, sendingNode->getClockSkewUsec()); | |
| 3911 | + } | |
| 3912 | + }); | |
| 3897 | 3913 | } |
| 3898 | 3914 | } |
| 3899 | 3915 | |
| @@ -3907,43 +3923,42 @@ int Application::processOctreeStats(NLPacket& packet, SharedNodePointer sendingN · 7 unmodified lines | ||
| 3907 | 3923 | const QUuid& nodeUUID = sendingNode->getUUID(); |
| 3908 | 3924 | |
| 3909 | 3925 | // now that we know the node ID, let's add these stats to the stats for that node... |
| 3910 | − _octreeSceneStatsLock.lockForWrite(); | |
| 3911 | − | |
| 3912 | − OctreeSceneStats& octreeStats = _octreeServerSceneStats[nodeUUID]; | |
| 3913 | − statsMessageLength = octreeStats.unpackFromPacket(packet); | |
| 3914 | − | |
| 3915 | − _octreeSceneStatsLock.unlock(); | |
| 3926 | + _octreeServerSceneStats.withWriteLock([&] { | |
| 3927 | + OctreeSceneStats& octreeStats = _octreeServerSceneStats[nodeUUID]; | |
| 3928 | + statsMessageLength = octreeStats.unpackFromPacket(packet); | |
| 3916 | 3929 | |
| 3917 | − // see if this is the first we've heard of this node... | |
| 3918 | − NodeToJurisdictionMap* jurisdiction = NULL; | |
| 3919 | − QString serverType; | |
| 3920 | − if (sendingNode->getType() == NodeType::EntityServer) { | |
| 3921 | − jurisdiction = &_entityServerJurisdictions; | |
| 3922 | − serverType = "Entity"; | |
| 3923 | − } | |
| 3930 | + // see if this is the first we've heard of this node... | |
| 3931 | + NodeToJurisdictionMap* jurisdiction = NULL; | |
| 3932 | + QString serverType; | |
| 3933 | + if (sendingNode->getType() == NodeType::EntityServer) { | |
| 3934 | + jurisdiction = &_entityServerJurisdictions; | |
| 3935 | + serverType = "Entity"; | |
| 3936 | + } | |
| 3924 | 3937 | |
| 3925 | − jurisdiction->lockForRead(); | |
| 3926 | − if (jurisdiction->find(nodeUUID) == jurisdiction->end()) { | |
| 3927 | − jurisdiction->unlock(); | |
| 3928 | − | |
| 3929 | − VoxelPositionSize rootDetails; | |
| 3930 | − voxelDetailsForCode(octreeStats.getJurisdictionRoot(), rootDetails); | |
| 3938 | + jurisdiction->withReadLock([&] { | |
| 3939 | + if (jurisdiction->find(nodeUUID) != jurisdiction->end()) { | |
| 3940 | + return; | |
| 3941 | + } | |
| 3931 | 3942 | |
| 3932 | − qCDebug(interfaceapp, "stats from new %s server... [%f, %f, %f, %f]", | |
| 3943 | + VoxelPositionSize rootDetails; | |
| 3944 | + voxelDetailsForCode(octreeStats.getJurisdictionRoot(), rootDetails); | |
| 3945 | + | |
| 3946 | + qCDebug(interfaceapp, "stats from new %s server... [%f, %f, %f, %f]", | |
| 3933 | 3947 | qPrintable(serverType), |
| 3934 | 3948 | (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s); |
| 3935 | − } else { | |
| 3936 | − jurisdiction->unlock(); | |
| 3937 | − } | |
| 3938 | − // store jurisdiction details for later use | |
| 3939 | − // This is bit of fiddling is because JurisdictionMap assumes it is the owner of the values used to construct it | |
| 3940 | − // but OctreeSceneStats thinks it's just returning a reference to its contents. So we need to make a copy of the | |
| 3941 | − // details from the OctreeSceneStats to construct the JurisdictionMap | |
| 3942 | − JurisdictionMap jurisdictionMap; | |
| 3943 | − jurisdictionMap.copyContents(octreeStats.getJurisdictionRoot(), octreeStats.getJurisdictionEndNodes()); | |
| 3944 | − jurisdiction->lockForWrite(); | |
| 3945 | − (*jurisdiction)[nodeUUID] = jurisdictionMap; | |
| 3946 | − jurisdiction->unlock(); | |
| 3949 | + }); | |
| 3950 | + // store jurisdiction details for later use | |
| 3951 | + // This is bit of fiddling is because JurisdictionMap assumes it is the owner of the values used to construct it | |
| 3952 | + // but OctreeSceneStats thinks it's just returning a reference to its contents. So we need to make a copy of the | |
| 3953 | + // details from the OctreeSceneStats to construct the JurisdictionMap | |
| 3954 | + JurisdictionMap jurisdictionMap; | |
| 3955 | + jurisdictionMap.copyContents(octreeStats.getJurisdictionRoot(), octreeStats.getJurisdictionEndNodes()); | |
| 3956 | + jurisdiction->withWriteLock([&] { | |
| 3957 | + (*jurisdiction)[nodeUUID] = jurisdictionMap; | |
| 3958 | + }); | |
| 3959 | + }); | |
| 3960 | + | |
| 3961 | + | |
| 3947 | 3962 | |
| 3948 | 3963 | return statsMessageLength; |
| 3949 | 3964 | } |
| @@ -4134,7 +4149,7 @@ bool Application::acceptURL(const QString& urlString) { · 184 unmodified lines | ||
| 4134 | 4149 | } |
| 4135 | 4150 | |
| 4136 | 4151 | void Application::setSessionUUID(const QUuid& sessionUUID) { |
| 4137 | − _physicsEngine.setSessionUUID(sessionUUID); | |
| 4152 | + _physicsEngine->setSessionUUID(sessionUUID); | |
| 4138 | 4153 | } |
| 4139 | 4154 | |
| 4140 | 4155 | bool Application::askToSetAvatarUrl(const QString& url) { |
| @@ -4389,7 +4404,7 @@ void Application::openUrl(const QUrl& url) { · 248 unmodified lines | ||
| 4389 | 4404 | void Application::updateMyAvatarTransform() { |
| 4390 | 4405 | const float SIMULATION_OFFSET_QUANTIZATION = 16.0f; // meters |
| 4391 | 4406 | glm::vec3 avatarPosition = _myAvatar->getPosition(); |
| 4392 | − glm::vec3 physicsWorldOffset = _physicsEngine.getOriginOffset(); | |
| 4407 | + glm::vec3 physicsWorldOffset = _physicsEngine->getOriginOffset(); | |
| 4393 | 4408 | if (glm::distance(avatarPosition, physicsWorldOffset) > SIMULATION_OFFSET_QUANTIZATION) { |
| 4394 | 4409 | glm::vec3 newOriginOffset = avatarPosition; |
| 4395 | 4410 | int halfExtent = (int)HALF_SIMULATION_EXTENT; |
| @@ -4398,7 +4413,7 @@ void Application::updateMyAvatarTransform() { · 2 unmodified lines | ||
| 4398 | 4413 | ((int)(avatarPosition[i] / SIMULATION_OFFSET_QUANTIZATION)) * (int)SIMULATION_OFFSET_QUANTIZATION)); |
| 4399 | 4414 | } |
| 4400 | 4415 | // TODO: Andrew to replace this with method that actually moves existing object positions in PhysicsEngine |
| 4401 | − _physicsEngine.setOriginOffset(newOriginOffset); | |
| 4416 | + _physicsEngine->setOriginOffset(newOriginOffset); | |
| 4402 | 4417 | } |
| 4403 | 4418 | } |
| 4404 | 4419 | |
| @@ -4596,7 +4611,7 @@ void Application::checkSkeleton() { · 191 unmodified lines | ||
| 4596 | 4611 | |
| 4597 | 4612 | _myAvatar->useFullAvatarURL(AvatarData::defaultFullAvatarModelUrl(), DEFAULT_FULL_AVATAR_MODEL_NAME); |
| 4598 | 4613 | } else { |
| 4599 | − _physicsEngine.setCharacterController(_myAvatar->getCharacterController()); | |
| 4614 | + _physicsEngine->setCharacterController(_myAvatar->getCharacterController()); | |
| 4600 | 4615 | } |
| 4601 | 4616 | } |
| 4602 | 4617 | |
| @@ -5036,7 +5051,7 @@ void Application::emulateMouse(Hand* hand, float click, float shift, int index) · 433 unmodified lines | ||
| 5036 | 5051 | glm::vec3 direction = glm::inverse(_myAvatar->getOrientation()) * palm->getFingerDirection(); |
| 5037 | 5052 | |
| 5038 | 5053 | // Get the angles, scaled between (-0.5,0.5) |
| 5039 | − float xAngle = (atan2(direction.z, direction.x) + M_PI_2); | |
| 5054 | + float xAngle = (atan2f(direction.z, direction.x) + (float)M_PI_2); | |
| 5040 | 5055 | float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)M_PI_2)); |
| 5041 | 5056 | auto canvasSize = qApp->getCanvasSize(); |
| 5042 | 5057 | // Get the pixel range over which the xAngle and yAngle are scaled |