diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index b2400b797e..6ddf44b82d 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -9,15 +9,18 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "RenderableBoxEntityItem.h" + #include #include #include #include +#include #include -#include "RenderableBoxEntityItem.h" +#include "RenderableDebugableEntityItem.h" EntityItemPointer RenderableBoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return EntityItemPointer(new RenderableBoxEntityItem(entityID, properties)); @@ -27,23 +30,11 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderableBoxEntityItem::render"); Q_ASSERT(getType() == EntityTypes::Box); glm::vec4 cubeColor(toGlm(getXColor()), getLocalRenderAlpha()); - - bool debugSimulationOwnership = args->_debugFlags & RenderArgs::RENDER_DEBUG_SIMULATION_OWNERSHIP; - bool highlightSimulationOwnership = false; - if (debugSimulationOwnership) { - auto nodeList = DependencyManager::get(); - const QUuid& myNodeID = nodeList->getSessionUUID(); - highlightSimulationOwnership = (getSimulatorID() == myNodeID); - } Q_ASSERT(args->_batch); gpu::Batch& batch = *args->_batch; batch.setModelTransform(getTransformToCenter()); - if (highlightSimulationOwnership) { - DependencyManager::get()->renderWireCube(batch, 1.0f, cubeColor); - } else { - DependencyManager::get()->renderSolidCube(batch, 1.0f, cubeColor); - } + DependencyManager::get()->renderSolidCube(batch, 1.0f, cubeColor); RenderableDebugableEntityItem::render(this, args); }; diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.h b/libraries/entities-renderer/src/RenderableBoxEntityItem.h index 06a62706b9..b14da9ee22 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.h @@ -13,7 +13,6 @@ #define hifi_RenderableBoxEntityItem_h #include -#include "RenderableDebugableEntityItem.h" #include "RenderableEntityItem.h" class RenderableBoxEntityItem : public BoxEntityItem { diff --git a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp index ca81ae4f2b..fecc574af2 100644 --- a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp @@ -10,58 +10,57 @@ // +#include "RenderableDebugableEntityItem.h" #include #include #include - #include -#include - -#include "RenderableDebugableEntityItem.h" +#include void RenderableDebugableEntityItem::renderBoundingBox(EntityItem* entity, RenderArgs* args, float puffedOut, glm::vec4& color) { Q_ASSERT(args->_batch); gpu::Batch& batch = *args->_batch; - batch.setModelTransform(entity->getTransformToCenter()); + Transform transform = entity->getTransformToCenter(); + //transform.postScale(entity->getDimensions()); + batch.setModelTransform(transform); DependencyManager::get()->renderWireCube(batch, 1.0f + puffedOut, color); } -void RenderableDebugableEntityItem::renderHoverDot(EntityItem* entity, RenderArgs* args) { - const int SLICES = 8, STACKS = 8; - float radius = 0.05f; - glm::vec4 blueColor(0.0f, 0.0f, 1.0f, 1.0f); - - Q_ASSERT(args->_batch); - gpu::Batch& batch = *args->_batch; - Transform transform = entity->getTransformToCenter(); - // Cancel true dimensions and set scale to 2 * radius (diameter) - transform.postScale(2.0f * glm::vec3(radius, radius, radius) / entity->getDimensions()); - batch.setModelTransform(transform); - DependencyManager::get()->renderSolidSphere(batch, 0.5f, SLICES, STACKS, blueColor); -} - void RenderableDebugableEntityItem::render(EntityItem* entity, RenderArgs* args) { - bool debugSimulationOwnership = args->_debugFlags & RenderArgs::RENDER_DEBUG_SIMULATION_OWNERSHIP; + if (args->_debugFlags & RenderArgs::RENDER_DEBUG_SIMULATION_OWNERSHIP) { + Q_ASSERT(args->_batch); + gpu::Batch& batch = *args->_batch; + Transform transform = entity->getTransformToCenter(); + transform.postScale(entity->getDimensions()); + batch.setModelTransform(transform); + + auto nodeList = DependencyManager::get(); + const QUuid& myNodeID = nodeList->getSessionUUID(); + bool highlightSimulationOwnership = (entity->getSimulatorID() == myNodeID); + if (highlightSimulationOwnership) { + glm::vec4 greenColor(0.0f, 1.0f, 0.2f, 1.0f); + renderBoundingBox(entity, args, 0.08f, greenColor); + } - if (debugSimulationOwnership) { quint64 now = usecTimestampNow(); if (now - entity->getLastEditedFromRemote() < 0.1f * USECS_PER_SECOND) { glm::vec4 redColor(1.0f, 0.0f, 0.0f, 1.0f); - renderBoundingBox(entity, args, 0.2f, redColor); + renderBoundingBox(entity, args, 0.16f, redColor); } if (now - entity->getLastBroadcast() < 0.2f * USECS_PER_SECOND) { glm::vec4 yellowColor(1.0f, 1.0f, 0.2f, 1.0f); - renderBoundingBox(entity, args, 0.3f, yellowColor); + renderBoundingBox(entity, args, 0.24f, yellowColor); } ObjectMotionState* motionState = static_cast(entity->getPhysicsInfo()); if (motionState && motionState->isActive()) { - renderHoverDot(entity, args); + glm::vec4 blueColor(0.0f, 0.0f, 1.0f, 1.0f); + renderBoundingBox(entity, args, 0.32f, blueColor); } } } diff --git a/libraries/entities-renderer/src/RenderableDebugableEntityItem.h b/libraries/entities-renderer/src/RenderableDebugableEntityItem.h index 758bac353b..2680d882f5 100644 --- a/libraries/entities-renderer/src/RenderableDebugableEntityItem.h +++ b/libraries/entities-renderer/src/RenderableDebugableEntityItem.h @@ -17,7 +17,6 @@ class RenderableDebugableEntityItem { public: static void renderBoundingBox(EntityItem* entity, RenderArgs* args, float puffedOut, glm::vec4& color); - static void renderHoverDot(EntityItem* entity, RenderArgs* args); static void render(EntityItem* entity, RenderArgs* args); }; diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index e0bc493a5c..14a64d289e 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -201,14 +201,6 @@ void RenderableModelEntityItem::render(RenderArgs* args) { glm::vec3 position = getPosition(); glm::vec3 dimensions = getDimensions(); - bool debugSimulationOwnership = args->_debugFlags & RenderArgs::RENDER_DEBUG_SIMULATION_OWNERSHIP; - bool highlightSimulationOwnership = false; - if (debugSimulationOwnership) { - auto nodeList = DependencyManager::get(); - const QUuid& myNodeID = nodeList->getSessionUUID(); - highlightSimulationOwnership = (getSimulatorID() == myNodeID); - } - if (hasModel()) { if (_model) { if (QUrl(getModelURL()) != _model->getURL()) { @@ -274,11 +266,6 @@ void RenderableModelEntityItem::render(RenderArgs* args) { } } } - - if (highlightSimulationOwnership) { - glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f); - RenderableDebugableEntityItem::renderBoundingBox(this, args, 0.0f, greenColor); - } } else { glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f); RenderableDebugableEntityItem::renderBoundingBox(this, args, 0.0f, greenColor); diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index d5cb7d11b8..b0aaebb2c8 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -9,6 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "RenderableSphereEntityItem.h" + #include #include @@ -18,7 +20,7 @@ #include #include -#include "RenderableSphereEntityItem.h" +#include "RenderableDebugableEntityItem.h" EntityItemPointer RenderableSphereEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return EntityItemPointer(new RenderableSphereEntityItem(entityID, properties)); @@ -39,4 +41,6 @@ void RenderableSphereEntityItem::render(RenderArgs* args) { gpu::Batch& batch = *args->_batch; batch.setModelTransform(getTransformToCenter()); DependencyManager::get()->renderSolidSphere(batch, 0.5f, SLICES, STACKS, sphereColor); + + RenderableDebugableEntityItem::render(this, args); }; diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 23237cab32..186ff40f60 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -180,10 +180,6 @@ btCollisionShape* EntityMotionState::computeNewShape() { return nullptr; } -// RELIABLE_SEND_HACK: until we have truly reliable resends of non-moving updates -// we alwasy resend packets for objects that have stopped moving up to some max limit. -const int MAX_NUM_NON_MOVING_UPDATES = 5; - bool EntityMotionState::isCandidateForOwnership(const QUuid& sessionID) const { if (!_body || !_entity) { return false; @@ -495,6 +491,10 @@ void EntityMotionState::measureBodyAcceleration() { glm::vec3 velocity = bulletToGLM(_body->getLinearVelocity()); _measuredAcceleration = (velocity / powf(1.0f - _body->getLinearDamping(), dt) - _lastVelocity) * invDt; _lastVelocity = velocity; + if (numSubsteps > PHYSICS_ENGINE_MAX_NUM_SUBSTEPS && !_candidateForOwnership) { + _loopsSinceOwnershipBid = 0; + _loopsWithoutOwner = 0; + } } } glm::vec3 EntityMotionState::getObjectLinearVelocityChange() const { diff --git a/libraries/physics/src/ObjectMotionState.h b/libraries/physics/src/ObjectMotionState.h index b17dc67cff..561ce02d62 100644 --- a/libraries/physics/src/ObjectMotionState.h +++ b/libraries/physics/src/ObjectMotionState.h @@ -53,8 +53,6 @@ const uint32_t OUTGOING_DIRTY_PHYSICS_FLAGS = EntityItem::DIRTY_TRANSFORM | Enti class OctreeEditPacketSender; class PhysicsEngine; -extern const int MAX_NUM_NON_MOVING_UPDATES; - class ObjectMotionState : public btMotionState { public: // These poroperties of the PhysicsEngine are "global" within the context of all ObjectMotionStates diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index e5c974dfbc..55fc5e6295 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -227,8 +227,7 @@ void PhysicsEngine::stepSimulation() { // (3) synchronize outgoing motion states // (4) send outgoing packets - const int MAX_NUM_SUBSTEPS = 4; - const float MAX_TIMESTEP = (float)MAX_NUM_SUBSTEPS * PHYSICS_ENGINE_FIXED_SUBSTEP; + const float MAX_TIMESTEP = (float)PHYSICS_ENGINE_MAX_NUM_SUBSTEPS * PHYSICS_ENGINE_FIXED_SUBSTEP; float dt = 1.0e-6f * (float)(_clock.getTimeMicroseconds()); _clock.reset(); float timeStep = btMin(dt, MAX_TIMESTEP); @@ -245,7 +244,7 @@ void PhysicsEngine::stepSimulation() { _characterController->preSimulation(timeStep); } - int numSubsteps = _dynamicsWorld->stepSimulation(timeStep, MAX_NUM_SUBSTEPS, PHYSICS_ENGINE_FIXED_SUBSTEP); + int numSubsteps = _dynamicsWorld->stepSimulation(timeStep, PHYSICS_ENGINE_MAX_NUM_SUBSTEPS, PHYSICS_ENGINE_FIXED_SUBSTEP); if (numSubsteps > 0) { BT_PROFILE("postSimulation"); _numSubsteps += (uint32_t)numSubsteps; diff --git a/libraries/shared/src/PhysicsHelpers.h b/libraries/shared/src/PhysicsHelpers.h index bef7275067..0e58ae99f0 100644 --- a/libraries/shared/src/PhysicsHelpers.h +++ b/libraries/shared/src/PhysicsHelpers.h @@ -15,6 +15,7 @@ #include #include +const int PHYSICS_ENGINE_MAX_NUM_SUBSTEPS = 4; const float PHYSICS_ENGINE_FIXED_SUBSTEP = 1.0f / 60.0f; // return incremental rotation (Bullet-style) caused by angularVelocity over timeStep