Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 12 files). Show all
Unified · Split
| @@ -27,9 +27,9 @@ void EntityScriptingInterface::queueEntityMessage(PacketType packetType, · 26 unmodified lines | ||
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
| 30 | −bool EntityScriptingInterface::canEdit() { | |
| 30 | +bool EntityScriptingInterface::canAdjustLocks() { | |
| 31 | 31 | auto nodeList = DependencyManager::get<NodeList>(); |
| 32 | − return nodeList->getThisNodeCanEdit(); | |
| 32 | + return nodeList->getThisNodeCanAdjustLocks(); | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
| @@ -40,18 +40,16 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro · 4 unmodified lines | ||
| 40 | 40 | |
| 41 | 41 | EntityItemID id(NEW_ENTITY, creatorTokenID, false ); |
| 42 | 42 | |
| 43 | − if (canEdit()) { | |
| 44 | − // If we have a local entity tree set, then also update it. | |
| 45 | − if (_entityTree) { | |
| 46 | − _entityTree->lockForWrite(); | |
| 47 | − _entityTree->addEntity(id, properties); | |
| 48 | − _entityTree->unlock(); | |
| 49 | − } | |
| 50 | − | |
| 51 | − // queue the packet | |
| 52 | − queueEntityMessage(PacketTypeEntityAddOrEdit, id, properties); | |
| 43 | + // If we have a local entity tree set, then also update it. | |
| 44 | + if (_entityTree) { | |
| 45 | + _entityTree->lockForWrite(); | |
| 46 | + _entityTree->addEntity(id, properties); | |
| 47 | + _entityTree->unlock(); | |
| 53 | 48 | } |
| 54 | 49 | |
| 50 | + // queue the packet | |
| 51 | + queueEntityMessage(PacketTypeEntityAddOrEdit, id, properties); | |
| 52 | + | |
| 55 | 53 | return id; |
| 56 | 54 | } |
| 57 | 55 | |
| @@ -74,32 +72,30 @@ EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) { · 16 unmodified lines | ||
| 74 | 72 | EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID entityID) { |
| 75 | 73 | EntityItemProperties results; |
| 76 | 74 | |
| 77 | − if (canEdit()) { | |
| 78 | − EntityItemID identity = identifyEntity(entityID); | |
| 79 | − if (_entityTree) { | |
| 80 | − _entityTree->lockForRead(); | |
| 81 | − EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(identity)); | |
| 75 | + EntityItemID identity = identifyEntity(entityID); | |
| 76 | + if (_entityTree) { | |
| 77 | + _entityTree->lockForRead(); | |
| 78 | + EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(identity)); | |
| 82 | 79 | |
| 83 | − if (entity) { | |
| 84 | − results = entity->getProperties(); | |
| 85 | − | |
| 86 | − // TODO: improve sitting points and naturalDimensions in the future, | |
| 87 | − // for now we've included the old sitting points model behavior for entity types that are models | |
| 88 | − // we've also added this hack for setting natural dimensions of models | |
| 89 | − if (entity->getType() == EntityTypes::Model) { | |
| 90 | − const FBXGeometry* geometry = _entityTree->getGeometryForEntity(entity); | |
| 91 | − if (geometry) { | |
| 92 | − results.setSittingPoints(geometry->sittingPoints); | |
| 93 | − Extents meshExtents = geometry->getUnscaledMeshExtents(); | |
| 94 | − results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum); | |
| 95 | − } | |
| 80 | + if (entity) { | |
| 81 | + results = entity->getProperties(); | |
| 82 | + | |
| 83 | + // TODO: improve sitting points and naturalDimensions in the future, | |
| 84 | + // for now we've included the old sitting points model behavior for entity types that are models | |
| 85 | + // we've also added this hack for setting natural dimensions of models | |
| 86 | + if (entity->getType() == EntityTypes::Model) { | |
| 87 | + const FBXGeometry* geometry = _entityTree->getGeometryForEntity(entity); | |
| 88 | + if (geometry) { | |
| 89 | + results.setSittingPoints(geometry->sittingPoints); | |
| 90 | + Extents meshExtents = geometry->getUnscaledMeshExtents(); | |
| 91 | + results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum); | |
| 96 | 92 | } |
| 97 | − | |
| 98 | − } else { | |
| 99 | − results.setIsUnknownID(); | |
| 100 | 93 | } |
| 101 | − _entityTree->unlock(); | |
| 94 | + | |
| 95 | + } else { | |
| 96 | + results.setIsUnknownID(); | |
| 102 | 97 | } |
| 98 | + _entityTree->unlock(); | |
| 103 | 99 | } |
| 104 | 100 | |
| 105 | 101 | return results; |
| @@ -107,10 +103,6 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID · 1 unmodified line | ||
| 107 | 103 | |
| 108 | 104 | EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) { |
| 109 | 105 | |
| 110 | − if (!canEdit()) { | |
| 111 | − return entityID; | |
| 112 | − } | |
| 113 | − | |
| 114 | 106 | EntityItemID actualID = entityID; |
| 115 | 107 | // if the entity is unknown, attempt to look it up |
| 116 | 108 | if (!entityID.isKnownID) { |
| @@ -125,7 +117,7 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E · 8 unmodified lines | ||
| 125 | 117 | // the actual id, because we can edit out local entities just with creatorTokenID |
| 126 | 118 | if (_entityTree) { |
| 127 | 119 | _entityTree->lockForWrite(); |
| 128 | − _entityTree->updateEntity(entityID, properties); | |
| 120 | + _entityTree->updateEntity(entityID, properties, canAdjustLocks()); | |
| 129 | 121 | _entityTree->unlock(); |
| 130 | 122 | } |
| 131 | 123 | |
| @@ -151,10 +143,6 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E · 19 unmodified lines | ||
| 151 | 143 | |
| 152 | 144 | void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { |
| 153 | 145 | |
| 154 | − if (!canEdit()) { | |
| 155 | − return; | |
| 156 | − } | |
| 157 | − | |
| 158 | 146 | EntityItemID actualID = entityID; |
| 159 | 147 | |
| 160 | 148 | // if the entity is unknown, attempt to look it up |