Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 452 files). Show all
Unified · Split
| @@ -32,7 +32,7 @@ EntityScriptingInterface::EntityScriptingInterface() : · 31 unmodified lines | |||
| 32 | connect(nodeList.data(), &NodeList::canRezChanged, this, &EntityScriptingInterface::canRezChanged); | 32 | connect(nodeList.data(), &NodeList::canRezChanged, this, &EntityScriptingInterface::canRezChanged); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | void EntityScriptingInterface::queueEntityMessage(PacketType packetType, | 35 | void EntityScriptingInterface::queueEntityMessage(PacketType::Value packetType, |
| 36 | EntityItemID entityID, const EntityItemProperties& properties) { | 36 | EntityItemID entityID, const EntityItemProperties& properties) { |
| 37 | getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); | 37 | getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); |
| 38 | } | 38 | } |
| @@ -93,7 +93,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 54 unmodified lines | |||
| 93 | 93 | ||
| 94 | // queue the packet | 94 | // queue the packet |
| 95 | if (success) { | 95 | if (success) { |
| 96 | queueEntityMessage(PacketTypeEntityAdd, id, propertiesWithSimID); | 96 | queueEntityMessage(PacketType::EntityAdd, id, propertiesWithSimID); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | return id; | 99 | return id; |
| @@ -118,6 +118,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 18 unmodified lines | |||
| 118 | results.setSittingPoints(geometry->sittingPoints); | 118 | results.setSittingPoints(geometry->sittingPoints); |
| 119 | Extents meshExtents = geometry->getUnscaledMeshExtents(); | 119 | Extents meshExtents = geometry->getUnscaledMeshExtents(); |
| 120 | results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum); | 120 | results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum); |
| 121 | results.calculateNaturalPosition(meshExtents.minimum, meshExtents.maximum); | ||
| 121 | } | 122 | } |
| 122 | } | 123 | } |
| 123 | 124 | ||
| @@ -175,13 +176,13 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, EntityItemProperties proper · 51 unmodified lines | |||
| 175 | entity->setLastBroadcast(usecTimestampNow()); | 176 | entity->setLastBroadcast(usecTimestampNow()); |
| 176 | } | 177 | } |
| 177 | _entityTree->unlock(); | 178 | _entityTree->unlock(); |
| 178 | queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | 179 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); |
| 179 | return id; | 180 | return id; |
| 180 | } | 181 | } |
| 181 | return QUuid(); | 182 | return QUuid(); |
| 182 | } | 183 | } |
| 183 | 184 | ||
| 184 | queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | 185 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); |
| 185 | return id; | 186 | return id; |
| 186 | } | 187 | } |
| 187 | 188 | ||
| @@ -419,7 +420,7 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 231 unmodified lines | |||
| 419 | return false; | 420 | return false; |
| 420 | } | 421 | } |
| 421 | 422 | ||
| 422 | EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | 423 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); |
| 423 | if (!entity) { | 424 | if (!entity) { |
| 424 | qCDebug(entities) << "EntityScriptingInterface::setVoxelSphere no entity with ID" << entityID; | 425 | qCDebug(entities) << "EntityScriptingInterface::setVoxelSphere no entity with ID" << entityID; |
| 425 | return false; | 426 | return false; |
| @@ -432,7 +433,7 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 6 unmodified lines | |||
| 432 | 433 | ||
| 433 | auto now = usecTimestampNow(); | 434 | auto now = usecTimestampNow(); |
| 434 | 435 | ||
| 435 | PolyVoxEntityItem* polyVoxEntity = static_cast<PolyVoxEntityItem*>(entity.get()); | 436 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); |
| 436 | _entityTree->lockForWrite(); | 437 | _entityTree->lockForWrite(); |
| 437 | actor(*polyVoxEntity); | 438 | actor(*polyVoxEntity); |
| 438 | entity->setLastEdited(now); | 439 | entity->setLastEdited(now); |
| @@ -446,18 +447,29 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 7 unmodified lines | |||
| 446 | properties.setVoxelDataDirty(); | 447 | properties.setVoxelDataDirty(); |
| 447 | properties.setLastEdited(now); | 448 | properties.setLastEdited(now); |
| 448 | 449 | ||
| 449 | queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | 450 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); |
| 450 | return true; | 451 | return true; |
| 451 | } | 452 | } |
| 452 | 453 | ||
| 453 | bool EntityScriptingInterface::setPoints(EntityItemPointer entity, std::function<bool(LineEntityItem&)> actor) { | 454 | bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) { |
| 454 | if (!_entityTree) { | 455 | if (!_entityTree) { |
| 455 | return false; | 456 | return false; |
| 456 | } | 457 | } |
| 457 | 458 | ||
| 459 | EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | ||
| 460 | if (!entity) { | ||
| 461 | qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; | ||
| 462 | } | ||
| 463 | |||
| 464 | EntityTypes::EntityType entityType = entity->getType(); | ||
| 465 | |||
| 466 | if (entityType != EntityTypes::Line) { | ||
| 467 | return false; | ||
| 468 | } | ||
| 469 | |||
| 458 | auto now = usecTimestampNow(); | 470 | auto now = usecTimestampNow(); |
| 459 | 471 | ||
| 460 | LineEntityItem* lineEntity = static_cast<LineEntityItem*>(entity.get()); | 472 | auto lineEntity = std::static_pointer_cast<LineEntityItem>(entity); |
| 461 | _entityTree->lockForWrite(); | 473 | _entityTree->lockForWrite(); |
| 462 | bool success = actor(*lineEntity); | 474 | bool success = actor(*lineEntity); |
| 463 | entity->setLastEdited(now); | 475 | entity->setLastEdited(now); |
| @@ -472,30 +484,44 @@ bool EntityScriptingInterface::setPoints(EntityItemPointer entity, std::function · 8 unmodified lines | |||
| 472 | properties.setLastEdited(now); | 484 | properties.setLastEdited(now); |
| 473 | 485 | ||
| 474 | 486 | ||
| 475 | queueEntityMessage(PacketTypeEntityEdit, entity->getID(), properties); | 487 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); |
| 476 | return success; | 488 | return success; |
| 477 | } | 489 | } |
| 478 | 490 | ||
| 479 | bool EntityScriptingInterface::setPoints(EntityItemPointer entity, std::function<bool(PolyLineEntityItem&)> actor) { | 491 | bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(PolyLineEntityItem&)> actor) { |
| 480 | if (!_entityTree) { | 492 | if (!_entityTree) { |
| 481 | return false; | 493 | return false; |
| 482 | } | 494 | } |
| 483 | 495 | ||
| 496 | EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | ||
| 497 | if (!entity) { | ||
| 498 | qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; | ||
| 499 | } | ||
| 500 | |||
| 501 | EntityTypes::EntityType entityType = entity->getType(); | ||
| 502 | |||
| 503 | if (entityType != EntityTypes::Line) { | ||
| 504 | return false; | ||
| 505 | } | ||
| 506 | |||
| 484 | auto now = usecTimestampNow(); | 507 | auto now = usecTimestampNow(); |
| 485 | PolyLineEntityItem* PolyLineEntity = static_cast<PolyLineEntityItem*>(entity.get()); | 508 | |
| 509 | auto polyLineEntity = std::static_pointer_cast<PolyLineEntityItem>(entity); | ||
| 486 | _entityTree->lockForWrite(); | 510 | _entityTree->lockForWrite(); |
| 487 | bool success = actor(*PolyLineEntity); | 511 | bool success = actor(*polyLineEntity); |
| 488 | entity->setLastEdited(now); | 512 | entity->setLastEdited(now); |
| 489 | entity->setLastBroadcast(now); | 513 | entity->setLastBroadcast(now); |
| 490 | _entityTree->unlock(); | 514 | _entityTree->unlock(); |
| 491 | 515 | ||
| 492 | _entityTree->lockForRead(); | 516 | _entityTree->lockForRead(); |
| 493 | EntityItemProperties properties = entity->getProperties(); | 517 | EntityItemProperties properties = entity->getProperties(); |
| 494 | _entityTree->unlock(); | 518 | _entityTree->unlock(); |
| 495 | 519 | ||
| 496 | properties.setLinePointsDirty(); | 520 | properties.setLinePointsDirty(); |
| 497 | properties.setLastEdited(now); | 521 | properties.setLastEdited(now); |
| 498 | queueEntityMessage(PacketTypeEntityEdit, entity->getID(), properties); | 522 | |
| 523 | |||
| 524 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); | ||
| 499 | return success; | 525 | return success; |
| 500 | } | 526 | } |
| 501 | 527 | ||
| @@ -526,14 +552,14 @@ bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::v · 24 unmodified lines | |||
| 526 | EntityTypes::EntityType entityType = entity->getType(); | 552 | EntityTypes::EntityType entityType = entity->getType(); |
| 527 | 553 | ||
| 528 | if (entityType == EntityTypes::Line) { | 554 | if (entityType == EntityTypes::Line) { |
| 529 | return setPoints(entity, [points](LineEntityItem& lineEntity) -> bool | 555 | return setPoints(entityID, [points](LineEntityItem& lineEntity) -> bool |
| 530 | { | 556 | { |
| 531 | return lineEntity.setLinePoints(points); | 557 | return lineEntity.setLinePoints(points); |
| 532 | }); | 558 | }); |
| 533 | } | 559 | } |
| 534 | 560 | ||
| 535 | if (entityType == EntityTypes::PolyLine) { | 561 | if (entityType == EntityTypes::PolyLine) { |
| 536 | return setPoints(entity, [points](PolyLineEntityItem& PolyLineEntity) -> bool | 562 | return setPoints(entityID, [points](PolyLineEntityItem& PolyLineEntity) -> bool |
| 537 | { | 563 | { |
| 538 | return PolyLineEntity.setLinePoints(points); | 564 | return PolyLineEntity.setLinePoints(points); |
| 539 | }); | 565 | }); |
| @@ -551,14 +577,14 @@ bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& poin · 11 unmodified lines | |||
| 551 | EntityTypes::EntityType entityType = entity->getType(); | 577 | EntityTypes::EntityType entityType = entity->getType(); |
| 552 | 578 | ||
| 553 | if (entityType == EntityTypes::Line) { | 579 | if (entityType == EntityTypes::Line) { |
| 554 | return setPoints(entity, [point](LineEntityItem& lineEntity) -> bool | 580 | return setPoints(entityID, [point](LineEntityItem& lineEntity) -> bool |
| 555 | { | 581 | { |
| 556 | return lineEntity.appendPoint(point); | 582 | return lineEntity.appendPoint(point); |
| 557 | }); | 583 | }); |
| 558 | } | 584 | } |
| 559 | 585 | ||
| 560 | if (entityType == EntityTypes::PolyLine) { | 586 | if (entityType == EntityTypes::PolyLine) { |
| 561 | return setPoints(entity, [point](PolyLineEntityItem& PolyLineEntity) -> bool | 587 | return setPoints(entityID, [point](PolyLineEntityItem& PolyLineEntity) -> bool |
| 562 | { | 588 | { |
| 563 | return PolyLineEntity.appendPoint(point); | 589 | return PolyLineEntity.appendPoint(point); |
| 564 | }); | 590 | }); |
| @@ -603,7 +629,7 @@ bool EntityScriptingInterface::actionWorker(const QUuid& entityID, · 38 unmodified lines | |||
| 603 | properties.setActionDataDirty(); | 629 | properties.setActionDataDirty(); |
| 604 | auto now = usecTimestampNow(); | 630 | auto now = usecTimestampNow(); |
| 605 | properties.setLastEdited(now); | 631 | properties.setLastEdited(now); |
| 606 | queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | 632 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); |
| 607 | 633 | ||
| 608 | return success; | 634 | return success; |
| 609 | } | 635 | } |