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
61 61
62 62
63 63
64void setSimId(EntityItemProperties& propertiesWithSimID) {64void setSimId(EntityItemProperties& propertiesWithSimID, EntityItem* entity) {
65 auto nodeList = DependencyManager::get<NodeList>();
66 const QUuid myNodeID = nodeList->getSessionUUID();
67
65 if (propertiesWithSimID.velocityChanged() ||68 if (propertiesWithSimID.velocityChanged() ||
66 propertiesWithSimID.rotationChanged() ||69 propertiesWithSimID.rotationChanged() ||
67 propertiesWithSimID.containsPositionChange()) {70 propertiesWithSimID.containsPositionChange()) {
68 auto nodeList = DependencyManager::get<NodeList>();
69 const QUuid myNodeID = nodeList->getSessionUUID();
70 propertiesWithSimID.setSimulatorID(myNodeID);71 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());
71 }76 }
72}77}
73 78
@@ -80,14 +85,14 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro · 6 unmodified lines
80 85
81 // This Node is creating a new object. If it's in motion, set this Node as the simulator.86 // This Node is creating a new object. If it's in motion, set this Node as the simulator.
82 EntityItemProperties propertiesWithSimID = properties;87 EntityItemProperties propertiesWithSimID = properties;
83 setSimId(propertiesWithSimID);
84 88
85 EntityItemID id(NEW_ENTITY, creatorTokenID, false );89 EntityItemID id(NEW_ENTITY, creatorTokenID, false );
86 90
87 // If we have a local entity tree set, then also update it.91 // If we have a local entity tree set, then also update it.
88 if (_entityTree) {92 if (_entityTree) {
89 _entityTree->lockForWrite();93 _entityTree->lockForWrite();
90 _entityTree->addEntity(id, propertiesWithSimID);94 EntityItem* entity = _entityTree->addEntity(id, propertiesWithSimID);
95 setSimId(propertiesWithSimID, entity);
91 _entityTree->unlock();96 _entityTree->unlock();
92 }97 }
93 98
@@ -157,7 +162,6 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E · 63 unmodified lines
157 162
158 // if this Node is changing a physics-related property, claim simulation ownership.163 // if this Node is changing a physics-related property, claim simulation ownership.
159 EntityItemProperties propertiesWithSimID = properties;164 EntityItemProperties propertiesWithSimID = properties;
160 setSimId(propertiesWithSimID);
161 165
162 // If we have a local entity tree set, then also update it. We can do this even if we don't know166 // If we have a local entity tree set, then also update it. We can do this even if we don't know
163 // the actual id, because we can edit out local entities just with creatorTokenID167 // 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
174 EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID);178 EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID);
175 if (entity) {179 if (entity) {
176 propertiesWithSimID.setType(entity->getType());180 propertiesWithSimID.setType(entity->getType());
181 setSimId(propertiesWithSimID, entity);
177 }182 }
178 }183 }
179 184