History

adjust logic related to claiming and releasing simulation ownership during scripted changes to entities

Seth Alves committed 11 years ago

Commit 32ced311 parent 3da2d161 file · +11 −6Browse files

Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 1 file). Show all

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+11−6
@@ -61,13 +61,18 @@ void EntityScriptingInterface::setEntityTree(EntityTree* modelTree) { · 60 unmodified lines
6161
6262
6363
64−void setSimId(EntityItemProperties& propertiesWithSimID) {
64+void setSimId(EntityItemProperties& propertiesWithSimID, EntityItem* entity) {
65+ auto nodeList = DependencyManager::get<NodeList>();
66+ const QUuid myNodeID = nodeList->getSessionUUID();
67+
6568 if (propertiesWithSimID.velocityChanged() ||
6669 propertiesWithSimID.rotationChanged() ||
6770 propertiesWithSimID.containsPositionChange()) {
68− auto nodeList = DependencyManager::get<NodeList>();
69− const QUuid myNodeID = nodeList->getSessionUUID();
7071 propertiesWithSimID.setSimulatorID(myNodeID);
72+ entity->setSimulatorID(myNodeID);
73+ } else if (entity->getSimulatorID() == myNodeID) {
74+ propertiesWithSimID.setSimulatorID(QUuid()); // give up simulation ownership
75+ entity->setSimulatorID(QUuid());
7176 }
7277 }
7378
@@ -80,14 +85,14 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro · 6 unmodified lines
8085
8186 // This Node is creating a new object. If it's in motion, set this Node as the simulator.
8287 EntityItemProperties propertiesWithSimID = properties;
83− setSimId(propertiesWithSimID);
8488
8589 EntityItemID id(NEW_ENTITY, creatorTokenID, false );
8690
8791 // If we have a local entity tree set, then also update it.
8892 if (_entityTree) {
8993 _entityTree->lockForWrite();
90− _entityTree->addEntity(id, propertiesWithSimID);
94+ EntityItem* entity = _entityTree->addEntity(id, propertiesWithSimID);
95+ setSimId(propertiesWithSimID, entity);
9196 _entityTree->unlock();
9297 }
9398
@@ -157,7 +162,6 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E · 63 unmodified lines
157162
158163 // if this Node is changing a physics-related property, claim simulation ownership.
159164 EntityItemProperties propertiesWithSimID = properties;
160− setSimId(propertiesWithSimID);
161165
162166 // If we have a local entity tree set, then also update it. We can do this even if we don't know
163167 // the actual id, because we can edit out local entities just with creatorTokenID
@@ -174,6 +178,7 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E · 10 unmodified lines
174178 EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID);
175179 if (entity) {
176180 propertiesWithSimID.setType(entity->getType());
181+ setSimId(propertiesWithSimID, entity);
177182 }
178183 }
179184