From 98fa9967526076ba437aac890fa657c8a1fe61fd Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Mon, 22 Jun 2015 16:56:49 -0700 Subject: [PATCH 01/11] Cleaning out comments --- interface/resources/qml/Tooltip.qml | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/resources/qml/Tooltip.qml b/interface/resources/qml/Tooltip.qml index c836030ba1..779ba63b3a 100644 --- a/interface/resources/qml/Tooltip.qml +++ b/interface/resources/qml/Tooltip.qml @@ -6,9 +6,7 @@ import "styles" Hifi.Tooltip { id: root HifiConstants { id: hifi } - // FIXME adjust position based on the edges of the screen x: (lastMousePosition.x > surfaceSize.width/2) ? lastMousePosition.x - 140 : lastMousePosition.x + 20 - //y: lastMousePosition.y + 5 y: (lastMousePosition.y > surfaceSize.height/2) ? lastMousePosition.y - 70 : lastMousePosition.y + 5 implicitWidth: border.implicitWidth implicitHeight: border.implicitHeight From d1526c25b2d39722aa9e551f17beb79b52db5614 Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Tue, 23 Jun 2015 10:08:48 -0700 Subject: [PATCH 02/11] Starting new tooltip design in QML --- .../resources/images/NoPictureProvided.svg | 3 +++ interface/resources/images/header_sep.svg | 3 +++ .../resources/images/tooltip_container.svg | 3 +++ interface/resources/qml/Tooltip.qml | 25 ++++++++++++++++--- 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 interface/resources/images/NoPictureProvided.svg create mode 100644 interface/resources/images/header_sep.svg create mode 100644 interface/resources/images/tooltip_container.svg diff --git a/interface/resources/images/NoPictureProvided.svg b/interface/resources/images/NoPictureProvided.svg new file mode 100644 index 0000000000..003b499bbc --- /dev/null +++ b/interface/resources/images/NoPictureProvided.svg @@ -0,0 +1,3 @@ + + +2015-06-22 17:35ZCanvas 1No infoNo Picture Provided diff --git a/interface/resources/images/header_sep.svg b/interface/resources/images/header_sep.svg new file mode 100644 index 0000000000..ae1434860c --- /dev/null +++ b/interface/resources/images/header_sep.svg @@ -0,0 +1,3 @@ + + +2015-06-22 17:35ZCanvas 1No info diff --git a/interface/resources/images/tooltip_container.svg b/interface/resources/images/tooltip_container.svg new file mode 100644 index 0000000000..2c89bbbd7d --- /dev/null +++ b/interface/resources/images/tooltip_container.svg @@ -0,0 +1,3 @@ + + +2015-06-22 17:35ZCanvas 1Info diff --git a/interface/resources/qml/Tooltip.qml b/interface/resources/qml/Tooltip.qml index 779ba63b3a..10b3006da4 100644 --- a/interface/resources/qml/Tooltip.qml +++ b/interface/resources/qml/Tooltip.qml @@ -6,17 +6,19 @@ import "styles" Hifi.Tooltip { id: root HifiConstants { id: hifi } - x: (lastMousePosition.x > surfaceSize.width/2) ? lastMousePosition.x - 140 : lastMousePosition.x + 20 - y: (lastMousePosition.y > surfaceSize.height/2) ? lastMousePosition.y - 70 : lastMousePosition.y + 5 + x: (lastMousePosition.x > surfaceSize.width/2) ? lastMousePosition.x - root.width : lastMousePosition.x + 20 + y: (lastMousePosition.y > surfaceSize.height/2) ? lastMousePosition.y - root.height : lastMousePosition.y + 5 implicitWidth: border.implicitWidth implicitHeight: border.implicitHeight Border { id: border anchors.fill: parent - implicitWidth: text.implicitWidth - implicitHeight: Math.max(text.implicitHeight, 64) + implicitWidth: tooltipBackground.implicitWidth + //implicitHeight: Math.max(text.implicitHeight, 64) + implicitHeight: tooltipBackground.implicitHeight + /* Text { id: text anchors.fill: parent @@ -24,6 +26,21 @@ Hifi.Tooltip { font.pixelSize: hifi.fonts.pixelSize / 2 text: root.text wrapMode: Original.Text.WordWrap + }*/ + + Image { + id: tooltipBackground + source: "../images/NoPictureProvided.svg" + width: 323 + height: 423 + anchors.fill: parent + + /* + Image { + id: tooltipBackground + source: "../images/NoPictureProvided.svg" + anchors.fill: parent + }*/ } } } From 0c2e208044d5f16a540de22ea931944c8328855b Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Tue, 23 Jun 2015 13:54:19 -0700 Subject: [PATCH 03/11] Added basic layout to tooltip QML --- interface/resources/qml/Tooltip.qml | 56 ++++++++++++++++++----------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/interface/resources/qml/Tooltip.qml b/interface/resources/qml/Tooltip.qml index 10b3006da4..4cca4c4c38 100644 --- a/interface/resources/qml/Tooltip.qml +++ b/interface/resources/qml/Tooltip.qml @@ -1,13 +1,14 @@ import Hifi 1.0 as Hifi import QtQuick 2.3 as Original +import QtQuick.Layouts 1.1 import "controls" import "styles" Hifi.Tooltip { id: root HifiConstants { id: hifi } - x: (lastMousePosition.x > surfaceSize.width/2) ? lastMousePosition.x - root.width : lastMousePosition.x + 20 - y: (lastMousePosition.y > surfaceSize.height/2) ? lastMousePosition.y - root.height : lastMousePosition.y + 5 + x: (lastMousePosition.x > surfaceSize.width/2) ? lastMousePosition.x - root.width : lastMousePosition.x + y: (lastMousePosition.y > surfaceSize.height/2) ? lastMousePosition.y - root.height : lastMousePosition.y implicitWidth: border.implicitWidth implicitHeight: border.implicitHeight @@ -18,29 +19,44 @@ Hifi.Tooltip { //implicitHeight: Math.max(text.implicitHeight, 64) implicitHeight: tooltipBackground.implicitHeight - /* - Text { - id: text - anchors.fill: parent - anchors.margins: 16 - font.pixelSize: hifi.fonts.pixelSize / 2 - text: root.text - wrapMode: Original.Text.WordWrap - }*/ - - Image { + Original.Image { id: tooltipBackground - source: "../images/NoPictureProvided.svg" + source: "../images/tooltip_container.svg" width: 323 height: 423 anchors.fill: parent - /* - Image { - id: tooltipBackground - source: "../images/NoPictureProvided.svg" - anchors.fill: parent - }*/ + ColumnLayout { + spacing: 5 + + Text { + id: textPlace + //anchors.fill: parent + anchors.margins: 5 + font.pixelSize: hifi.fonts.pixelSize / 2 + text: root.text + wrapMode: Original.Text.WordWrap + } + + Original.Image { + id: tooltipPic + source: "../images/NoPictureProvided.svg" + //anchors.fill: parent + anchors.margins: 5 + verticalAlignment: Original.Image.AlignVCenter + //horizontalAlignment: Image.AlignHCenter + } + + Text { + id: textDescription + //anchors.fill: parent + anchors.margins: 5 + font.pixelSize: hifi.fonts.pixelSize / 2 + text: root.text + wrapMode: Original.Text.WordWrap + } + + } } } } From 210a1205a787971b812f8dafcb30fa8515a93e83 Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Thu, 25 Jun 2015 14:07:03 -0700 Subject: [PATCH 04/11] More layout changes --- interface/resources/qml/Tooltip.qml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/interface/resources/qml/Tooltip.qml b/interface/resources/qml/Tooltip.qml index 4cca4c4c38..216d1a093f 100644 --- a/interface/resources/qml/Tooltip.qml +++ b/interface/resources/qml/Tooltip.qml @@ -12,25 +12,28 @@ Hifi.Tooltip { implicitWidth: border.implicitWidth implicitHeight: border.implicitHeight + /* Border { id: border anchors.fill: parent implicitWidth: tooltipBackground.implicitWidth //implicitHeight: Math.max(text.implicitHeight, 64) - implicitHeight: tooltipBackground.implicitHeight + implicitHeight: tooltipBackground.implicitHeight*/ - Original.Image { - id: tooltipBackground - source: "../images/tooltip_container.svg" - width: 323 - height: 423 - anchors.fill: parent + Original.Rectangle { + id: border + color: "#7f000000" + implicitWidth: 322 + implicitHeight: col.height + hifi.layout.spacing * 2 ColumnLayout { + id: col spacing: 5 Text { id: textPlace + color: "#ffffff" + width: border.implicitWidth //anchors.fill: parent anchors.margins: 5 font.pixelSize: hifi.fonts.pixelSize / 2 @@ -49,6 +52,8 @@ Hifi.Tooltip { Text { id: textDescription + color: "#ffffff" + width: border.implicitWidth //anchors.fill: parent anchors.margins: 5 font.pixelSize: hifi.fonts.pixelSize / 2 @@ -58,5 +63,5 @@ Hifi.Tooltip { } } - } -} + //} +} \ No newline at end of file From de26dc9c49519918432b03dd7c3e17993396d65f Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Thu, 25 Jun 2015 14:15:06 -0700 Subject: [PATCH 05/11] Further changes to tooltip --- interface/resources/qml/Tooltip.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/Tooltip.qml b/interface/resources/qml/Tooltip.qml index 216d1a093f..d8ba62840a 100644 --- a/interface/resources/qml/Tooltip.qml +++ b/interface/resources/qml/Tooltip.qml @@ -38,7 +38,7 @@ Hifi.Tooltip { anchors.margins: 5 font.pixelSize: hifi.fonts.pixelSize / 2 text: root.text - wrapMode: Original.Text.WordWrap + wrapMode: Original.Text.WrapAnywhere } Original.Image { @@ -58,7 +58,7 @@ Hifi.Tooltip { anchors.margins: 5 font.pixelSize: hifi.fonts.pixelSize / 2 text: root.text - wrapMode: Original.Text.WordWrap + wrapMode: Original.Text.WrapAnywhere } } From 6b14a64c8c6653ab44a01a921a414f7e1e957a2e Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Thu, 25 Jun 2015 15:15:44 -0700 Subject: [PATCH 06/11] Formatting changes and teleport on click --- interface/resources/qml/Tooltip.qml | 10 ++++------ libraries/entities-renderer/src/EntityTreeRenderer.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/interface/resources/qml/Tooltip.qml b/interface/resources/qml/Tooltip.qml index d8ba62840a..43d4628063 100644 --- a/interface/resources/qml/Tooltip.qml +++ b/interface/resources/qml/Tooltip.qml @@ -33,10 +33,10 @@ Hifi.Tooltip { Text { id: textPlace color: "#ffffff" - width: border.implicitWidth + implicitWidth: 322 //anchors.fill: parent anchors.margins: 5 - font.pixelSize: hifi.fonts.pixelSize / 2 + font.pixelSize: hifi.fonts.pixelSize * 1.5 text: root.text wrapMode: Original.Text.WrapAnywhere } @@ -46,17 +46,15 @@ Hifi.Tooltip { source: "../images/NoPictureProvided.svg" //anchors.fill: parent anchors.margins: 5 - verticalAlignment: Original.Image.AlignVCenter - //horizontalAlignment: Image.AlignHCenter } Text { id: textDescription color: "#ffffff" - width: border.implicitWidth + implicitWidth: 322 //anchors.fill: parent anchors.margins: 5 - font.pixelSize: hifi.fonts.pixelSize / 2 + font.pixelSize: hifi.fonts.pixelSize text: root.text wrapMode: Original.Text.WrapAnywhere } diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index fe580eb137..0ea6080165 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -43,6 +43,7 @@ #include "RenderableLineEntityItem.h" #include "RenderablePolyVoxEntityItem.h" #include "EntitiesRendererLogging.h" +#include "AddressManager.h" EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterface* viewState, AbstractScriptingServicesInterface* scriptingServices) : @@ -836,6 +837,14 @@ void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int device RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock, precisionPicking); if (rayPickResult.intersects) { //qCDebug(entitiesrenderer) << "mousePressEvent over entity:" << rayPickResult.entityID; + + QString urlString = rayPickResult.properties.getHref(); + QUrl url = QUrl(urlString, QUrl::StrictMode); + if (url.isValid() && !url.isEmpty()){ + DependencyManager::get()->handleLookupString(urlString); + + } + emit mousePressOnEntity(rayPickResult, event, deviceID); QScriptValueList entityScriptArgs = createMouseEventArgs(rayPickResult.entityID, event, deviceID); From 8ea01b45ae7b78cd5527f34b8cd01b5e14553035 Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Thu, 25 Jun 2015 15:46:43 -0700 Subject: [PATCH 07/11] Word wrap implementation --- interface/resources/qml/Tooltip.qml | 105 +++++++++++++++------------- 1 file changed, 57 insertions(+), 48 deletions(-) diff --git a/interface/resources/qml/Tooltip.qml b/interface/resources/qml/Tooltip.qml index 43d4628063..f212bc11ea 100644 --- a/interface/resources/qml/Tooltip.qml +++ b/interface/resources/qml/Tooltip.qml @@ -1,5 +1,5 @@ import Hifi 1.0 as Hifi -import QtQuick 2.3 as Original +import QtQuick 2.4 import QtQuick.Layouts 1.1 import "controls" import "styles" @@ -7,59 +7,68 @@ import "styles" Hifi.Tooltip { id: root HifiConstants { id: hifi } - x: (lastMousePosition.x > surfaceSize.width/2) ? lastMousePosition.x - root.width : lastMousePosition.x - y: (lastMousePosition.y > surfaceSize.height/2) ? lastMousePosition.y - root.height : lastMousePosition.y - implicitWidth: border.implicitWidth - implicitHeight: border.implicitHeight + x: lastMousePosition.x + offsetX + y: lastMousePosition.y + offsetY + property int offsetX: 0 + property int offsetY: 0 + width: border.width + height: border.height - /* - Border { + Component.onCompleted: { + offsetX = (lastMousePosition.x > surfaceSize.width/2) ? -root.width : 0 + offsetY = (lastMousePosition.y > surfaceSize.height/2) ? -root.height : 0 + } + + Rectangle { id: border - anchors.fill: parent - implicitWidth: tooltipBackground.implicitWidth - //implicitHeight: Math.max(text.implicitHeight, 64) - implicitHeight: tooltipBackground.implicitHeight*/ + color: "#7f000000" + width: 322 + height: col.height + hifi.layout.spacing * 2 - Original.Rectangle { - id: border - color: "#7f000000" - implicitWidth: 322 - implicitHeight: col.height + hifi.layout.spacing * 2 - - ColumnLayout { - id: col - spacing: 5 - - Text { - id: textPlace - color: "#ffffff" - implicitWidth: 322 - //anchors.fill: parent - anchors.margins: 5 - font.pixelSize: hifi.fonts.pixelSize * 1.5 - text: root.text - wrapMode: Original.Text.WrapAnywhere + Column { + id: col + x: hifi.layout.spacing + y: hifi.layout.spacing + anchors.left: parent.left + anchors.leftMargin: hifi.layout.spacing + anchors.right: parent.right + anchors.rightMargin: hifi.layout.spacing + spacing: 5 + Text { + id: textPlace + color: "white" + anchors.left: parent.left + anchors.right: parent.right + font.pixelSize: hifi.fonts.pixelSize / 2 + text: root.text + wrapMode: Text.WrapAnywhere + + /* Uncomment for debugging to see the extent of the + Rectangle { + anchors.fill: parent + color: "#7fff00ff" } + */ + } - Original.Image { - id: tooltipPic - source: "../images/NoPictureProvided.svg" - //anchors.fill: parent - anchors.margins: 5 - } - - Text { - id: textDescription - color: "#ffffff" - implicitWidth: 322 - //anchors.fill: parent - anchors.margins: 5 - font.pixelSize: hifi.fonts.pixelSize - text: root.text - wrapMode: Original.Text.WrapAnywhere - } + Image { + id: tooltipPic + source: "../images/NoPictureProvided.svg" + anchors.left: parent.left + anchors.right: parent.right + verticalAlignment: Image.AlignVCenter + } + Text { + id: textDescription + color: "white" + width: border.implicitWidth + anchors.left: parent.left + anchors.right: parent.right + font.pixelSize: hifi.fonts.pixelSize / 2 + text: root.text + wrapMode: Text.WrapAnywhere } } - //} + } } \ No newline at end of file From 23f4f7d82465063d9abe1c46054959510fccbb26 Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Thu, 25 Jun 2015 15:56:40 -0700 Subject: [PATCH 08/11] Place name is underlined --- interface/resources/qml/Tooltip.qml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/resources/qml/Tooltip.qml b/interface/resources/qml/Tooltip.qml index f212bc11ea..169e5fe211 100644 --- a/interface/resources/qml/Tooltip.qml +++ b/interface/resources/qml/Tooltip.qml @@ -34,9 +34,11 @@ Hifi.Tooltip { anchors.right: parent.right anchors.rightMargin: hifi.layout.spacing spacing: 5 + Text { id: textPlace color: "white" + font.underline: true anchors.left: parent.left anchors.right: parent.right font.pixelSize: hifi.fonts.pixelSize / 2 From a0d77c061cdb4875f604c314c3b3d9a01db7255f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 26 Jun 2015 07:00:28 -0700 Subject: [PATCH 09/11] lock the entity tree during physics operations that access then entity tree. if the simulation and entity-tree are both going to be locked, be sure to lock the entity tree first (and unlock it last), because this is what the network-reading thread does --- interface/src/Application.cpp | 21 +++++ libraries/physics/src/EntityMotionState.cpp | 92 ++++++++++++++++----- libraries/physics/src/EntityMotionState.h | 4 + 3 files changed, 95 insertions(+), 22 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8a572d2d41..d9c5589631 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2496,24 +2496,45 @@ void Application::update(float deltaTime) { _entitySimulation.lock(); _physicsEngine.deleteObjects(_entitySimulation.getObjectsToDelete()); + _entitySimulation.unlock(); + + _entities.getTree()->lockForWrite(); + _entitySimulation.lock(); _physicsEngine.addObjects(_entitySimulation.getObjectsToAdd()); + _entitySimulation.unlock(); + _entities.getTree()->unlock(); + + _entities.getTree()->lockForWrite(); + _entitySimulation.lock(); _physicsEngine.changeObjects(_entitySimulation.getObjectsToChange()); + _entitySimulation.unlock(); + _entities.getTree()->unlock(); + + _entitySimulation.lock(); _entitySimulation.applyActionChanges(); _entitySimulation.unlock(); + AvatarManager* avatarManager = DependencyManager::get().data(); _physicsEngine.deleteObjects(avatarManager->getObjectsToDelete()); _physicsEngine.addObjects(avatarManager->getObjectsToAdd()); _physicsEngine.changeObjects(avatarManager->getObjectsToChange()); + _entities.getTree()->lockForWrite(); _physicsEngine.stepSimulation(); + _entities.getTree()->unlock(); if (_physicsEngine.hasOutgoingChanges()) { + _entities.getTree()->lockForWrite(); _entitySimulation.lock(); _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID()); _entitySimulation.unlock(); + _entities.getTree()->unlock(); + _entities.getTree()->lockForWrite(); avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges()); + _entities.getTree()->unlock(); + auto collisionEvents = _physicsEngine.getCollisionEvents(); avatarManager->handleCollisionEvents(collisionEvents); diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index eeb9d5ca10..2ca996e2a5 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -19,6 +19,10 @@ #include "PhysicsHelpers.h" #include "PhysicsLogging.h" +#ifdef WANT_DEBUG_ENTITY_TREE_LOCKS +#include "EntityTree.h" +#endif + static const float ACCELERATION_EQUIVALENT_EPSILON_RATIO = 0.1f; static const quint8 STEPS_TO_DECIDE_BALLISTIC = 4; @@ -42,6 +46,7 @@ EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer { _type = MOTIONSTATE_TYPE_ENTITY; assert(_entity != nullptr); + assert(entityTreeIsLocked()); setMass(_entity->computeMass()); } @@ -50,7 +55,35 @@ EntityMotionState::~EntityMotionState() { assert(!_entity); } +#ifdef WANT_DEBUG_ENTITY_TREE_LOCKS +bool EntityMotionState::entityTreeIsLocked() const { + EntityTreeElement* element = _entity ? _entity->getElement() : nullptr; + EntityTree* tree = element ? element->getTree() : nullptr; + if (tree) { + bool readSuccess = tree->tryLockForRead(); + if (readSuccess) { + tree->unlock(); + } + bool writeSuccess = tree->tryLockForWrite(); + if (writeSuccess) { + tree->unlock(); + } + if (readSuccess && writeSuccess) { + return false; // if we can take either kind of lock, there was no tree lock. + } + return true; // either read or write failed, so there is some lock in place. + } else { + return true; + } +} +#else +bool EntityMotionState::entityTreeIsLocked() const { + return true; +} +#endif + void EntityMotionState::updateServerPhysicsVariables() { + assert(entityTreeIsLocked()); _serverPosition = _entity->getPosition(); _serverRotation = _entity->getRotation(); _serverVelocity = _entity->getVelocity(); @@ -60,6 +93,7 @@ void EntityMotionState::updateServerPhysicsVariables() { // virtual void EntityMotionState::handleEasyChanges(uint32_t flags) { + assert(entityTreeIsLocked()); updateServerPhysicsVariables(); ObjectMotionState::handleEasyChanges(flags); if (flags & EntityItem::DIRTY_SIMULATOR_ID) { @@ -101,6 +135,7 @@ MotionType EntityMotionState::computeObjectMotionType() const { if (!_entity) { return MOTION_TYPE_STATIC; } + assert(entityTreeIsLocked()); if (_entity->getCollisionsWillMove()) { return MOTION_TYPE_DYNAMIC; } @@ -108,6 +143,7 @@ MotionType EntityMotionState::computeObjectMotionType() const { } bool EntityMotionState::isMoving() const { + assert(entityTreeIsLocked()); return _entity && _entity->isMoving(); } @@ -120,6 +156,7 @@ void EntityMotionState::getWorldTransform(btTransform& worldTrans) const { if (!_entity) { return; } + assert(entityTreeIsLocked()); if (_motionType == MOTION_TYPE_KINEMATIC) { // This is physical kinematic motion which steps strictly by the subframe count // of the physics simulation. @@ -140,6 +177,7 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { if (!_entity) { return; } + assert(entityTreeIsLocked()); measureBodyAcceleration(); _entity->setPosition(bulletToGLM(worldTrans.getOrigin()) + ObjectMotionState::getWorldOffset()); _entity->setRotation(bulletToGLM(worldTrans.getRotation())); @@ -164,9 +202,12 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { #ifdef WANT_DEBUG quint64 now = usecTimestampNow(); qCDebug(physics) << "EntityMotionState::setWorldTransform()... changed entity:" << _entity->getEntityItemID(); - qCDebug(physics) << " last edited:" << _entity->getLastEdited() << formatUsecTime(now - _entity->getLastEdited()) << "ago"; - qCDebug(physics) << " last simulated:" << _entity->getLastSimulated() << formatUsecTime(now - _entity->getLastSimulated()) << "ago"; - qCDebug(physics) << " last updated:" << _entity->getLastUpdated() << formatUsecTime(now - _entity->getLastUpdated()) << "ago"; + qCDebug(physics) << " last edited:" << _entity->getLastEdited() + << formatUsecTime(now - _entity->getLastEdited()) << "ago"; + qCDebug(physics) << " last simulated:" << _entity->getLastSimulated() + << formatUsecTime(now - _entity->getLastSimulated()) << "ago"; + qCDebug(physics) << " last updated:" << _entity->getLastUpdated() + << formatUsecTime(now - _entity->getLastUpdated()) << "ago"; #endif } @@ -174,16 +215,18 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { btCollisionShape* EntityMotionState::computeNewShape() { if (_entity) { ShapeInfo shapeInfo; + assert(entityTreeIsLocked()); _entity->computeShapeInfo(shapeInfo); return getShapeManager()->getShape(shapeInfo); } return nullptr; } -bool EntityMotionState::isCandidateForOwnership(const QUuid& sessionID) const { +bool EntityMotionState::isCandidateForOwnership(const QUuid& sessionID) const { if (!_body || !_entity) { return false; } + assert(entityTreeIsLocked()); return _candidateForOwnership || sessionID == _entity->getSimulatorID(); } @@ -200,7 +243,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { _sentActive = false; return false; } - + #ifdef WANT_DEBUG glm::vec3 wasPosition = _serverPosition; glm::quat wasRotation = _serverRotation; @@ -213,7 +256,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { const float INACTIVE_UPDATE_PERIOD = 0.5f; if (!_sentActive) { // we resend the inactive update every INACTIVE_UPDATE_PERIOD - // until it is removed from the outgoing updates + // until it is removed from the outgoing updates // (which happens when we don't own the simulation and it isn't touching our simulation) return (dt > INACTIVE_UPDATE_PERIOD); } @@ -231,10 +274,10 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { _serverPosition += dt * _serverVelocity; } - // 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. - // NOTE: math is done in the simulation-frame, which is NOT necessarily the same as the world-frame + // NOTE: math is done in the simulation-frame, which is NOT necessarily the same as the world-frame // due to _worldOffset. // TODO: compensate for _worldOffset offset here @@ -242,7 +285,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { btTransform worldTrans = _body->getWorldTransform(); glm::vec3 position = bulletToGLM(worldTrans.getOrigin()); - + float dx2 = glm::distance2(position, _serverPosition); const float MAX_POSITION_ERROR_SQUARED = 0.000004f; // Sqrt() - corresponds to 2 millimeters @@ -258,13 +301,13 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { return true; } - + if (glm::length2(_serverAngularVelocity) > 0.0f) { // compute rotation error float attenuation = powf(1.0f - _body->getAngularDamping(), dt); _serverAngularVelocity *= attenuation; - - // Bullet caps the effective rotation velocity inside its rotation integration step, therefore + + // 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); @@ -276,7 +319,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { #ifdef WANT_DEBUG if ((fabsf(glm::dot(actualRotation, _serverRotation)) < MIN_ROTATION_DOT)) { qCDebug(physics) << ".... ((fabsf(glm::dot(actualRotation, _serverRotation)) < MIN_ROTATION_DOT)) ...."; - + qCDebug(physics) << "wasAngularVelocity:" << wasAngularVelocity; qCDebug(physics) << "_serverAngularVelocity:" << _serverAngularVelocity; @@ -293,10 +336,11 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { } bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& sessionID) { - // 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. + // 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); assert(_body); + assert(entityTreeIsLocked()); if (!remoteSimulationOutOfSync(simulationStep)) { _candidateForOwnership = false; @@ -326,6 +370,7 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& s void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const QUuid& sessionID, uint32_t step) { assert(_entity); + assert(entityTreeIsLocked()); bool active = _body->isActive(); if (!active) { @@ -435,17 +480,18 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q _lastStep = step; } -uint32_t EntityMotionState::getAndClearIncomingDirtyFlags() { +uint32_t EntityMotionState::getAndClearIncomingDirtyFlags() { + assert(entityTreeIsLocked()); uint32_t dirtyFlags = 0; if (_body && _entity) { - dirtyFlags = _entity->getDirtyFlags(); + dirtyFlags = _entity->getDirtyFlags(); _entity->clearDirtyFlags(); // we add DIRTY_MOTION_TYPE if the body's motion type disagrees with entity velocity settings int bodyFlags = _body->getCollisionFlags(); bool isMoving = _entity->isMoving(); if (((bodyFlags & btCollisionObject::CF_STATIC_OBJECT) && isMoving) || (bodyFlags & btCollisionObject::CF_KINEMATIC_OBJECT && !isMoving)) { - dirtyFlags |= EntityItem::DIRTY_MOTION_TYPE; + dirtyFlags |= EntityItem::DIRTY_MOTION_TYPE; } } return dirtyFlags; @@ -455,6 +501,7 @@ uint32_t EntityMotionState::getAndClearIncomingDirtyFlags() { // virtual QUuid EntityMotionState::getSimulatorID() const { if (_entity) { + assert(entityTreeIsLocked()); return _entity->getSimulatorID(); } return QUuid(); @@ -469,12 +516,12 @@ void EntityMotionState::bump() { void EntityMotionState::resetMeasuredBodyAcceleration() { _lastMeasureStep = ObjectMotionState::getWorldSimulationStep(); if (_body) { - _lastVelocity = bulletToGLM(_body->getLinearVelocity()); + _lastVelocity = bulletToGLM(_body->getLinearVelocity()); } else { _lastVelocity = glm::vec3(0.0f); } _measuredAcceleration = glm::vec3(0.0f); -} +} void EntityMotionState::measureBodyAcceleration() { // try to manually measure the true acceleration of the object @@ -504,7 +551,7 @@ glm::vec3 EntityMotionState::getObjectLinearVelocityChange() const { return _measuredAcceleration * _measuredDeltaTime; } -// virtual +// virtual void EntityMotionState::setMotionType(MotionType motionType) { ObjectMotionState::setMotionType(motionType); resetMeasuredBodyAcceleration(); @@ -514,12 +561,13 @@ void EntityMotionState::setMotionType(MotionType motionType) { // virtual QString EntityMotionState::getName() { if (_entity) { + assert(entityTreeIsLocked()); return _entity->getName(); } return ""; } -// virtual +// virtual int16_t EntityMotionState::computeCollisionGroup() { switch (computeObjectMotionType()){ case MOTION_TYPE_STATIC: diff --git a/libraries/physics/src/EntityMotionState.h b/libraries/physics/src/EntityMotionState.h index 2d732f8ee0..4f777a4575 100644 --- a/libraries/physics/src/EntityMotionState.h +++ b/libraries/physics/src/EntityMotionState.h @@ -83,6 +83,10 @@ public: friend class PhysicalEntitySimulation; protected: + #ifdef WANT_DEBUG_ENTITY_TREE_LOCKS + bool entityTreeIsLocked() const; + #endif + virtual btCollisionShape* computeNewShape(); virtual void clearObjectBackPointer(); virtual void setMotionType(MotionType motionType); From 2682c4720d4bf048a09c4bf9340281fcf432d4a2 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 26 Jun 2015 07:04:10 -0700 Subject: [PATCH 10/11] fix alt-branch of ifdef --- libraries/physics/src/EntityMotionState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 2ca996e2a5..0dad876349 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -77,7 +77,7 @@ bool EntityMotionState::entityTreeIsLocked() const { } } #else -bool EntityMotionState::entityTreeIsLocked() const { +bool entityTreeIsLocked() { return true; } #endif From 015498a6e0281bd2ef9d43161745feb19b6aea46 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 26 Jun 2015 07:20:22 -0700 Subject: [PATCH 11/11] move function up so this builds in non-debug mode --- libraries/physics/src/EntityMotionState.cpp | 55 +++++++++++---------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 0dad876349..5e9591a031 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -27,6 +27,34 @@ static const float ACCELERATION_EQUIVALENT_EPSILON_RATIO = 0.1f; static const quint8 STEPS_TO_DECIDE_BALLISTIC = 4; +#ifdef WANT_DEBUG_ENTITY_TREE_LOCKS +bool EntityMotionState::entityTreeIsLocked() const { + EntityTreeElement* element = _entity ? _entity->getElement() : nullptr; + EntityTree* tree = element ? element->getTree() : nullptr; + if (tree) { + bool readSuccess = tree->tryLockForRead(); + if (readSuccess) { + tree->unlock(); + } + bool writeSuccess = tree->tryLockForWrite(); + if (writeSuccess) { + tree->unlock(); + } + if (readSuccess && writeSuccess) { + return false; // if we can take either kind of lock, there was no tree lock. + } + return true; // either read or write failed, so there is some lock in place. + } else { + return true; + } +} +#else +bool entityTreeIsLocked() { + return true; +} +#endif + + EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer entity) : ObjectMotionState(shape), _entity(entity), @@ -55,33 +83,6 @@ EntityMotionState::~EntityMotionState() { assert(!_entity); } -#ifdef WANT_DEBUG_ENTITY_TREE_LOCKS -bool EntityMotionState::entityTreeIsLocked() const { - EntityTreeElement* element = _entity ? _entity->getElement() : nullptr; - EntityTree* tree = element ? element->getTree() : nullptr; - if (tree) { - bool readSuccess = tree->tryLockForRead(); - if (readSuccess) { - tree->unlock(); - } - bool writeSuccess = tree->tryLockForWrite(); - if (writeSuccess) { - tree->unlock(); - } - if (readSuccess && writeSuccess) { - return false; // if we can take either kind of lock, there was no tree lock. - } - return true; // either read or write failed, so there is some lock in place. - } else { - return true; - } -} -#else -bool entityTreeIsLocked() { - return true; -} -#endif - void EntityMotionState::updateServerPhysicsVariables() { assert(entityTreeIsLocked()); _serverPosition = _entity->getPosition();