From dcf28937cfd022af646c71e2538f77a14f7834f9 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 11 Apr 2016 21:19:55 -0700 Subject: [PATCH] cleanup cached Physics::sessionUUID --- interface/src/Application.cpp | 7 ++----- libraries/physics/src/EntityMotionState.cpp | 20 ++++++++++--------- libraries/physics/src/EntityMotionState.h | 6 +++--- .../physics/src/PhysicalEntitySimulation.cpp | 12 +++++------ .../physics/src/PhysicalEntitySimulation.h | 2 +- libraries/physics/src/PhysicsEngine.cpp | 11 +++++----- libraries/physics/src/PhysicsEngine.h | 4 ---- 7 files changed, 28 insertions(+), 34 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 65bbfd7d6c..eb9a0c8661 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3446,7 +3446,7 @@ void Application::update(float deltaTime) { getEntities()->getTree()->withWriteLock([&] { PerformanceTimer perfTimer("handleOutgoingChanges"); const VectorOfMotionStates& outgoingChanges = _physicsEngine->getOutgoingChanges(); - _entitySimulation.handleOutgoingChanges(outgoingChanges, Physics::getSessionUUID()); + _entitySimulation.handleOutgoingChanges(outgoingChanges); avatarManager->handleOutgoingChanges(outgoingChanges); }); @@ -4542,10 +4542,7 @@ bool Application::acceptURL(const QString& urlString, bool defaultUpload) { } void Application::setSessionUUID(const QUuid& sessionUUID) const { - // HACK: until we swap the library dependency order between physics and entities - // we cache the sessionID in two distinct places for physics. - Physics::setSessionUUID(sessionUUID); // TODO: remove this one - _physicsEngine->setSessionUUID(sessionUUID); + Physics::setSessionUUID(sessionUUID); } bool Application::askToSetAvatarUrl(const QString& url) { diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index a9dcb4a16c..5dd6edddda 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -223,7 +223,6 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { if (_entity->getSimulatorID().isNull()) { _loopsWithoutOwner++; - if (_loopsWithoutOwner > LOOPS_FOR_SIMULATION_ORPHAN && usecTimestampNow() > _nextOwnershipBid) { upgradeOutgoingPriority(VOLUNTEER_SIMULATION_PRIORITY); } @@ -255,11 +254,13 @@ btCollisionShape* EntityMotionState::computeNewShape() { return getShapeManager()->getShape(shapeInfo); } -bool EntityMotionState::isCandidateForOwnership(const QUuid& sessionID) const { +bool EntityMotionState::isCandidateForOwnership() const { assert(_body); assert(_entity); assert(entityTreeIsLocked()); - return _outgoingPriority != 0 || sessionID == _entity->getSimulatorID() || _entity->actionDataNeedsTransmit(); + return _outgoingPriority != 0 + || Physics::getSessionUUID() == _entity->getSimulatorID() + || _entity->actionDataNeedsTransmit(); } bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { @@ -384,7 +385,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { return (fabsf(glm::dot(actualRotation, _serverRotation)) < MIN_ROTATION_DOT); } -bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& sessionID) { +bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) { // NOTE: we expect _entity and _body to be valid in this context, since shouldSendUpdate() is only called // after doesNotNeedToSendUpdate() returns false and that call should return 'true' if _entity or _body are NULL. assert(_entity); @@ -399,7 +400,7 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& s return true; } - if (_entity->getSimulatorID() != sessionID) { + if (_entity->getSimulatorID() != Physics::getSessionUUID()) { // we don't own the simulation bool shouldBid = _outgoingPriority > 0 && // but we would like to own it and usecTimestampNow() > _nextOwnershipBid; // it is time to bid again @@ -415,7 +416,7 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& s return remoteSimulationOutOfSync(simulationStep); } -void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const QUuid& sessionID, uint32_t step) { +void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t step) { assert(_entity); assert(entityTreeIsLocked()); @@ -514,9 +515,10 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q // but we remember we do still own it... and rely on the server to tell us we don't properties.clearSimulationOwner(); _outgoingPriority = 0; - } else if (sessionID != _entity->getSimulatorID()) { + } else if (Physics::getSessionUUID() != _entity->getSimulatorID()) { // we don't own the simulation for this entity yet, but we're sending a bid for it - properties.setSimulationOwner(sessionID, glm::max(_outgoingPriority, VOLUNTEER_SIMULATION_PRIORITY)); + properties.setSimulationOwner(Physics::getSessionUUID(), + glm::max(_outgoingPriority, VOLUNTEER_SIMULATION_PRIORITY)); _nextOwnershipBid = now + USECS_BETWEEN_OWNERSHIP_BIDS; _outgoingPriority = 0; // reset outgoing priority whenever we bid } else if (_outgoingPriority != _entity->getSimulationPriority()) { @@ -526,7 +528,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q properties.clearSimulationOwner(); } else { // we just need to change the priority - properties.setSimulationOwner(sessionID, _outgoingPriority); + properties.setSimulationOwner(Physics::getSessionUUID(), _outgoingPriority); } } diff --git a/libraries/physics/src/EntityMotionState.h b/libraries/physics/src/EntityMotionState.h index ac16ec6d5d..8150de22d6 100644 --- a/libraries/physics/src/EntityMotionState.h +++ b/libraries/physics/src/EntityMotionState.h @@ -43,10 +43,10 @@ public: // this relays outgoing position/rotation to the EntityItem virtual void setWorldTransform(const btTransform& worldTrans) override; - bool isCandidateForOwnership(const QUuid& sessionID) const; + bool isCandidateForOwnership() const; bool remoteSimulationOutOfSync(uint32_t simulationStep); - bool shouldSendUpdate(uint32_t simulationStep, const QUuid& sessionID); - void sendUpdate(OctreeEditPacketSender* packetSender, const QUuid& sessionID, uint32_t step); + bool shouldSendUpdate(uint32_t simulationStep); + void sendUpdate(OctreeEditPacketSender* packetSender, uint32_t step); virtual uint32_t getIncomingDirtyFlags() override; virtual void clearIncomingDirtyFlags() override; diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index 2d219915c8..70ca512646 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -251,7 +251,7 @@ void PhysicalEntitySimulation::getObjectsToChange(VectorOfMotionStates& result) _pendingChanges.clear(); } -void PhysicalEntitySimulation::handleOutgoingChanges(const VectorOfMotionStates& motionStates, const QUuid& sessionID) { +void PhysicalEntitySimulation::handleOutgoingChanges(const VectorOfMotionStates& motionStates) { QMutexLocker lock(&_mutex); // walk the motionStates looking for those that correspond to entities @@ -261,7 +261,7 @@ void PhysicalEntitySimulation::handleOutgoingChanges(const VectorOfMotionStates& EntityMotionState* entityState = static_cast(state); EntityItemPointer entity = entityState->getEntity(); assert(entity.get()); - if (entityState->isCandidateForOwnership(sessionID)) { + if (entityState->isCandidateForOwnership()) { _outgoingChanges.insert(entityState); } _entitiesToSort.insert(entity); @@ -272,7 +272,7 @@ void PhysicalEntitySimulation::handleOutgoingChanges(const VectorOfMotionStates& if (_lastStepSendPackets != numSubsteps) { _lastStepSendPackets = numSubsteps; - if (sessionID.isNull()) { + if (Physics::getSessionUUID().isNull()) { // usually don't get here, but if so --> nothing to do _outgoingChanges.clear(); return; @@ -282,12 +282,12 @@ void PhysicalEntitySimulation::handleOutgoingChanges(const VectorOfMotionStates& QSet::iterator stateItr = _outgoingChanges.begin(); while (stateItr != _outgoingChanges.end()) { EntityMotionState* state = *stateItr; - if (!state->isCandidateForOwnership(sessionID)) { + if (!state->isCandidateForOwnership()) { // prune stateItr = _outgoingChanges.erase(stateItr); - } else if (state->shouldSendUpdate(numSubsteps, sessionID)) { + } else if (state->shouldSendUpdate(numSubsteps)) { // update - state->sendUpdate(_entityPacketSender, sessionID, numSubsteps); + state->sendUpdate(_entityPacketSender, numSubsteps); ++stateItr; } else { ++stateItr; diff --git a/libraries/physics/src/PhysicalEntitySimulation.h b/libraries/physics/src/PhysicalEntitySimulation.h index 7138fb924c..935ee57115 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.h +++ b/libraries/physics/src/PhysicalEntitySimulation.h @@ -54,7 +54,7 @@ public: void setObjectsToChange(const VectorOfMotionStates& objectsToChange); void getObjectsToChange(VectorOfMotionStates& result); - void handleOutgoingChanges(const VectorOfMotionStates& motionStates, const QUuid& sessionID); + void handleOutgoingChanges(const VectorOfMotionStates& motionStates); void handleCollisionEvents(const CollisionEvents& collisionEvents); EntityEditPacketSender* getPacketSender() { return _entityPacketSender; } diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 0040c19c3d..9312504c72 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -20,7 +20,6 @@ PhysicsEngine::PhysicsEngine(const glm::vec3& offset) : _originOffset(offset), - _sessionID(), _myAvatarController(nullptr) { } @@ -286,20 +285,20 @@ void PhysicsEngine::doOwnershipInfection(const btCollisionObject* objectA, const ObjectMotionState* motionStateB = static_cast(objectB->getUserPointer()); if (motionStateB && - ((motionStateA && motionStateA->getSimulatorID() == _sessionID && !objectA->isStaticObject()) || + ((motionStateA && motionStateA->getSimulatorID() == Physics::getSessionUUID() && !objectA->isStaticObject()) || (objectA == characterObject))) { // NOTE: we might own the simulation of a kinematic object (A) // but we don't claim ownership of kinematic objects (B) based on collisions here. - if (!objectB->isStaticOrKinematicObject() && motionStateB->getSimulatorID() != _sessionID) { + if (!objectB->isStaticOrKinematicObject() && motionStateB->getSimulatorID() != Physics::getSessionUUID()) { quint8 priorityA = motionStateA ? motionStateA->getSimulationPriority() : PERSONAL_SIMULATION_PRIORITY; motionStateB->bump(priorityA); } } else if (motionStateA && - ((motionStateB && motionStateB->getSimulatorID() == _sessionID && !objectB->isStaticObject()) || + ((motionStateB && motionStateB->getSimulatorID() == Physics::getSessionUUID() && !objectB->isStaticObject()) || (objectB == characterObject))) { // SIMILARLY: we might own the simulation of a kinematic object (B) // but we don't claim ownership of kinematic objects (A) based on collisions here. - if (!objectA->isStaticOrKinematicObject() && motionStateA->getSimulatorID() != _sessionID) { + if (!objectA->isStaticOrKinematicObject() && motionStateA->getSimulatorID() != Physics::getSessionUUID()) { quint8 priorityB = motionStateB ? motionStateB->getSimulationPriority() : PERSONAL_SIMULATION_PRIORITY; motionStateA->bump(priorityB); } @@ -333,7 +332,7 @@ void PhysicsEngine::updateContactMap() { _contactMap[ContactKey(a, b)].update(_numContactFrames, contactManifold->getContactPoint(0)); } - if (!_sessionID.isNull()) { + if (!Physics::getSessionUUID().isNull()) { doOwnershipInfection(objectA, objectB); } } diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index f644d6f5b2..38caf079e7 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -87,8 +87,6 @@ public: void removeAction(const QUuid actionID); void forEachAction(std::function actor); - void setSessionUUID(const QUuid& sessionID) { _sessionID = sessionID; } - private: void addObjectToDynamicsWorld(ObjectMotionState* motionState); @@ -112,7 +110,6 @@ private: QHash _objectActions; glm::vec3 _originOffset; - QUuid _sessionID; CharacterController* _myAvatarController; @@ -121,7 +118,6 @@ private: bool _dumpNextStats = false; bool _hasOutgoingChanges = false; - }; typedef std::shared_ptr PhysicsEnginePointer;