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