Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 104 files). Show all
Unified · Split
| @@ -20,7 +20,6 @@ · 19 unmodified lines | ||
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | EntityScriptingInterface::EntityScriptingInterface() : |
| 23 | − _nextCreatorTokenID(0), | |
| 24 | 23 | _entityTree(NULL) |
| 25 | 24 | { |
| 26 | 25 | auto nodeList = DependencyManager::get<NodeList>(); |
| @@ -29,7 +28,7 @@ EntityScriptingInterface::EntityScriptingInterface() : · 2 unmodified lines | ||
| 29 | 28 | } |
| 30 | 29 | |
| 31 | 30 | void EntityScriptingInterface::queueEntityMessage(PacketType packetType, |
| 32 | − EntityItemID entityID, const EntityItemProperties& properties) { | |
| 31 | + QUuid entityID, const EntityItemProperties& properties) { | |
| 33 | 32 | getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); |
| 34 | 33 | } |
| 35 | 34 | |
| @@ -71,14 +70,10 @@ void bidForSimulationOwnership(EntityItemProperties& properties) { · 35 unmodified lines | ||
| 71 | 70 | |
| 72 | 71 | |
| 73 | 72 | |
| 74 | −EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& properties) { | |
| 75 | − | |
| 76 | − // The application will keep track of creatorTokenID | |
| 77 | − uint32_t creatorTokenID = EntityItemID::getNextCreatorTokenID(); | |
| 73 | +QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties) { | |
| 78 | 74 | |
| 79 | 75 | EntityItemProperties propertiesWithSimID = properties; |
| 80 | − | |
| 81 | − EntityItemID id(NEW_ENTITY, creatorTokenID, false); | |
| 76 | + QUuid id = QUuid::createUuid(); | |
| 82 | 77 | |
| 83 | 78 | // If we have a local entity tree set, then also update it. |
| 84 | 79 | bool success = true; |
| @@ -104,25 +99,8 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro · 19 unmodified lines | ||
| 104 | 99 | return id; |
| 105 | 100 | } |
| 106 | 101 | |
| 107 | −EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) { | |
| 108 | − EntityItemID actualID = entityID; | |
| 109 | − | |
| 110 | − if (!entityID.isKnownID) { | |
| 111 | − actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); | |
| 112 | − if (actualID == UNKNOWN_ENTITY_ID) { | |
| 113 | − return entityID; // bailing early | |
| 114 | − } | |
| 115 | − | |
| 116 | − // found it! | |
| 117 | − entityID.id = actualID.id; | |
| 118 | − entityID.isKnownID = true; | |
| 119 | − } | |
| 120 | − return entityID; | |
| 121 | −} | |
| 122 | − | |
| 123 | −EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID entityID) { | |
| 102 | +EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity) { | |
| 124 | 103 | EntityItemProperties results; |
| 125 | − EntityItemID identity = identifyEntity(entityID); | |
| 126 | 104 | if (_entityTree) { |
| 127 | 105 | _entityTree->lockForRead(); |
| 128 | 106 | EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(identity)); |
| @@ -142,8 +120,6 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID · 13 unmodified lines | ||
| 142 | 120 | } |
| 143 | 121 | } |
| 144 | 122 | |
| 145 | − } else { | |
| 146 | − results.setIsUnknownID(); | |
| 147 | 123 | } |
| 148 | 124 | _entityTree->unlock(); |
| 149 | 125 | } |
| @@ -151,59 +127,33 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID · 1 unmodified line | ||
| 151 | 127 | return results; |
| 152 | 128 | } |
| 153 | 129 | |
| 154 | −EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) { | |
| 155 | − EntityItemID actualID = entityID; | |
| 156 | − // if the entity is unknown, attempt to look it up | |
| 157 | − if (!entityID.isKnownID) { | |
| 158 | − actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); | |
| 159 | − if (actualID.id != UNKNOWN_ENTITY_ID) { | |
| 160 | − entityID.id = actualID.id; | |
| 161 | − entityID.isKnownID = true; | |
| 162 | − } | |
| 163 | − } | |
| 164 | − | |
| 165 | − // If we have a local entity tree set, then also update it. We can do this even if we don't know | |
| 166 | − // the actual id, because we can edit out local entities just with creatorTokenID | |
| 130 | +QUuid EntityScriptingInterface::editEntity(QUuid entityID, const EntityItemProperties& properties) { | |
| 131 | + // If we have a local entity tree set, then also update it. | |
| 167 | 132 | if (_entityTree) { |
| 168 | 133 | _entityTree->lockForWrite(); |
| 169 | 134 | _entityTree->updateEntity(entityID, properties); |
| 170 | 135 | _entityTree->unlock(); |
| 171 | 136 | } |
| 172 | 137 | |
| 173 | − // if at this point, we know the id, send the update to the entity server | |
| 174 | − if (entityID.isKnownID) { | |
| 175 | − // make sure the properties has a type, so that the encode can know which properties to include | |
| 176 | − if (properties.getType() == EntityTypes::Unknown) { | |
| 177 | − EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID); | |
| 178 | − if (entity) { | |
| 179 | − // we need to change the outgoing properties, so we make a copy, modify, and send. | |
| 180 | − EntityItemProperties modifiedProperties = properties; | |
| 181 | − entity->setLastBroadcast(usecTimestampNow()); | |
| 182 | − modifiedProperties.setType(entity->getType()); | |
| 183 | − bidForSimulationOwnership(modifiedProperties); | |
| 184 | − queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, modifiedProperties); | |
| 185 | − return entityID; | |
| 186 | − } | |
| 138 | + // make sure the properties has a type, so that the encode can know which properties to include | |
| 139 | + if (properties.getType() == EntityTypes::Unknown) { | |
| 140 | + EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID); | |
| 141 | + if (entity) { | |
| 142 | + // we need to change the outgoing properties, so we make a copy, modify, and send. | |
| 143 | + EntityItemProperties modifiedProperties = properties; | |
| 144 | + entity->setLastBroadcast(usecTimestampNow()); | |
| 145 | + modifiedProperties.setType(entity->getType()); | |
| 146 | + bidForSimulationOwnership(modifiedProperties); | |
| 147 | + queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, modifiedProperties); | |
| 148 | + return entityID; | |
| 187 | 149 | } |
| 188 | − | |
| 189 | − queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); | |
| 190 | 150 | } |
| 191 | − | |
| 151 | + | |
| 152 | + queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); | |
| 192 | 153 | return entityID; |
| 193 | 154 | } |
| 194 | 155 | |
| 195 | −void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { | |
| 196 | − | |
| 197 | − EntityItemID actualID = entityID; | |
| 198 | − | |
| 199 | − // if the entity is unknown, attempt to look it up | |
| 200 | − if (!entityID.isKnownID) { | |
| 201 | − actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); | |
| 202 | − if (actualID.id != UNKNOWN_ENTITY_ID) { | |
| 203 | − entityID.id = actualID.id; | |
| 204 | − entityID.isKnownID = true; | |
| 205 | − } | |
| 206 | − } | |
| 156 | +void EntityScriptingInterface::deleteEntity(QUuid entityID) { | |
| 207 | 157 | |
| 208 | 158 | bool shouldDelete = true; |
| 209 | 159 | |
| @@ -211,7 +161,7 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { · 1 unmodified line | ||
| 211 | 161 | if (_entityTree) { |
| 212 | 162 | _entityTree->lockForWrite(); |
| 213 | 163 | |
| 214 | − EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(actualID)); | |
| 164 | + EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(entityID)); | |
| 215 | 165 | if (entity) { |
| 216 | 166 | if (entity->getLocked()) { |
| 217 | 167 | shouldDelete = false; |
| @@ -224,19 +174,19 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { · 6 unmodified lines | ||
| 224 | 174 | } |
| 225 | 175 | |
| 226 | 176 | // if at this point, we know the id, and we should still delete the entity, send the update to the entity server |
| 227 | − if (shouldDelete && entityID.isKnownID) { | |
| 177 | + if (shouldDelete) { | |
| 228 | 178 | getEntityPacketSender()->queueEraseEntityMessage(entityID); |
| 229 | 179 | } |
| 230 | 180 | } |
| 231 | 181 | |
| 232 | −EntityItemID EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { | |
| 233 | − EntityItemID result(UNKNOWN_ENTITY_ID, UNKNOWN_ENTITY_TOKEN, false); | |
| 182 | +QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { | |
| 183 | + QUuid result; | |
| 234 | 184 | if (_entityTree) { |
| 235 | 185 | _entityTree->lockForRead(); |
| 236 | 186 | const EntityItem* closestEntity = _entityTree->findClosestEntity(center, radius); |
| 237 | 187 | _entityTree->unlock(); |
| 238 | 188 | if (closestEntity) { |
| 239 | − result = closestEntity->getEntityItemID(); | |
| 189 | + result = closestEntity->getID(); | |
| 240 | 190 | } |
| 241 | 191 | } |
| 242 | 192 | return result; |
| @@ -251,8 +201,8 @@ void EntityScriptingInterface::dumpTree() const { · 8 unmodified lines | ||
| 251 | 201 | } |
| 252 | 202 | } |
| 253 | 203 | |
| 254 | −QVector<EntityItemID> EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { | |
| 255 | − QVector<EntityItemID> result; | |
| 204 | +QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { | |
| 205 | + QVector<QUuid> result; | |
| 256 | 206 | if (_entityTree) { |
| 257 | 207 | _entityTree->lockForRead(); |
| 258 | 208 | QVector<const EntityItem*> entities; |
| @@ -260,14 +210,14 @@ QVector<EntityItemID> EntityScriptingInterface::findEntities(const glm::vec3& ce · 1 unmodified line | ||
| 260 | 210 | _entityTree->unlock(); |
| 261 | 211 | |
| 262 | 212 | foreach (const EntityItem* entity, entities) { |
| 263 | − result << entity->getEntityItemID(); | |
| 213 | + result << entity->getID(); | |
| 264 | 214 | } |
| 265 | 215 | } |
| 266 | 216 | return result; |
| 267 | 217 | } |
| 268 | 218 | |
| 269 | −QVector<EntityItemID> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { | |
| 270 | − QVector<EntityItemID> result; | |
| 219 | +QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { | |
| 220 | + QVector<QUuid> result; | |
| 271 | 221 | if (_entityTree) { |
| 272 | 222 | _entityTree->lockForRead(); |
| 273 | 223 | AABox box(corner, dimensions); |
| @@ -276,7 +226,7 @@ QVector<EntityItemID> EntityScriptingInterface::findEntitiesInBox(const glm::vec · 2 unmodified lines | ||
| 276 | 226 | _entityTree->unlock(); |
| 277 | 227 | |
| 278 | 228 | foreach (const EntityItem* entity, entities) { |
| 279 | − result << entity->getEntityItemID(); | |
| 229 | + result << entity->getID(); | |
| 280 | 230 | } |
| 281 | 231 | } |
| 282 | 232 | return result; |
| @@ -303,7 +253,7 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke · 20 unmodified lines | ||
| 303 | 253 | (void**)&intersectedEntity, lockType, &result.accurate, |
| 304 | 254 | precisionPicking); |
| 305 | 255 | if (result.intersects && intersectedEntity) { |
| 306 | − result.entityID = intersectedEntity->getEntityItemID(); | |
| 256 | + result.entityID = intersectedEntity->getID(); | |
| 307 | 257 | result.properties = intersectedEntity->getProperties(); |
| 308 | 258 | result.intersection = ray.origin + (ray.direction * result.distance); |
| 309 | 259 | } |
| @@ -359,7 +309,7 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c · 49 unmodified lines | ||
| 359 | 309 | QScriptValue obj = engine->newObject(); |
| 360 | 310 | obj.setProperty("intersects", value.intersects); |
| 361 | 311 | obj.setProperty("accurate", value.accurate); |
| 362 | − QScriptValue entityItemValue = EntityItemIDtoScriptValue(engine, value.entityID); | |
| 312 | + QScriptValue entityItemValue = quuidToScriptValue(engine, value.entityID); | |
| 363 | 313 | obj.setProperty("entityID", entityItemValue); |
| 364 | 314 | |
| 365 | 315 | QScriptValue propertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties); |
| @@ -403,9 +353,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra · 37 unmodified lines | ||
| 403 | 353 | value.intersects = object.property("intersects").toVariant().toBool(); |
| 404 | 354 | value.accurate = object.property("accurate").toVariant().toBool(); |
| 405 | 355 | QScriptValue entityIDValue = object.property("entityID"); |
| 406 | − if (entityIDValue.isValid()) { | |
| 407 | − EntityItemIDfromScriptValue(entityIDValue, value.entityID); | |
| 408 | − } | |
| 356 | + quuidFromScriptValue(entityIDValue, value.entityID); | |
| 409 | 357 | QScriptValue entityPropertiesValue = object.property("properties"); |
| 410 | 358 | if (entityPropertiesValue.isValid()) { |
| 411 | 359 | EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties); |