Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 1 file). Show all
Unified · Split
| @@ -61,13 +61,18 @@ void EntityScriptingInterface::setEntityTree(EntityTree* modelTree) { · 60 unmodified lines | ||
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | |
| 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 | + | |
| 65 | 68 | if (propertiesWithSimID.velocityChanged() || |
| 66 | 69 | propertiesWithSimID.rotationChanged() || |
| 67 | 70 | propertiesWithSimID.containsPositionChange()) { |
| 68 | − auto nodeList = DependencyManager::get<NodeList>(); | |
| 69 | − const QUuid myNodeID = nodeList->getSessionUUID(); | |
| 70 | 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 | 86 | // This Node is creating a new object. If it's in motion, set this Node as the simulator. |
| 82 | 87 | EntityItemProperties propertiesWithSimID = properties; |
| 83 | − setSimId(propertiesWithSimID); | |
| 84 | 88 | |
| 85 | 89 | EntityItemID id(NEW_ENTITY, creatorTokenID, false ); |
| 86 | 90 | |
| 87 | 91 | // If we have a local entity tree set, then also update it. |
| 88 | 92 | if (_entityTree) { |
| 89 | 93 | _entityTree->lockForWrite(); |
| 90 | − _entityTree->addEntity(id, propertiesWithSimID); | |
| 94 | + EntityItem* entity = _entityTree->addEntity(id, propertiesWithSimID); | |
| 95 | + setSimId(propertiesWithSimID, entity); | |
| 91 | 96 | _entityTree->unlock(); |
| 92 | 97 | } |
| 93 | 98 | |
| @@ -157,7 +162,6 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E · 63 unmodified lines | ||
| 157 | 162 | |
| 158 | 163 | // if this Node is changing a physics-related property, claim simulation ownership. |
| 159 | 164 | EntityItemProperties propertiesWithSimID = properties; |
| 160 | − setSimId(propertiesWithSimID); | |
| 161 | 165 | |
| 162 | 166 | // If we have a local entity tree set, then also update it. We can do this even if we don't know |
| 163 | 167 | // 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 | 178 | EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID); |
| 175 | 179 | if (entity) { |
| 176 | 180 | propertiesWithSimID.setType(entity->getType()); |
| 181 | + setSimId(propertiesWithSimID, entity); | |
| 177 | 182 | } |
| 178 | 183 | } |
| 179 | 184 | |