remove some redundancy checks

no need to assert(_entity) : guaranteed by ctor and dtor logic
moved some checks around to avoid redundant work
This commit is contained in:
Andrew Meadows 2018-03-15 15:21:43 -07:00
parent dcf5110caa
commit 49dce6fa1a

View file

@ -120,7 +120,6 @@ void EntityMotionState::handleDeactivation() {
// virtual // virtual
void EntityMotionState::handleEasyChanges(uint32_t& flags) { void EntityMotionState::handleEasyChanges(uint32_t& flags) {
assert(_entity);
assert(entityTreeIsLocked()); assert(entityTreeIsLocked());
updateServerPhysicsVariables(); updateServerPhysicsVariables();
ObjectMotionState::handleEasyChanges(flags); ObjectMotionState::handleEasyChanges(flags);
@ -177,7 +176,6 @@ void EntityMotionState::handleEasyChanges(uint32_t& flags) {
// virtual // virtual
bool EntityMotionState::handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine* engine) { bool EntityMotionState::handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine* engine) {
assert(_entity);
updateServerPhysicsVariables(); updateServerPhysicsVariables();
return ObjectMotionState::handleHardAndEasyChanges(flags, engine); return ObjectMotionState::handleHardAndEasyChanges(flags, engine);
} }
@ -255,7 +253,6 @@ void EntityMotionState::getWorldTransform(btTransform& worldTrans) const {
// This callback is invoked by the physics simulation at the end of each simulation step... // This callback is invoked by the physics simulation at the end of each simulation step...
// iff the corresponding RigidBody is DYNAMIC and ACTIVE. // iff the corresponding RigidBody is DYNAMIC and ACTIVE.
void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { void EntityMotionState::setWorldTransform(const btTransform& worldTrans) {
assert(_entity);
assert(entityTreeIsLocked()); assert(entityTreeIsLocked());
measureBodyAcceleration(); measureBodyAcceleration();
@ -327,18 +324,25 @@ void EntityMotionState::setShape(const btCollisionShape* shape) {
bool EntityMotionState::isCandidateForOwnership() const { bool EntityMotionState::isCandidateForOwnership() const {
assert(_body); assert(_body);
assert(_entity);
assert(entityTreeIsLocked()); assert(entityTreeIsLocked());
return _outgoingPriority != 0 if (isLocallyOwned()) {
|| isLocallyOwned() return true;
|| _entity->dynamicDataNeedsTransmit(); } else if (_entity->getClientOnly()) {
// don't send updates for someone else's avatarEntities
return false;
}
return _outgoingPriority != 0 || _entity->dynamicDataNeedsTransmit();
} }
bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
DETAILED_PROFILE_RANGE(simulation_physics, "CheckOutOfSync");
// NOTE: we only get here if we think we own the simulation // NOTE: we only get here if we think we own the simulation
DETAILED_PROFILE_RANGE(simulation_physics, "CheckOutOfSync");
assert(_body); assert(_body);
// Since 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());
bool parentTransformSuccess; bool parentTransformSuccess;
Transform localToWorld = _entity->getParentTransform(parentTransformSuccess); Transform localToWorld = _entity->getParentTransform(parentTransformSuccess);
Transform worldToLocal; Transform worldToLocal;
@ -417,10 +421,6 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
return true; return true;
} }
if (_entity->shouldSuppressLocationEdits()) {
return false;
}
// Else we measure the error between current and extrapolated transform (according to expected behavior // Else we measure the error between current and extrapolated transform (according to expected behavior
// of remote EntitySimulation) and return true if the error is significant. // of remote EntitySimulation) and return true if the error is significant.
@ -491,14 +491,11 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) {
DETAILED_PROFILE_RANGE(simulation_physics, "ShouldSend"); DETAILED_PROFILE_RANGE(simulation_physics, "ShouldSend");
// NOTE: we expect _entity and _body to be valid in this context, since shouldSendUpdate() is only called // 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. // after doesNotNeedToSendUpdate() returns false and that call should return 'true' if _entity or _body are NULL.
assert(_entity);
assert(_body); assert(_body);
assert(entityTreeIsLocked()); assert(entityTreeIsLocked());
if (_entity->getClientOnly() && _entity->getOwningAvatarID() != Physics::getSessionUUID()) { // this case prevented by isCandidateForOwnership()
// don't send updates for someone else's avatarEntities assert(!(_entity->getClientOnly() && _entity->getOwningAvatarID() != Physics::getSessionUUID()));
return false;
}
if (_entity->dynamicDataNeedsTransmit() || _entity->queryAACubeNeedsUpdate()) { if (_entity->dynamicDataNeedsTransmit() || _entity->queryAACubeNeedsUpdate()) {
return true; return true;
@ -523,10 +520,6 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) {
_nextOwnershipBid = usecTimestampNow() + USECS_BETWEEN_OWNERSHIP_BIDS; _nextOwnershipBid = usecTimestampNow() + USECS_BETWEEN_OWNERSHIP_BIDS;
} }
return shouldBid; return shouldBid;
} else {
// 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());
} }
return remoteSimulationOutOfSync(simulationStep); return remoteSimulationOutOfSync(simulationStep);
@ -534,7 +527,6 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) {
void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t step) { void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t step) {
DETAILED_PROFILE_RANGE(simulation_physics, "Send"); DETAILED_PROFILE_RANGE(simulation_physics, "Send");
assert(_entity);
assert(entityTreeIsLocked()); assert(entityTreeIsLocked());
if (!_body->isActive()) { if (!_body->isActive()) {
@ -807,7 +799,6 @@ QString EntityMotionState::getName() const {
// virtual // virtual
void EntityMotionState::computeCollisionGroupAndMask(int16_t& group, int16_t& mask) const { void EntityMotionState::computeCollisionGroupAndMask(int16_t& group, int16_t& mask) const {
assert(_entity);
_entity->computeCollisionGroupAndFinalMask(group, mask); _entity->computeCollisionGroupAndFinalMask(group, mask);
} }