From 505332c367b925421fab203d75ae2c0fb25a166d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 30 Jun 2015 10:19:03 -0700 Subject: [PATCH] include action data among physics initiated network updates from interface to entity-server --- libraries/physics/src/EntityMotionState.cpp | 25 ++++++++++++++++----- libraries/physics/src/EntityMotionState.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index d04d190145..f4b4f2e500 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -69,6 +69,7 @@ EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer _serverAngularVelocity(0.0f), _serverGravity(0.0f), _serverAcceleration(0.0f), + _serverActionData(QByteArray()), _lastMeasureStep(0), _lastVelocity(glm::vec3(0.0f)), _measuredAcceleration(glm::vec3(0.0f)), @@ -95,6 +96,7 @@ void EntityMotionState::updateServerPhysicsVariables() { _serverVelocity = _entity->getVelocity(); _serverAngularVelocity = _entity->getAngularVelocity(); _serverAcceleration = _entity->getAcceleration(); + _serverActionData = _entity->getActionData(); } // virtual @@ -250,6 +252,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { _serverVelocity = bulletToGLM(_body->getLinearVelocity()); _serverAngularVelocity = bulletToGLM(_body->getAngularVelocity()); _lastStep = simulationStep; + _serverActionData = _entity->getActionData(); _sentInactive = true; return false; } @@ -284,6 +287,10 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { _serverPosition += dt * _serverVelocity; } + if (_serverActionData != _entity->getActionData()) { + return true; + } + // 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. @@ -320,7 +327,8 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { // Bullet caps the effective rotation velocity inside its rotation integration step, therefore // we must integrate with the same algorithm and timestep in order achieve similar results. for (int i = 0; i < numSteps; ++i) { - _serverRotation = glm::normalize(computeBulletRotationStep(_serverAngularVelocity, PHYSICS_ENGINE_FIXED_SUBSTEP) * _serverRotation); + _serverRotation = glm::normalize(computeBulletRotationStep(_serverAngularVelocity, + PHYSICS_ENGINE_FIXED_SUBSTEP) * _serverRotation); } } const float MIN_ROTATION_DOT = 0.99999f; // This corresponds to about 0.5 degrees of rotation @@ -363,8 +371,8 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& s return usecTimestampNow() > _nextOwnershipBid; } return false; - } - + } + return remoteSimulationOutOfSync(simulationStep); } @@ -405,9 +413,12 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q const float DYNAMIC_LINEAR_VELOCITY_THRESHOLD = 0.05f; // 5 cm/sec const float DYNAMIC_ANGULAR_VELOCITY_THRESHOLD = 0.087266f; // ~5 deg/sec - bool movingSlowly = glm::length2(_entity->getVelocity()) < (DYNAMIC_LINEAR_VELOCITY_THRESHOLD * DYNAMIC_LINEAR_VELOCITY_THRESHOLD) - && glm::length2(_entity->getAngularVelocity()) < (DYNAMIC_ANGULAR_VELOCITY_THRESHOLD * DYNAMIC_ANGULAR_VELOCITY_THRESHOLD) - && _entity->getAcceleration() == glm::vec3(0.0f); + + bool movingSlowlyLinear = + glm::length2(_entity->getVelocity()) < (DYNAMIC_LINEAR_VELOCITY_THRESHOLD * DYNAMIC_LINEAR_VELOCITY_THRESHOLD); + bool movingSlowlyAngular = glm::length2(_entity->getAngularVelocity()) < + (DYNAMIC_ANGULAR_VELOCITY_THRESHOLD * DYNAMIC_ANGULAR_VELOCITY_THRESHOLD); + bool movingSlowly = movingSlowlyLinear && movingSlowlyAngular && _entity->getAcceleration() == glm::vec3(0.0f); if (movingSlowly) { // velocities might not be zero, but we'll fake them as such, which will hopefully help convince @@ -425,6 +436,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q _serverVelocity = _entity->getVelocity(); _serverAcceleration = _entity->getAcceleration(); _serverAngularVelocity = _entity->getAngularVelocity(); + _serverActionData = _entity->getActionData(); EntityItemProperties properties; @@ -434,6 +446,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q properties.setVelocity(_serverVelocity); properties.setAcceleration(_serverAcceleration); properties.setAngularVelocity(_serverAngularVelocity); + properties.setActionData(_serverActionData); // set the LastEdited of the properties but NOT the entity itself quint64 now = usecTimestampNow(); diff --git a/libraries/physics/src/EntityMotionState.h b/libraries/physics/src/EntityMotionState.h index 9f7bafd416..3f427d42e2 100644 --- a/libraries/physics/src/EntityMotionState.h +++ b/libraries/physics/src/EntityMotionState.h @@ -107,6 +107,7 @@ protected: glm::vec3 _serverAngularVelocity; // radians per second glm::vec3 _serverGravity; glm::vec3 _serverAcceleration; + QByteArray _serverActionData; uint32_t _lastMeasureStep; glm::vec3 _lastVelocity;