diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 803955f02c..5e059fa2cb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2461,8 +2461,9 @@ void Application::update(float deltaTime) { updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process... - - DependencyManager::get()->updateOtherAvatars(deltaTime); //loop through all the other avatars and simulate them... + + //loop through all the other avatars and simulate them... + DependencyManager::get()->updateOtherAvatars(deltaTime); updateCamera(deltaTime); // handle various camera tweaks like off axis projection updateDialogs(deltaTime); // update various stats dialogs if present @@ -2476,6 +2477,7 @@ void Application::update(float deltaTime) { _physicsEngine.deleteObjects(_entitySimulation.getObjectsToDelete()); _physicsEngine.addObjects(_entitySimulation.getObjectsToAdd()); _physicsEngine.changeObjects(_entitySimulation.getObjectsToChange()); + _entitySimulation.applyActionChanges(); _entitySimulation.unlock(); AvatarManager* avatarManager = DependencyManager::get().data(); @@ -2498,7 +2500,8 @@ void Application::update(float deltaTime) { if (!_aboutToQuit) { PerformanceTimer perfTimer("entities"); - // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk deadlock.) + // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk + // deadlock.) _entitySimulation.handleCollisionEvents(collisionEvents); // NOTE: the _entities.update() call below will wait for lock // and will simulate entity motion (the EntityTree has been given an EntitySimulation). @@ -2511,11 +2514,12 @@ void Application::update(float deltaTime) { PerformanceTimer perfTimer("overlays"); _overlays.update(deltaTime); } - + { PerformanceTimer perfTimer("myAvatar"); updateMyAvatarLookAtPosition(); - DependencyManager::get()->updateMyAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes + // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes + DependencyManager::get()->updateMyAvatar(deltaTime); } { diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index cbf8d57723..7887b286f0 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1369,8 +1369,6 @@ void EntityItem::removeAction(const QUuid actionID) { simulation->removeAction(action->getID()); } } - - delete action; } } diff --git a/libraries/entities/src/EntitySimulation.h b/libraries/entities/src/EntitySimulation.h index fc0c6aa7e4..baf1736d2e 100644 --- a/libraries/entities/src/EntitySimulation.h +++ b/libraries/entities/src/EntitySimulation.h @@ -59,6 +59,7 @@ public: virtual void addAction(EntityActionInterface* action) {} virtual void removeAction(const QUuid actionID) {} virtual void removeActions(QList actionIDsToRemove) {} + virtual void applyActionChanges() {} protected: // these only called by the EntityTree? /// \param entity pointer to EntityItem to be added @@ -116,7 +117,7 @@ protected: SetOfEntities _entitiesToDelete; // entities simulation decided needed to be deleted (EntityTree will actually delete) SetOfEntities _simpleKinematicEntities; // entities undergoing non-colliding kinematic motion -private: + private: void moveSimpleKinematics(); }; diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index e5fe5d44a3..8cc9345e67 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -233,19 +233,33 @@ void PhysicalEntitySimulation::handleCollisionEvents(CollisionEvents& collisionE } void PhysicalEntitySimulation::addAction(EntityActionInterface* action) { - if (_physicsEngine) { - _physicsEngine->addAction(action); - } + // if (_physicsEngine) { + // _physicsEngine->addAction(action); + // } + _actionsToAdd += action; } void PhysicalEntitySimulation::removeAction(const QUuid actionID) { - if (_physicsEngine) { - _physicsEngine->removeAction(actionID); - } + // if (_physicsEngine) { + // _physicsEngine->removeAction(actionID); + // } + _actionsToRemove += actionID; } void PhysicalEntitySimulation::removeActions(QList actionIDsToRemove) { + // if (_physicsEngine) { + // _physicsEngine->removeActions(actionIDsToRemove); + // } + _actionsToRemove += actionIDsToRemove; +} + +void PhysicalEntitySimulation::applyActionChanges() { if (_physicsEngine) { - _physicsEngine->removeActions(actionIDsToRemove); + foreach (EntityActionInterface* actionToAdd, _actionsToAdd) { + _physicsEngine->addAction(actionToAdd); + } + foreach (QUuid actionToRemove, _actionsToRemove) { + _physicsEngine->removeAction(actionToRemove); + } } } diff --git a/libraries/physics/src/PhysicalEntitySimulation.h b/libraries/physics/src/PhysicalEntitySimulation.h index 0c907f078c..e57cd4326b 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.h +++ b/libraries/physics/src/PhysicalEntitySimulation.h @@ -35,6 +35,7 @@ public: virtual void addAction(EntityActionInterface* action); virtual void removeAction(const QUuid actionID); virtual void removeActions(QList actionIDsToRemove); + virtual void applyActionChanges(); protected: // only called by EntitySimulation // overrides for EntitySimulation @@ -68,6 +69,9 @@ private: EntityEditPacketSender* _entityPacketSender = nullptr; uint32_t _lastStepSendPackets = 0; + + QList _actionsToAdd; + QList _actionsToRemove; }; #endif // hifi_PhysicalEntitySimulation_h diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 9f843a052c..c572121d60 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -466,11 +466,6 @@ void PhysicsEngine::removeAction(const QUuid actionID) { ObjectAction* action = _objectActions[actionID]; _dynamicsWorld->removeAction(action); _objectActions.remove(actionID); - } -} - -void PhysicsEngine::removeActions(QList actionIDsToRemove) { - foreach(QUuid actionID, actionIDsToRemove) { - removeAction(actionID); + delete action; } } diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index 085b51d224..e009cac60f 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -97,7 +97,6 @@ public: void addAction(EntityActionInterface* action); void removeAction(const QUuid actionID); - void removeActions(QList actionIDsToRemove); private: void removeContacts(ObjectMotionState* motionState);