History

Merge 'master' into 'workload'

Andrew Meadows committed 8 years ago

Commit d50da2b2 parents dae857e 3e665fb295 files · +6222 −12556Browse files

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

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+42−13
@@ -258,27 +258,40 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 257 unmodified lines
258258 propertiesWithSimID = convertPropertiesFromScriptSemantics(propertiesWithSimID, scalesWithParent);
259259 propertiesWithSimID.setDimensionsInitialized(properties.dimensionsChanged());
260260
261− EntityItemID id = EntityItemID(QUuid::createUuid());
262−
261+ EntityItemID id;
263262 // 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) {
264275 bool success = true;
276+ id = EntityItemID(QUuid::createUuid());
277+
265278 if (_entityTree) {
266279 _entityTree->withWriteLock([&] {
267− EntityItemPointer entity = _entityTree->addEntity(id, propertiesWithSimID);
280+ EntityItemPointer entity = _entityTree->addEntity(id, properties, isClone);
268281 if (entity) {
269− if (propertiesWithSimID.queryAACubeRelatedPropertyChanged()) {
282+ if (properties.queryAACubeRelatedPropertyChanged()) {
270283 // due to parenting, the server may not know where something is in world-space, so include the bounding cube.
271284 bool success;
272285 AACube queryAACube = entity->getQueryAACube(success);
273286 if (success) {
274− propertiesWithSimID.setQueryAACube(queryAACube);
287+ properties.setQueryAACube(queryAACube);
275288 }
276289 }
277290
278291 entity->setLastBroadcast(usecTimestampNow());
279292 // since we're creating this object we will immediately volunteer to own its simulation
280293 entity->setScriptSimulationPriority(VOLUNTEER_SIMULATION_PRIORITY);
281− propertiesWithSimID.setLastEdited(entity->getLastEdited());
294+ properties.setLastEdited(entity->getLastEdited());
282295 } else {
283296 qCDebug(entities) << "script failed to add new Entity to local Octree";
284297 success = false;
@@ -286,13 +299,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 1 unmodified line
286299 });
287300 }
288301
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;
296303 }
297304
298305 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
320327 return addEntity(properties);
321328 }
322329
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+
323352 EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity) {
324353 EntityPropertyFlags noSpecificProperties;
325354 return getEntityProperties(identity, noSpecificProperties);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t