Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 295 files). Show all
Unified · Split
| @@ -258,27 +258,40 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 257 unmodified lines | ||
| 258 | 258 | propertiesWithSimID = convertPropertiesFromScriptSemantics(propertiesWithSimID, scalesWithParent); |
| 259 | 259 | propertiesWithSimID.setDimensionsInitialized(properties.dimensionsChanged()); |
| 260 | 260 | |
| 261 | − EntityItemID id = EntityItemID(QUuid::createUuid()); | |
| 262 | − | |
| 261 | + EntityItemID id; | |
| 263 | 262 | // If we have a local entity tree set, then also update it. |
| 263 | + bool success = addLocalEntityCopy(propertiesWithSimID, id); | |
| 264 | + | |
| 265 | + // queue the packet | |
| 266 | + if (success) { | |
| 267 | + queueEntityMessage(PacketType::EntityAdd, id, propertiesWithSimID); | |
| 268 | + return id; | |
| 269 | + } else { | |
| 270 | + return QUuid(); | |
| 271 | + } | |
| 272 | +} | |
| 273 | + | |
| 274 | +bool EntityScriptingInterface::addLocalEntityCopy(EntityItemProperties& properties, EntityItemID& id, bool isClone) { | |
| 264 | 275 | bool success = true; |
| 276 | + id = EntityItemID(QUuid::createUuid()); | |
| 277 | + | |
| 265 | 278 | if (_entityTree) { |
| 266 | 279 | _entityTree->withWriteLock([&] { |
| 267 | − EntityItemPointer entity = _entityTree->addEntity(id, propertiesWithSimID); | |
| 280 | + EntityItemPointer entity = _entityTree->addEntity(id, properties, isClone); | |
| 268 | 281 | if (entity) { |
| 269 | − if (propertiesWithSimID.queryAACubeRelatedPropertyChanged()) { | |
| 282 | + if (properties.queryAACubeRelatedPropertyChanged()) { | |
| 270 | 283 | // due to parenting, the server may not know where something is in world-space, so include the bounding cube. |
| 271 | 284 | bool success; |
| 272 | 285 | AACube queryAACube = entity->getQueryAACube(success); |
| 273 | 286 | if (success) { |
| 274 | − propertiesWithSimID.setQueryAACube(queryAACube); | |
| 287 | + properties.setQueryAACube(queryAACube); | |
| 275 | 288 | } |
| 276 | 289 | } |
| 277 | 290 | |
| 278 | 291 | entity->setLastBroadcast(usecTimestampNow()); |
| 279 | 292 | // since we're creating this object we will immediately volunteer to own its simulation |
| 280 | 293 | entity->setScriptSimulationPriority(VOLUNTEER_SIMULATION_PRIORITY); |
| 281 | − propertiesWithSimID.setLastEdited(entity->getLastEdited()); | |
| 294 | + properties.setLastEdited(entity->getLastEdited()); | |
| 282 | 295 | } else { |
| 283 | 296 | qCDebug(entities) << "script failed to add new Entity to local Octree"; |
| 284 | 297 | success = false; |
| @@ -286,13 +299,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 1 unmodified line | ||
| 286 | 299 | }); |
| 287 | 300 | } |
| 288 | 301 | |
| 289 | − // queue the packet | |
| 290 | − if (success) { | |
| 291 | − queueEntityMessage(PacketType::EntityAdd, id, propertiesWithSimID); | |
| 292 | − return id; | |
| 293 | − } else { | |
| 294 | − return QUuid(); | |
| 295 | − } | |
| 302 | + return success; | |
| 296 | 303 | } |
| 297 | 304 | |
| 298 | 305 | QUuid EntityScriptingInterface::addModelEntity(const QString& name, const QString& modelUrl, const QString& textures, |
| @@ -320,6 +327,28 @@ QUuid EntityScriptingInterface::addModelEntity(const QString& name, const QStrin · 21 unmodified lines | ||
| 320 | 327 | return addEntity(properties); |
| 321 | 328 | } |
| 322 | 329 | |
| 330 | +QUuid EntityScriptingInterface::cloneEntity(QUuid entityIDToClone) { | |
| 331 | + EntityItemID newEntityID; | |
| 332 | + EntityItemProperties properties = getEntityProperties(entityIDToClone); | |
| 333 | + bool cloneAvatarEntity = properties.getCloneAvatarEntity(); | |
| 334 | + properties.convertToCloneProperties(entityIDToClone); | |
| 335 | + | |
| 336 | + if (cloneAvatarEntity) { | |
| 337 | + return addEntity(properties, true); | |
| 338 | + } else { | |
| 339 | + // setLastEdited timestamp to 0 to ensure this entity gets updated with the properties | |
| 340 | + // from the server-created entity, don't change this unless you know what you are doing | |
| 341 | + properties.setLastEdited(0); | |
| 342 | + bool success = addLocalEntityCopy(properties, newEntityID, true); | |
| 343 | + if (success) { | |
| 344 | + getEntityPacketSender()->queueCloneEntityMessage(entityIDToClone, newEntityID); | |
| 345 | + return newEntityID; | |
| 346 | + } else { | |
| 347 | + return QUuid(); | |
| 348 | + } | |
| 349 | + } | |
| 350 | +} | |
| 351 | + | |
| 323 | 352 | EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity) { |
| 324 | 353 | EntityPropertyFlags noSpecificProperties; |
| 325 | 354 | return getEntityProperties(identity, noSpecificProperties); |