From 01fd6dc8f6e32b27b8de1ac044e5760841b33aa0 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 4 Jan 2018 13:47:31 -0800 Subject: [PATCH] add comments to make code more clear --- libraries/physics/src/EntityMotionState.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 8d6fdc7464..33ac887f4f 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -503,19 +503,20 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) { // we don't own the simulation // NOTE: we do not volunteer to own kinematic or static objects - uint8_t insufficientPriority = _body->isStaticOrKinematicObject() ? VOLUNTEER_SIMULATION_PRIORITY : 0; + uint8_t volunteerPriority = _body->isStaticOrKinematicObject() ? VOLUNTEER_SIMULATION_PRIORITY : 0; - bool shouldBid = _outgoingPriority > insufficientPriority && // but we would like to own it AND + bool shouldBid = _outgoingPriority > volunteerPriority && // but we would like to own it AND usecTimestampNow() > _nextOwnershipBid; // it is time to bid again if (shouldBid && _outgoingPriority < _entity->getSimulationPriority()) { - // we are insufficiently interested so clear our interest + // we are insufficiently interested so clear _outgoingPriority // and reset the bid expiry _outgoingPriority = 0; _nextOwnershipBid = usecTimestampNow() + USECS_BETWEEN_OWNERSHIP_BIDS; } return shouldBid; } else { - // make sure _outgoingPriority is not less than current owned priority + // When we own the simulation: make sure _outgoingPriority is not less than current owned priority + // because: an _outgoingPriority of zero indicates that we should drop ownership when we have it. upgradeOutgoingPriority(_entity->getSimulationPriority()); } @@ -622,8 +623,10 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ _entity->setPendingOwnershipPriority(_outgoingPriority, now); // don't forget to remember that we have made a bid _entity->rememberHasSimulationOwnershipBid(); - // ...then reset _outgoingPriority in preparation for the next frame + // ...then reset _outgoingPriority _outgoingPriority = 0; + // _outgoingPrioriuty will be re-computed before next bid, + // or will be set to agree with ownership priority should we win the bid } else if (_outgoingPriority != _entity->getSimulationPriority()) { // we own the simulation but our desired priority has changed if (_outgoingPriority == 0) {