From d5c0c200de30a2eddf9fedd7fa09aa7929ddb00a Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 27 Jan 2015 15:54:32 -0800 Subject: [PATCH] optimization for when physics engine doesn't step --- libraries/physics/src/PhysicsEngine.cpp | 38 ++++++++++++++----------- libraries/physics/src/PhysicsEngine.h | 1 + 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index dfd28dd8a4..f4aa06e31d 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -29,23 +29,27 @@ PhysicsEngine::~PhysicsEngine() { // begin EntitySimulation overrides void PhysicsEngine::updateEntitiesInternal(const quint64& now) { - // NOTE: the grand order of operations is: - // (1) relay incoming changes - // (2) step simulation - // (3) synchronize outgoing motion states - // (4) send outgoing packets - - // this is step (4) - QSet::iterator stateItr = _outgoingPackets.begin(); - while (stateItr != _outgoingPackets.end()) { - ObjectMotionState* state = *stateItr; - if (state->doesNotNeedToSendUpdate()) { - stateItr = _outgoingPackets.erase(stateItr); - } else if (state->shouldSendUpdate(_numSubsteps)) { - state->sendUpdate(_entityPacketSender, _numSubsteps); - ++stateItr; - } else { - ++stateItr; + // no need to send updates unless the physics simulation has actually stepped + if (_lastNumSubstepsAtUpdateInternal != _numSubsteps) { + _lastNumSubstepsAtUpdateInternal = _numSubsteps; + // NOTE: the grand order of operations is: + // (1) relay incoming changes + // (2) step simulation + // (3) synchronize outgoing motion states + // (4) send outgoing packets + + // this is step (4) + QSet::iterator stateItr = _outgoingPackets.begin(); + while (stateItr != _outgoingPackets.end()) { + ObjectMotionState* state = *stateItr; + if (state->doesNotNeedToSendUpdate()) { + stateItr = _outgoingPackets.erase(stateItr); + } else if (state->shouldSendUpdate(_numSubsteps)) { + state->sendUpdate(_entityPacketSender, _numSubsteps); + ++stateItr; + } else { + ++stateItr; + } } } } diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index 347f7c2620..67a0076b6c 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -114,6 +114,7 @@ private: ContactMap _contactMap; uint32_t _numContactFrames = 0; + uint32_t _lastNumSubstepsAtUpdateInternal = 0; }; #endif // hifi_PhysicsEngine_h