From eff02d3e3ac4bb480ca6beb1283b44cd5d8d2bd2 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Sun, 10 Jan 2016 10:11:47 -0800 Subject: [PATCH 1/3] Fix Agents bidding on simulation ownership --- assignment-client/src/Agent.cpp | 2 +- assignment-client/src/AssignmentClient.cpp | 2 +- interface/src/Application.cpp | 2 +- libraries/entities/src/EntityScriptingInterface.cpp | 7 ++++--- libraries/entities/src/EntityScriptingInterface.h | 5 +++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 07d15c9e26..3ff7eafd6b 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -469,7 +469,7 @@ void Agent::aboutToFinish() { } // our entity tree is going to go away so tell that to the EntityScriptingInterface - DependencyManager::get()->setEntityTree(NULL); + DependencyManager::get()->setEntityTree(nullptr); // cleanup the AssetClient thread QThread* assetThread = DependencyManager::get()->thread(); diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 3bd38c4ae7..85a2c95b4d 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -60,7 +60,7 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri auto nodeList = DependencyManager::set(NodeType::Unassigned, listenPort); auto animationCache = DependencyManager::set(); - auto entityScriptingInterface = DependencyManager::set(); + auto entityScriptingInterface = DependencyManager::set(false); DependencyManager::registerInheritance(); auto actionFactory = DependencyManager::set(); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ab5edec527..f7d2bd9ada 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -348,7 +348,7 @@ bool setupEssentials(int& argc, char** argv) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); - DependencyManager::set(); + DependencyManager::set(true); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 8fd7be912e..6bfcc66f1e 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -25,8 +25,9 @@ #include "ZoneEntityItem.h" -EntityScriptingInterface::EntityScriptingInterface() : - _entityTree(NULL) +EntityScriptingInterface::EntityScriptingInterface(bool bidOnSimulationOwnership) : + _entityTree(NULL), + _bidOnSimulationOwnership(bidOnSimulationOwnership) { auto nodeList = DependencyManager::get(); connect(nodeList.data(), &NodeList::canAdjustLocksChanged, this, &EntityScriptingInterface::canAdjustLocksChanged); @@ -255,7 +256,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& properties.setType(entity->getType()); bool hasTerseUpdateChanges = properties.hasTerseUpdateChanges(); bool hasPhysicsChanges = properties.hasMiscPhysicsChanges() || hasTerseUpdateChanges; - if (hasPhysicsChanges) { + if (_bidOnSimulationOwnership && hasPhysicsChanges) { auto nodeList = DependencyManager::get(); const QUuid myNodeID = nodeList->getSessionUUID(); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 641da7518e..934a194360 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -58,7 +58,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra class EntityScriptingInterface : public OctreeScriptingInterface, public Dependency { Q_OBJECT public: - EntityScriptingInterface(); + EntityScriptingInterface(bool bidOnSimulationOwnership); EntityEditPacketSender* getEntityPacketSender() const { return (EntityEditPacketSender*)getPacketSender(); } virtual NodeType_t getServerNodeType() const { return NodeType::EntityServer; } @@ -204,7 +204,8 @@ private: bool precisionPicking, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard); EntityTreePointer _entityTree; - EntitiesScriptEngineProvider* _entitiesScriptEngine = nullptr; + EntitiesScriptEngineProvider* _entitiesScriptEngine { nullptr }; + bool _bidOnSimulationOwnership { false }; }; #endif // hifi_EntityScriptingInterface_h From 25632b63b70a4b25c55066a1781a972503fbd81e Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 2 Feb 2016 13:00:35 -0800 Subject: [PATCH 2/3] Adjust Entities.addEntity to not bid on simulation from AC Script --- .../entities/src/EntityScriptingInterface.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 6bfcc66f1e..5d793d7547 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -131,17 +131,20 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties _entityTree->withWriteLock([&] { EntityItemPointer entity = _entityTree->addEntity(id, propertiesWithSimID); if (entity) { - // This Node is creating a new object. If it's in motion, set this Node as the simulator. - auto nodeList = DependencyManager::get(); - const QUuid myNodeID = nodeList->getSessionUUID(); - propertiesWithSimID.setSimulationOwner(myNodeID, SCRIPT_EDIT_SIMULATION_PRIORITY); if (propertiesWithSimID.parentRelatedPropertyChanged()) { // due to parenting, the server may not know where something is in world-space, so include the bounding cube. propertiesWithSimID.setQueryAACube(entity->getQueryAACube()); } - // and make note of it now, so we can act on it right away. - entity->setSimulationOwner(myNodeID, SCRIPT_EDIT_SIMULATION_PRIORITY); + if (_bidOnSimulationOwnership) { + // This Node is creating a new object. If it's in motion, set this Node as the simulator. + auto nodeList = DependencyManager::get(); + const QUuid myNodeID = nodeList->getSessionUUID(); + + // and make note of it now, so we can act on it right away. + propertiesWithSimID.setSimulationOwner(myNodeID, SCRIPT_EDIT_SIMULATION_PRIORITY); + entity->setSimulationOwner(myNodeID, SCRIPT_EDIT_SIMULATION_PRIORITY); + } entity->setLastBroadcast(usecTimestampNow()); } else { From 963c71a47698536a979479990f0e712ddfea401b Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 3 Feb 2016 09:28:49 -0800 Subject: [PATCH 3/3] Fix ES rejecting unowned entity physics updates --- libraries/entities/src/EntityTree.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 34dd809510..1405121d2e 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -194,7 +194,7 @@ bool EntityTree::updateEntityWithElement(EntityItemPointer entity, const EntityI // the entire update is suspect --> ignore it return false; } - } else { + } else if (simulationBlocked) { simulationBlocked = senderID != entity->getSimulatorID(); } if (simulationBlocked) {