History

Split physics perf timing into three parts: updateStates, stepSimulation, and harvestChanges.

howard-stearns committed 10 years ago

Commit 8a77e2e1 parent 6f85ee11 file · +52 −45Browse files

Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all

Unified · Split

interface/src/Application.cpp+52−45
@@ -3102,63 +3102,70 @@ void Application::update(float deltaTime) { · 3101 unmodified lines
31023102
31033103 if (_physicsEnabled) {
31043104 PerformanceTimer perfTimer("physics");
3105+ AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data();
31053106
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);
31133112
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);
31203116
3121− _entitySimulation.applyActionChanges();
3117+ });
3118+ getEntities()->getTree()->withWriteLock([&] {
3119+ _entitySimulation.getObjectsToChange(motionStates);
3120+ VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates);
3121+ _entitySimulation.setObjectsToChange(stillNeedChange);
3122+ });
31223123
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();
31353125
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);
31393132
3140− if (_physicsEngine->hasOutgoingChanges()) {
3133+ myAvatar->prepareForPhysicsSimulation();
3134+ _physicsEngine->forEachAction([&](EntityActionPointer action) {
3135+ action->prepareForPhysicsSimulation();
3136+ });
3137+ }
3138+ {
3139+ PerformanceTimer perfTimer("stepSimulation");
31413140 getEntities()->getTree()->withWriteLock([&] {
3142− _entitySimulation.handleOutgoingChanges(_physicsEngine->getOutgoingChanges(), _physicsEngine->getSessionID());
3143− avatarManager->handleOutgoingChanges(_physicsEngine->getOutgoingChanges());
3141+ _physicsEngine->stepSimulation();
31443142 });
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+ });
31453151
3146− auto collisionEvents = _physicsEngine->getCollisionEvents();
3147− avatarManager->handleCollisionEvents(collisionEvents);
3152+ auto collisionEvents = _physicsEngine->getCollisionEvents();
3153+ avatarManager->handleCollisionEvents(collisionEvents);
31483154
3149− _physicsEngine->dumpStatsIfNecessary();
3155+ _physicsEngine->dumpStatsIfNecessary();
31503156
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+ }
31603166
3161− myAvatar->harvestResultsFromPhysicsSimulation(deltaTime);
3167+ myAvatar->harvestResultsFromPhysicsSimulation(deltaTime);
3168+ }
31623169 }
31633170 }
31643171