Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all
Unified · Split
| @@ -3102,63 +3102,70 @@ void Application::update(float deltaTime) { · 3101 unmodified lines | ||
| 3102 | 3102 | |
| 3103 | 3103 | if (_physicsEnabled) { |
| 3104 | 3104 | PerformanceTimer perfTimer("physics"); |
| 3105 | + AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data(); | |
| 3105 | 3106 | |
| 3106 | − static VectorOfMotionStates motionStates; | |
| 3107 | − _entitySimulation.getObjectsToRemoveFromPhysics(motionStates); | |
| 3108 | − _physicsEngine->removeObjects(motionStates); | |
| 3109 | − | |
| 3110 | − getEntities()->getTree()->withWriteLock([&] { | |
| 3111 | − _entitySimulation.getObjectsToAddToPhysics(motionStates); | |
| 3112 | − _physicsEngine->addObjects(motionStates); | |
| 3107 | + { | |
| 3108 | + PerformanceTimer perfTimer("updateStates)"); | |
| 3109 | + static VectorOfMotionStates motionStates; | |
| 3110 | + _entitySimulation.getObjectsToRemoveFromPhysics(motionStates); | |
| 3111 | + _physicsEngine->removeObjects(motionStates); | |
| 3113 | 3112 | |
| 3114 | − }); | |
| 3115 | − getEntities()->getTree()->withWriteLock([&] { | |
| 3116 | − _entitySimulation.getObjectsToChange(motionStates); | |
| 3117 | − VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates); | |
| 3118 | − _entitySimulation.setObjectsToChange(stillNeedChange); | |
| 3119 | − }); | |
| 3113 | + getEntities()->getTree()->withWriteLock([&] { | |
| 3114 | + _entitySimulation.getObjectsToAddToPhysics(motionStates); | |
| 3115 | + _physicsEngine->addObjects(motionStates); | |
| 3120 | 3116 | |
| 3121 | − _entitySimulation.applyActionChanges(); | |
| 3117 | + }); | |
| 3118 | + getEntities()->getTree()->withWriteLock([&] { | |
| 3119 | + _entitySimulation.getObjectsToChange(motionStates); | |
| 3120 | + VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates); | |
| 3121 | + _entitySimulation.setObjectsToChange(stillNeedChange); | |
| 3122 | + }); | |
| 3122 | 3123 | |
| 3123 | − AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data(); | |
| 3124 | − avatarManager->getObjectsToRemoveFromPhysics(motionStates); | |
| 3125 | − _physicsEngine->removeObjects(motionStates); | |
| 3126 | − avatarManager->getObjectsToAddToPhysics(motionStates); | |
| 3127 | − _physicsEngine->addObjects(motionStates); | |
| 3128 | − avatarManager->getObjectsToChange(motionStates); | |
| 3129 | − _physicsEngine->changeObjects(motionStates); | |
| 3130 | − | |
| 3131 | − myAvatar->prepareForPhysicsSimulation(); | |
| 3132 | − _physicsEngine->forEachAction([&](EntityActionPointer action) { | |
| 3133 | − action->prepareForPhysicsSimulation(); | |
| 3134 | − }); | |
| 3124 | + _entitySimulation.applyActionChanges(); | |
| 3135 | 3125 | |
| 3136 | − getEntities()->getTree()->withWriteLock([&] { | |
| 3137 | − _physicsEngine->stepSimulation(); | |
| 3138 | − }); | |
| 3126 | + avatarManager->getObjectsToRemoveFromPhysics(motionStates); | |
| 3127 | + _physicsEngine->removeObjects(motionStates); | |
| 3128 | + avatarManager->getObjectsToAddToPhysics(motionStates); | |
| 3129 | + _physicsEngine->addObjects(motionStates); | |
| 3130 | + avatarManager->getObjectsToChange(motionStates); | |
| 3131 | + _physicsEngine->changeObjects(motionStates); | |
| 3139 | 3132 | |
| 3140 | − if (_physicsEngine->hasOutgoingChanges()) { | |
| 3133 | + myAvatar->prepareForPhysicsSimulation(); | |
| 3134 | + _physicsEngine->forEachAction([&](EntityActionPointer action) { | |
| 3135 | + action->prepareForPhysicsSimulation(); | |
| 3136 | + }); | |
| 3137 | + } | |
| 3138 | + { | |
| 3139 | + PerformanceTimer perfTimer("stepSimulation"); | |
| 3141 | 3140 | getEntities()->getTree()->withWriteLock([&] { |
| 3142 | − _entitySimulation.handleOutgoingChanges(_physicsEngine->getOutgoingChanges(), _physicsEngine->getSessionID()); | |
| 3143 | − avatarManager->handleOutgoingChanges(_physicsEngine->getOutgoingChanges()); | |
| 3141 | + _physicsEngine->stepSimulation(); | |
| 3144 | 3142 | }); |
| 3143 | + } | |
| 3144 | + { | |
| 3145 | + PerformanceTimer perfTimer("havestChanges"); | |
| 3146 | + if (_physicsEngine->hasOutgoingChanges()) { | |
| 3147 | + getEntities()->getTree()->withWriteLock([&] { | |
| 3148 | + _entitySimulation.handleOutgoingChanges(_physicsEngine->getOutgoingChanges(), _physicsEngine->getSessionID()); | |
| 3149 | + avatarManager->handleOutgoingChanges(_physicsEngine->getOutgoingChanges()); | |
| 3150 | + }); | |
| 3145 | 3151 | |
| 3146 | − auto collisionEvents = _physicsEngine->getCollisionEvents(); | |
| 3147 | − avatarManager->handleCollisionEvents(collisionEvents); | |
| 3152 | + auto collisionEvents = _physicsEngine->getCollisionEvents(); | |
| 3153 | + avatarManager->handleCollisionEvents(collisionEvents); | |
| 3148 | 3154 | |
| 3149 | − _physicsEngine->dumpStatsIfNecessary(); | |
| 3155 | + _physicsEngine->dumpStatsIfNecessary(); | |
| 3150 | 3156 | |
| 3151 | − if (!_aboutToQuit) { | |
| 3152 | − PerformanceTimer perfTimer("entities"); | |
| 3153 | − // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk | |
| 3154 | − // deadlock.) | |
| 3155 | − _entitySimulation.handleCollisionEvents(collisionEvents); | |
| 3156 | − // NOTE: the getEntities()->update() call below will wait for lock | |
| 3157 | − // and will simulate entity motion (the EntityTree has been given an EntitySimulation). | |
| 3158 | − getEntities()->update(); // update the models... | |
| 3159 | − } | |
| 3157 | + if (!_aboutToQuit) { | |
| 3158 | + PerformanceTimer perfTimer("entities"); | |
| 3159 | + // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk | |
| 3160 | + // deadlock.) | |
| 3161 | + _entitySimulation.handleCollisionEvents(collisionEvents); | |
| 3162 | + // NOTE: the getEntities()->update() call below will wait for lock | |
| 3163 | + // and will simulate entity motion (the EntityTree has been given an EntitySimulation). | |
| 3164 | + getEntities()->update(); // update the models... | |
| 3165 | + } | |
| 3160 | 3166 | |
| 3161 | − myAvatar->harvestResultsFromPhysicsSimulation(deltaTime); | |
| 3167 | + myAvatar->harvestResultsFromPhysicsSimulation(deltaTime); | |
| 3168 | + } | |
| 3162 | 3169 | } |
| 3163 | 3170 | } |
| 3164 | 3171 | |