From 8f38ea8c6a80de8f6c901aca656af1b699ec6458 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 20 May 2017 11:54:42 -0700 Subject: [PATCH 1/2] force locked entities to be static in bullet --- libraries/entities/src/EntityItem.cpp | 5 +++++ libraries/physics/src/EntityMotionState.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 14122594fe..80f992d865 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -2767,6 +2767,11 @@ void EntityItem::setLocked(bool value) { withWriteLock([&] { _locked = value; }); + markDirtyFlags(Simulation::DIRTY_MOTION_TYPE); + EntityTreePointer tree = getTree(); + if (tree) { + tree->entityChanged(getThisPointer()); + } } QString EntityItem::getUserData() const { diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 0c804fb5b7..452495cf18 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -185,6 +185,10 @@ PhysicsMotionType EntityMotionState::computePhysicsMotionType() const { return MOTION_TYPE_STATIC; } + if (_entity->getLocked()) { + return MOTION_TYPE_STATIC; + } + if (_entity->getDynamic()) { if (!_entity->getParentID().isNull()) { // if something would have been dynamic but is a child of something else, force it to be kinematic, instead. From 2512b3984841e82b89893541674c8f329500710a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 20 May 2017 14:14:33 -0700 Subject: [PATCH 2/2] don't dirty motion-type if lock value isn't actually changing --- libraries/entities/src/EntityItem.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 80f992d865..2cfb71df0c 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -2764,13 +2764,19 @@ bool EntityItem::getLocked() const { } void EntityItem::setLocked(bool value) { + bool changed { false }; withWriteLock([&] { - _locked = value; + if (_locked != value) { + _locked = value; + changed = true; + } }); - markDirtyFlags(Simulation::DIRTY_MOTION_TYPE); - EntityTreePointer tree = getTree(); - if (tree) { - tree->entityChanged(getThisPointer()); + if (changed) { + markDirtyFlags(Simulation::DIRTY_MOTION_TYPE); + EntityTreePointer tree = getTree(); + if (tree) { + tree->entityChanged(getThisPointer()); + } } }